Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9ef445ea6 | ||
|
|
a4192718b5 | ||
|
5ad7fce0ac
|
|||
| fcd9ab4d56 | |||
| 3094e355c9 |
79
.github/workflows/snyk-security.yml
vendored
79
.github/workflows/snyk-security.yml
vendored
@@ -1,79 +0,0 @@
|
||||
# This workflow uses actions that are not certified by GitHub.
|
||||
# They are provided by a third-party and are governed by
|
||||
# separate terms of service, privacy policy, and support
|
||||
# documentation.
|
||||
|
||||
# A sample workflow which sets up Snyk to analyze the full Snyk platform (Snyk Open Source, Snyk Code,
|
||||
# Snyk Container and Snyk Infrastructure as Code)
|
||||
# The setup installs the Snyk CLI - for more details on the possible commands
|
||||
# check https://docs.snyk.io/snyk-cli/cli-reference
|
||||
# The results of Snyk Code are then uploaded to GitHub Security Code Scanning
|
||||
#
|
||||
# In order to use the Snyk Action you will need to have a Snyk API token.
|
||||
# More details in https://github.com/snyk/actions#getting-your-snyk-token
|
||||
# or you can signup for free at https://snyk.io/login
|
||||
#
|
||||
# For more examples, including how to limit scans to only high-severity issues
|
||||
# and fail PR checks, see https://github.com/snyk/actions/
|
||||
|
||||
name: Snyk Security
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main" ]
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
snyk:
|
||||
permissions:
|
||||
contents: read # for actions/checkout to fetch code
|
||||
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
|
||||
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Snyk CLI to check for security issues
|
||||
# Snyk can be used to break the build when it detects security issues.
|
||||
# In this case we want to upload the SAST issues to GitHub Code Scanning
|
||||
uses: snyk/actions/setup@806182742461562b67788a64410098c9d9b96adb
|
||||
|
||||
# For Snyk Open Source you must first set up the development environment for your application's dependencies
|
||||
# For example for Node
|
||||
#- uses: actions/setup-node@v3
|
||||
# with:
|
||||
# node-version: 16
|
||||
|
||||
env:
|
||||
# This is where you will need to introduce the Snyk API token created with your Snyk account
|
||||
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
||||
|
||||
# Runs Snyk Code (SAST) analysis and uploads result into GitHub.
|
||||
# Use || true to not fail the pipeline
|
||||
- name: Snyk Code test
|
||||
run: snyk code test --sarif > snyk-code.sarif # || true
|
||||
|
||||
# Runs Snyk Open Source (SCA) analysis and uploads result to Snyk.
|
||||
- name: Snyk Open Source monitor
|
||||
run: snyk monitor --all-projects
|
||||
|
||||
# Runs Snyk Infrastructure as Code (IaC) analysis and uploads result to Snyk.
|
||||
# Use || true to not fail the pipeline.
|
||||
- name: Snyk IaC test and report
|
||||
run: snyk iac test --report # || true
|
||||
|
||||
# Build the docker image for testing
|
||||
- name: Build a Docker image
|
||||
run: docker build -t your/image-to-test .
|
||||
# Runs Snyk Container (Container and SCA) analysis and uploads result to Snyk.
|
||||
- name: Snyk Container monitor
|
||||
run: snyk container monitor your/image-to-test --file=Dockerfile
|
||||
|
||||
# Push the Snyk Code results into GitHub Code Scanning tab
|
||||
- name: Upload result to GitHub Code Scanning
|
||||
uses: github/codeql-action/upload-sarif@v2
|
||||
with:
|
||||
sarif_file: snyk-code.sarif
|
||||
12
SECURITY.md
Normal file
12
SECURITY.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| > 0.0.x | :white_check_mark: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
create issue with details.
|
||||
@@ -1,3 +1,6 @@
|
||||
// SPDX-FileCopyrightText: 2023 Jon Lundy <jon@xuu.cc>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package cron
|
||||
|
||||
import (
|
||||
@@ -30,7 +33,7 @@ type state struct {
|
||||
}
|
||||
type cron struct {
|
||||
jobs []job
|
||||
state *locker.Locked[state]
|
||||
state *locker.Locked[*state]
|
||||
granularity time.Duration
|
||||
}
|
||||
|
||||
|
||||
13
env/env.go
vendored
13
env/env.go
vendored
@@ -1,7 +1,10 @@
|
||||
// SPDX-FileCopyrightText: 2023 Jon Lundy <jon@xuu.cc>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package env
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
@@ -10,10 +13,10 @@ func Default(name, defaultValue string) string {
|
||||
name = strings.TrimSpace(name)
|
||||
defaultValue = strings.TrimSpace(defaultValue)
|
||||
if v := strings.TrimSpace(os.Getenv(name)); v != "" {
|
||||
log.Println("# ", name, "=", v)
|
||||
slog.Info("env", name, v)
|
||||
return v
|
||||
}
|
||||
log.Println("# ", name, "=", defaultValue, "(default)")
|
||||
slog.Info("env", name, defaultValue+" (default)")
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
@@ -32,9 +35,9 @@ func Secret(name, defaultValue string) secret {
|
||||
name = strings.TrimSpace(name)
|
||||
defaultValue = strings.TrimSpace(defaultValue)
|
||||
if v := strings.TrimSpace(os.Getenv(name)); v != "" {
|
||||
log.Println("# ", name, "=", secret(v))
|
||||
slog.Info("env", name, secret(v))
|
||||
return secret(v)
|
||||
}
|
||||
log.Println("# ", name, "=", secret(defaultValue), "(default)")
|
||||
slog.Info("env", name, secret(defaultValue).String()+" (default)")
|
||||
return secret(defaultValue)
|
||||
}
|
||||
|
||||
18
go.mod
18
go.mod
@@ -9,7 +9,7 @@ require (
|
||||
github.com/matryer/is v1.4.1
|
||||
github.com/ravilushqa/otelgqlgen v0.13.1
|
||||
github.com/vektah/gqlparser/v2 v2.5.6
|
||||
go.opentelemetry.io/otel v1.16.0
|
||||
go.opentelemetry.io/otel v1.17.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.16.0
|
||||
go.opentelemetry.io/otel/sdk/metric v0.39.0
|
||||
go.uber.org/multierr v1.11.0
|
||||
@@ -25,8 +25,8 @@ require (
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/prometheus/client_model v0.4.0 // indirect
|
||||
github.com/prometheus/common v0.42.0 // indirect
|
||||
github.com/prometheus/procfs v0.10.1 // indirect
|
||||
github.com/prometheus/common v0.44.0 // indirect
|
||||
github.com/prometheus/procfs v0.11.0 // indirect
|
||||
go.opentelemetry.io/contrib v1.16.1 // indirect
|
||||
)
|
||||
|
||||
@@ -35,21 +35,21 @@ require (
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
|
||||
github.com/prometheus/client_golang v1.16.0
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.42.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.39.0
|
||||
go.opentelemetry.io/otel/metric v1.16.0
|
||||
go.opentelemetry.io/otel/metric v1.17.0
|
||||
go.opentelemetry.io/otel/sdk v1.16.0
|
||||
go.opentelemetry.io/otel/trace v1.16.0
|
||||
go.opentelemetry.io/otel/trace v1.17.0
|
||||
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
|
||||
golang.org/x/net v0.8.0 // indirect
|
||||
golang.org/x/sys v0.8.0 // indirect
|
||||
golang.org/x/net v0.10.0 // indirect
|
||||
golang.org/x/sys v0.10.0 // indirect
|
||||
golang.org/x/text v0.9.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
|
||||
google.golang.org/grpc v1.55.0 // indirect
|
||||
google.golang.org/protobuf v1.30.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
)
|
||||
|
||||
26
go.sum
26
go.sum
@@ -147,8 +147,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 h1:BZHcxBETFHIdVyhyEfOvn/RdU/QGdLI4y34qQGjGWO0=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.3 h1:kmRrRLlInXvng0SmLxmQpQkpbYAvcXm7NPDrgxJa9mE=
|
||||
@@ -173,10 +173,8 @@ github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lF
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY=
|
||||
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
|
||||
github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM=
|
||||
github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc=
|
||||
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
|
||||
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
|
||||
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
|
||||
github.com/prometheus/procfs v0.11.0 h1:5EAgkfkMl659uZPbe9AS2N68a7Cc1TJbPEuGzFuRbyk=
|
||||
github.com/ravilushqa/otelgqlgen v0.13.1 h1:V+zFE75iDd2/CSzy5kKnb+Fi09SsE5535wv9U2nUEFE=
|
||||
github.com/ravilushqa/otelgqlgen v0.13.1/go.mod h1:ZIyWykK2paCuNi9k8gk5edcNSwDJuxZaW90vZXpafxw=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
@@ -205,8 +203,7 @@ go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 h1:pginetY
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0/go.mod h1:XiYsayHc36K3EByOO6nbAXnAWbrUxdjUROCEeeROOH8=
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.42.0 h1:EbmAUG9hEAMXyfWEasIt2kmh/WmXUznUksChApTgBGc=
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.42.0/go.mod h1:rD9feqRYP24P14t5kmhNMqsqm1jvKmpx2H2rKVw52V8=
|
||||
go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s=
|
||||
go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4=
|
||||
go.opentelemetry.io/otel v1.17.0 h1:MW+phZ6WZ5/uk2nd93ANk/6yJ+dVrvNWUjGhnnFU5jM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 h1:t4ZwRPU+emrcvM2e9DHd0Fsf0JTPVcbfa/BhTDF03d0=
|
||||
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0/go.mod h1:vLarbg68dH2Wa77g71zmKQqlQ8+8Rq3GRG31uc0WcWI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 h1:cbsD4cUcviQGXdw8+bo5x2wazq10SKz8hEbtCRPcU78=
|
||||
@@ -215,14 +212,12 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.16.0 h1:iqjq9
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.16.0/go.mod h1:hGXzO5bhhSHZnKvrDaXB82Y9DRFour0Nz/KrBh7reWw=
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.39.0 h1:whAaiHxOatgtKd+w0dOi//1KUxj3KoPINZdtDaDj3IA=
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.39.0/go.mod h1:4jo5Q4CROlCpSPsXLhymi+LYrDXd2ObU5wbKayfZs7Y=
|
||||
go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo=
|
||||
go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4=
|
||||
go.opentelemetry.io/otel/metric v1.17.0 h1:iG6LGVz5Gh+IuO0jmgvpTB6YVrCGngi8QGm+pMd8Pdc=
|
||||
go.opentelemetry.io/otel/sdk v1.16.0 h1:Z1Ok1YsijYL0CSJpHt4cS3wDDh7p572grzNrBMiMWgE=
|
||||
go.opentelemetry.io/otel/sdk v1.16.0/go.mod h1:tMsIuKXuuIWPBAOrH+eHtvhTL+SntFtXF9QD68aP6p4=
|
||||
go.opentelemetry.io/otel/sdk/metric v0.39.0 h1:Kun8i1eYf48kHH83RucG93ffz0zGV1sh46FAScOTuDI=
|
||||
go.opentelemetry.io/otel/sdk/metric v0.39.0/go.mod h1:piDIRgjcK7u0HCL5pCA4e74qpK/jk3NiUoAHATVAmiI=
|
||||
go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs=
|
||||
go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0=
|
||||
go.opentelemetry.io/otel/trace v1.17.0 h1:/SWhSRHmDPOImIAetP1QAeMnZYiQXrTy4fMMYOdSKWQ=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJPI1Nnw=
|
||||
go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U=
|
||||
@@ -290,8 +285,7 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@@ -336,8 +330,7 @@ golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@@ -480,8 +473,7 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
||||
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
scalar Time
|
||||
scalar Map
|
||||
|
||||
type Connection @goModel(model: "go.sour.is/ev/pkg/gql.Connection") {
|
||||
type Connection @goModel(model: "go.sour.is/pkg/gql.Connection") {
|
||||
paging: PageInfo!
|
||||
edges: [Edge!]!
|
||||
}
|
||||
input PageInput @goModel(model: "go.sour.is/ev/pkg/gql.PageInput") {
|
||||
input PageInput @goModel(model: "go.sour.is/pkg/gql.PageInput") {
|
||||
after: Int = 0
|
||||
before: Int
|
||||
count: Int = 30
|
||||
}
|
||||
type PageInfo @goModel(model: "go.sour.is/ev/pkg/gql.PageInfo") {
|
||||
type PageInfo @goModel(model: "go.sour.is/pkg/gql.PageInfo") {
|
||||
next: Boolean!
|
||||
prev: Boolean!
|
||||
|
||||
begin: Int!
|
||||
end: Int!
|
||||
}
|
||||
interface Edge @goModel(model: "go.sour.is/ev/pkg/gql.Edge"){
|
||||
interface Edge @goModel(model: "go.sour.is/pkg/gql.Edge"){
|
||||
id: ID!
|
||||
}
|
||||
|
||||
|
||||
83
lg/metric.go
83
lg/metric.go
@@ -4,25 +4,30 @@ import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
|
||||
"go.opentelemetry.io/contrib/instrumentation/runtime"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/exporters/prometheus"
|
||||
api "go.opentelemetry.io/otel/metric"
|
||||
sdk "go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
)
|
||||
|
||||
var meterKey = contextKey{"meter"}
|
||||
var promHTTPKey = contextKey{"promHTTP"}
|
||||
|
||||
func Meter(ctx context.Context) api.Meter {
|
||||
if t := fromContext[contextKey, api.Meter](ctx, tracerKey); t != nil {
|
||||
if t := fromContext[contextKey, api.Meter](ctx, meterKey); t != nil {
|
||||
return t
|
||||
}
|
||||
|
||||
log.Printf("default meter")
|
||||
return otel.Meter("")
|
||||
}
|
||||
func NewHTTP(ctx context.Context) *httpHandle {
|
||||
@@ -31,50 +36,50 @@ func NewHTTP(ctx context.Context) *httpHandle {
|
||||
}
|
||||
|
||||
func initMetrics(ctx context.Context, name string) (context.Context, func() error) {
|
||||
// goversion := ""
|
||||
// pkg := ""
|
||||
// host := ""
|
||||
// if info, ok := debug.ReadBuildInfo(); ok {
|
||||
// goversion = info.GoVersion
|
||||
// pkg = info.Path
|
||||
// }
|
||||
// if h, err := os.Hostname(); err == nil {
|
||||
// host = h
|
||||
// }
|
||||
goversion := ""
|
||||
pkg := ""
|
||||
host := ""
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
goversion = info.GoVersion
|
||||
pkg = info.Path
|
||||
}
|
||||
if h, err := os.Hostname(); err == nil {
|
||||
host = h
|
||||
}
|
||||
|
||||
// config := prometheus.Config{
|
||||
// DefaultHistogramBoundaries: []float64{
|
||||
// 2 << 6, 2 << 8, 2 << 10, 2 << 12, 2 << 14, 2 << 16, 2 << 18, 2 << 20, 2 << 22, 2 << 24, 2 << 26, 2 << 28,
|
||||
// },
|
||||
// }
|
||||
// cont := controller.New(
|
||||
// processor.NewFactory(
|
||||
// selector.NewWithHistogramDistribution(
|
||||
// histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries),
|
||||
// ),
|
||||
// aggregation.CumulativeTemporalitySelector(),
|
||||
// processor.WithMemory(true),
|
||||
// ),
|
||||
// controller.WithResource(
|
||||
// resource.NewWithAttributes(
|
||||
// semconv.SchemaURL,
|
||||
// attribute.String("app", name),
|
||||
// attribute.String("host", host),
|
||||
// attribute.String("go_version", goversion),
|
||||
// attribute.String("pkg", pkg),
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
ex, err := prometheus.New()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return ctx, nil
|
||||
}
|
||||
provider := sdk.NewMeterProvider(sdk.WithReader(ex))
|
||||
meter := provider.Meter(name)
|
||||
|
||||
|
||||
ctx = toContext(ctx, promHTTPKey, ex)
|
||||
|
||||
provider := sdk.NewMeterProvider(
|
||||
sdk.WithResource(resource.Default()),
|
||||
sdk.WithView(sdk.NewView(
|
||||
sdk.Instrument{Name: "histogram_*"},
|
||||
sdk.Stream{
|
||||
Aggregation: aggregation.ExplicitBucketHistogram{
|
||||
Boundaries: []float64{
|
||||
2 << 6, 2 << 8, 2 << 10, 2 << 12, 2 << 14, 2 << 16, 2 << 18, 2 << 20, 2 << 22, 2 << 24, 2 << 26, 2 << 28,
|
||||
},
|
||||
},
|
||||
},
|
||||
)),
|
||||
sdk.WithReader(ex),
|
||||
)
|
||||
|
||||
meter := provider.Meter(name,
|
||||
api.WithInstrumentationVersion("0.0.1"),
|
||||
api.WithInstrumentationAttributes(
|
||||
attribute.String("app", name),
|
||||
attribute.String("host", host),
|
||||
attribute.String("go_version", goversion),
|
||||
attribute.String("pkg", pkg),
|
||||
),
|
||||
)
|
||||
ctx = toContext(ctx, meterKey, meter)
|
||||
|
||||
runtime.Start()
|
||||
|
||||
return ctx, func() error {
|
||||
|
||||
45
lg/tracer.go
45
lg/tracer.go
@@ -1,9 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2023 Jon Lundy <jon@xuu.cc>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package lg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@@ -50,10 +54,51 @@ func attrs(ctx context.Context) (string, []attribute.KeyValue) {
|
||||
return name, attrs
|
||||
}
|
||||
|
||||
type wrapSpan struct {
|
||||
trace.Span
|
||||
}
|
||||
|
||||
func (w wrapSpan) AddEvent(name string, options ...trace.EventOption) {
|
||||
w.Span.AddEvent(name, options...)
|
||||
|
||||
cfg := trace.NewEventConfig(options...)
|
||||
|
||||
attrs := cfg.Attributes()
|
||||
args := make([]any, len(attrs)*2)
|
||||
|
||||
for i, a := range attrs {
|
||||
args[2*i] = a.Key
|
||||
args[2*i+1] = a.Value
|
||||
}
|
||||
|
||||
slog.Info(name, args...)
|
||||
}
|
||||
|
||||
func (w wrapSpan) RecordError(err error, options ...trace.EventOption) {
|
||||
w.Span.RecordError(err, options...)
|
||||
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
cfg := trace.NewEventConfig(options...)
|
||||
|
||||
attrs := cfg.Attributes()
|
||||
args := make([]any, len(attrs)*2)
|
||||
|
||||
for i, a := range attrs {
|
||||
args[2*i] = a.Key
|
||||
args[2*i+1] = a.Value
|
||||
}
|
||||
|
||||
slog.Error(err.Error(), args...)
|
||||
}
|
||||
|
||||
func Span(ctx context.Context, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
|
||||
name, attrs := attrs(ctx)
|
||||
attrs = append(attrs, attribute.String("name", name))
|
||||
ctx, span := Tracer(ctx).Start(ctx, name, opts...)
|
||||
span = &wrapSpan{span}
|
||||
|
||||
span.SetAttributes(attrs...)
|
||||
|
||||
return ctx, span
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// SPDX-FileCopyrightText: 2023 Jon Lundy <jon@xuu.cc>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package locker
|
||||
|
||||
import (
|
||||
@@ -10,13 +13,13 @@ import (
|
||||
)
|
||||
|
||||
type Locked[T any] struct {
|
||||
state chan *T
|
||||
state chan T
|
||||
}
|
||||
|
||||
// New creates a new locker for the given value.
|
||||
func New[T any](initial *T) *Locked[T] {
|
||||
func New[T any](initial T) *Locked[T] {
|
||||
s := &Locked[T]{}
|
||||
s.state = make(chan *T, 1)
|
||||
s.state = make(chan T, 1)
|
||||
s.state <- initial
|
||||
return s
|
||||
}
|
||||
@@ -24,7 +27,7 @@ func New[T any](initial *T) *Locked[T] {
|
||||
type ctxKey struct{ name string }
|
||||
|
||||
// Use will call the function with the locked value
|
||||
func (s *Locked[T]) Use(ctx context.Context, fn func(context.Context, *T) error) error {
|
||||
func (s *Locked[T]) Use(ctx context.Context, fn func(context.Context, T) error) error {
|
||||
if s == nil {
|
||||
return fmt.Errorf("locker not initialized")
|
||||
}
|
||||
@@ -61,10 +64,8 @@ func (s *Locked[T]) Use(ctx context.Context, fn func(context.Context, *T) error)
|
||||
func (s *Locked[T]) Copy(ctx context.Context) (T, error) {
|
||||
var t T
|
||||
|
||||
err := s.Use(ctx, func(ctx context.Context, c *T) error {
|
||||
if c != nil {
|
||||
t = *c
|
||||
}
|
||||
err := s.Use(ctx, func(ctx context.Context, c T) error {
|
||||
t = c
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
//go:build darwin
|
||||
// +build darwin
|
||||
// SPDX-FileCopyrightText: 2023 Jon Lundy <jon@xuu.cc>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package xdg
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
// SPDX-FileCopyrightText: 2023 Jon Lundy <jon@xuu.cc>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package xdg
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
// SPDX-FileCopyrightText: 2023 Jon Lundy <jon@xuu.cc>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package xdg
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// SPDX-FileCopyrightText: 2023 Jon Lundy <jon@xuu.cc>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package xdg
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user