Skip to content

Commit

Permalink
Push gateway: fix prometheus format + add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcorbin committed Jul 4, 2024
1 parent 6a46a73 commit 78c91c2
Show file tree
Hide file tree
Showing 31 changed files with 5,654 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
server
/server
6 changes: 6 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
with-expecter: true
packages:
github.com/appclacks/server/pkg/pushgateway:
interfaces:
Store:
config:
Binary file removed api
Binary file not shown.
2 changes: 1 addition & 1 deletion dev/migrations/20240603_pushgateway.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ create table if not exists pushgateway_metric (
description varchar(255),
ttl varchar(255),
labels jsonb default '{}'::jsonb,
value real,
value double precision,
type varchar(255),
created_at timestamp not null,
expires_at timestamp
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/appclacks/server
go 1.22.0

require (
github.com/appclacks/go-client v0.0.0-20240703205617-8b0425724375
github.com/appclacks/go-client v0.0.0-20240704181602-986408774b6c
github.com/baidubce/bce-sdk-go v0.9.182
github.com/go-playground/validator/v10 v10.21.0
github.com/golang-migrate/migrate/v4 v4.17.1
Expand All @@ -12,7 +12,6 @@ require (
github.com/labstack/echo/v4 v4.12.0
github.com/lib/pq v1.10.9
github.com/mcorbin/corbierror v0.0.0-20220804210425-326e0b6f18e4
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -40,6 +39,7 @@ require (
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
go.uber.org/atomic v1.11.0 // indirect
Expand Down
24 changes: 10 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,10 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/appclacks/go-client v0.0.0-20240601153604-3e5f27cc6056 h1:Iz5NtXS/BjLzgkVqYAB7/TYyskrJ66y6/vVj8HD+nKE=
github.com/appclacks/go-client v0.0.0-20240601153604-3e5f27cc6056/go.mod h1:ZOQEaU5H5BTLZr326dMjvVbB+pdkeRX3emyu4cEq9GU=
github.com/appclacks/go-client v0.0.0-20240610183348-ab8dfe4619e9 h1:gEo4/IUpmViyOXz4PRCE9sVtNHIUtsJM6IiYhJ8p3bU=
github.com/appclacks/go-client v0.0.0-20240610183348-ab8dfe4619e9/go.mod h1:ZOQEaU5H5BTLZr326dMjvVbB+pdkeRX3emyu4cEq9GU=
github.com/appclacks/go-client v0.0.0-20240612211353-ca705a8ef159 h1:uf+OKgnq0e2rm7ssddZ1I3NFNmQyJBHo35qd7+G5AWg=
github.com/appclacks/go-client v0.0.0-20240612211353-ca705a8ef159/go.mod h1:ZOQEaU5H5BTLZr326dMjvVbB+pdkeRX3emyu4cEq9GU=
github.com/appclacks/go-client v0.0.0-20240615165525-db218ab6cbc8 h1:DXAwhDr62DChJfIILXcNqDNO5KDECv09oUP++UC22IY=
github.com/appclacks/go-client v0.0.0-20240615165525-db218ab6cbc8/go.mod h1:ZOQEaU5H5BTLZr326dMjvVbB+pdkeRX3emyu4cEq9GU=
github.com/appclacks/go-client v0.0.0-20240616203643-c8ce02eb386d h1:xNugXlR+pcLY4d3zuYQ4qzm/e68A+roY1HnquwBgiR8=
github.com/appclacks/go-client v0.0.0-20240616203643-c8ce02eb386d/go.mod h1:ZOQEaU5H5BTLZr326dMjvVbB+pdkeRX3emyu4cEq9GU=
github.com/appclacks/go-client v0.0.0-20240618204225-51a556fa72ba h1://S8sLRrM/2eJLfYXcFOpsP7eDGwKDrHj0rqlXj6uSo=
github.com/appclacks/go-client v0.0.0-20240618204225-51a556fa72ba/go.mod h1:ZOQEaU5H5BTLZr326dMjvVbB+pdkeRX3emyu4cEq9GU=
github.com/appclacks/go-client v0.0.0-20240703204325-c8a3257d9e08 h1:vjf4pQGIx8BCj1+wEsNBR04lyVzje74O7ozJQn6JO3w=
github.com/appclacks/go-client v0.0.0-20240703204325-c8a3257d9e08/go.mod h1:ZOQEaU5H5BTLZr326dMjvVbB+pdkeRX3emyu4cEq9GU=
github.com/appclacks/go-client v0.0.0-20240703205617-8b0425724375 h1:eVJ+l4qRByZ2L9O4xl2HC009T7TMw2z5EPnf+ArUH3A=
github.com/appclacks/go-client v0.0.0-20240703205617-8b0425724375/go.mod h1:ZOQEaU5H5BTLZr326dMjvVbB+pdkeRX3emyu4cEq9GU=
github.com/appclacks/go-client v0.0.0-20240704181602-986408774b6c h1:EQiTE3jqDdtXOqPOt+LQOxuAipB9/+v0qmPuJVV+hKs=
github.com/appclacks/go-client v0.0.0-20240704181602-986408774b6c/go.mod h1:ZOQEaU5H5BTLZr326dMjvVbB+pdkeRX3emyu4cEq9GU=
github.com/baidubce/bce-sdk-go v0.9.182 h1:DUNNEzQh5Gk198izzjt39L/HlURbltTK4nBzNfEn6HQ=
github.com/baidubce/bce-sdk-go v0.9.182/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand All @@ -28,6 +16,7 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dhui/dktest v0.4.1 h1:/w+IWuDXVymg3IrRJCHHOkMK10m9aNVMOyD0X12YVTg=
Expand Down Expand Up @@ -119,6 +108,12 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Expand Down Expand Up @@ -148,5 +143,6 @@ google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion internal/database/pushgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type pushgatewayMetric struct {
Type *string
CreatedAt time.Time `db:"created_at"`
ExpiresAt *time.Time `db:"expires_at"`
Value float32
Value float64
}

func toPushGatewayMetric(metric *pushgatewayMetric) (*aggregates.PushgatewayMetric, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/database/pushgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestPushgatewayCRUD(t *testing.T) {
metric, err = TestComponent.GetMetrics(context.Background())
assert.NoError(t, err)
assert.Len(t, metric, 1)
assert.Equal(t, metric[0].Value, float32(8000))
assert.Equal(t, metric[0].Value, float64(8000))

// new metric by name
desc3 := "description"
Expand Down
Loading

0 comments on commit 78c91c2

Please sign in to comment.