Skip to content

Commit

Permalink
Merge pull request #8 from persona-id/kuzmik/updates
Browse files Browse the repository at this point in the history
chore: updates to various things
  • Loading branch information
kuzmik authored Oct 15, 2024
2 parents 540a9e3 + 636de2c commit 8af6523
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ go.work

# Test coverage output and a temp directory
/coverage
/tmp
/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
30 changes: 15 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,4 @@ changelog:
checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ incpatch .Version }}-next"

report_sizes: true
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,15 @@ snapshot: clean lint
@goreleaser --snapshot --clean

release: clean lint
@goreleaser --clean
@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)
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
11 changes: 3 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"errors"
"flag"
"fmt"
"log/slog"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
// )
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion tests/datadogmetric-working.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 8af6523

Please sign in to comment.