diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index a7430ed..4439686 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -28,7 +28,7 @@ jobs: # Require: The version of golangci-lint to use. # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. - version: v1.57.1 + version: latest # Optional: working directory, useful for monorepos # working-directory: somedir diff --git a/.gitignore b/.gitignore index 818888e..a0b3c5a 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,9 @@ go.work # Test coverage output and a temp directory /coverage -/tmp \ No newline at end of file +/tmp.envrc + +# dont commit the envrc because it has persona-specific gcp values +# in it. NOT any actual secrets though, of course, just gcp projects +# and secret names. +/.envrc \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 19a673d..2372bff 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,46 +7,46 @@ issues: linters: disable-all: true enable: - - goimports + - copyloopvar + - decorder - dupl - dupword - durationcheck - errcheck - errname - errorlint - - exportloopref + - forbidigo - forcetypeassert - # - forbidigo - - godot - - decorder - - gocritic - - goconst - gochecknoglobals + - goconst + - gocritic + - godot # - godox - gofmt - gofumpt - # - gomnd + - goimports + - mnd - gosimple - govet - ineffassign - makezero - - nilnil - - musttag - misspell + - musttag - nilerr + - nilnil - predeclared - - staticcheck - reassign - revive + - sloglint + - staticcheck - tenv + - testifylint - unconvert - unparam - - sloglint - unused - # - testifylint - # - wrapcheck - - wsl - whitespace + - wrapcheck + - wsl linters-settings: goconst: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5a14bf3..5b8270d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -46,7 +46,4 @@ changelog: checksum: name_template: 'checksums.txt' -snapshot: - name_template: "{{ incpatch .Version }}-next" - report_sizes: true diff --git a/Makefile b/Makefile index 75698b2..b93099a 100644 --- a/Makefile +++ b/Makefile @@ -41,4 +41,15 @@ snapshot: clean lint @goreleaser --snapshot --clean release: clean lint - @goreleaser --clean \ No newline at end of file + @goreleaser --clean + +dockertest: + @echo $$(pwd)/tests + @docker container run --rm \ + --user $$(id -u ${USER}):$$(id -g ${USER}) \ + --volume $$(pwd)/tests:/tests \ + --env DD_CLIENT_API_KEY=${DD_API_KEY} \ + --env DD_CLIENT_APP_KEY=${DD_APP_KEY} \ + ghcr.io/persona-id/datadog-query-linter:latest \ + /usr/local/bin/datadog-query-linter \ + $$(ls tests/*.yaml) diff --git a/go.mod b/go.mod index e00b39e..b8d107b 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,14 @@ module github.com/persona-id/datadog-query-linter go 1.22.3 require ( - github.com/DataDog/datadog-api-client-go/v2 v2.27.0 - github.com/lmittmann/tint v1.0.4 + github.com/DataDog/datadog-api-client-go/v2 v2.31.0 + github.com/lmittmann/tint v1.0.5 + github.com/pkg/errors v0.9.1 gopkg.in/yaml.v2 v2.4.0 ) require ( - github.com/DataDog/zstd v1.5.5 // indirect + github.com/DataDog/zstd v1.5.6 // indirect github.com/goccy/go-json v0.10.3 // indirect - golang.org/x/oauth2 v0.21.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect ) diff --git a/go.sum b/go.sum index cb73390..5b920a6 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,17 @@ -github.com/DataDog/datadog-api-client-go/v2 v2.27.0 h1:AGZj41frjnjMufQHQbJH2fzmifOs20wpmVDtIBCv33E= -github.com/DataDog/datadog-api-client-go/v2 v2.27.0/go.mod h1:QKOu6vscsh87fMY1lHfLEmNSunyXImj8BUaUWJXOehc= -github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= -github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= +github.com/DataDog/datadog-api-client-go/v2 v2.31.0 h1:JfJhYlHfLzvauI8u6h23smTooWYe6quNhhg9gpTszWY= +github.com/DataDog/datadog-api-client-go/v2 v2.31.0/go.mod h1:d3tOEgUd2kfsr9uuHQdY+nXrWp4uikgTgVCPdKNK30U= +github.com/DataDog/zstd v1.5.6 h1:LbEglqepa/ipmmQJUDnSsfvA8e8IStVcGaFWDuxvGOY= +github.com/DataDog/zstd v1.5.6/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/lmittmann/tint v1.0.4 h1:LeYihpJ9hyGvE0w+K2okPTGUdVLfng1+nDNVR4vWISc= -github.com/lmittmann/tint v1.0.4/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +github.com/lmittmann/tint v1.0.5 h1:NQclAutOfYsqs2F1Lenue6OoWCajs5wJcP3DfWVpePw= +github.com/lmittmann/tint v1.0.5/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= diff --git a/main.go b/main.go index df0617a..1420133 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "errors" "flag" "fmt" "log/slog" @@ -13,6 +12,7 @@ import ( "github.com/DataDog/datadog-api-client-go/v2/api/datadog" "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" "github.com/lmittmann/tint" + "github.com/pkg/errors" "gopkg.in/yaml.v2" ) @@ -147,14 +147,14 @@ func setupLogger(logLevel string) { func extractQuery(filePath string) (string, error) { data, err := os.ReadFile(filePath) if err != nil { - return "", err + return "", errors.Wrap(err, fmt.Sprintf("Failed to read file: %s", filePath)) } var metric DatadogMetricDefinition err = yaml.Unmarshal(data, &metric) if err != nil { - return "", err + return "", errors.Wrap(err, fmt.Sprintf("Failed to unmarshal yaml: %s", filePath)) } return metric.Spec.Query, nil @@ -198,8 +198,3 @@ func fetchMetric(ctx context.Context, api *datadogV1.MetricsApi, query string) ( } } } - -// slog.Info("No data available or unexpected response format, but the query was valid", -// // slog.String("file", file), -// slog.String("query", query), -// ) diff --git a/main_test.go b/main_test.go index 1d467be..a20b7ff 100644 --- a/main_test.go +++ b/main_test.go @@ -24,7 +24,7 @@ func TestFileLoading(t *testing.T) { t.Fatalf("Expected an error but didn't receive one.") } - expectedErr := "open tests/datadogmetric-no-file.yaml: no such file or directory" + expectedErr := "Failed to read file: tests/datadogmetric-no-file.yaml: open tests/datadogmetric-no-file.yaml: no such file or directory" if err.Error() != expectedErr { t.Fatalf("Expected error string `%s` but got `%v`.", expectedErr, err) } diff --git a/tests/datadogmetric-working.yaml b/tests/datadogmetric-working.yaml index eaf055a..e94b9fb 100644 --- a/tests/datadogmetric-working.yaml +++ b/tests/datadogmetric-working.yaml @@ -4,5 +4,7 @@ metadata: name: temporal-retention-workflow-start-latency namespace: web spec: - # This query will pass + # This query will pass because it isn't malformed. however, if the query isn't + # technically valid because the metric doesn't exist, it will still pass due to the + # default_zero() function. TODO: figure out a way around this. query: default_zero(avg:rails.temporal.workflow_task.queue_time.avg{app:persona-web-temporal-worker-retention,env:production,region:us-central1,task_queue:retention}.fill(null))