From a29235f3dbae7f30fbcb2b5912378619c4f1ffbd Mon Sep 17 00:00:00 2001 From: Nurlan Moldomurov Date: Wed, 9 Oct 2024 13:32:42 +0300 Subject: [PATCH 01/13] PMM-13057 Fix imports. --- .golangci.yml | 4 ++- CONTRIBUTING.md | 2 +- api-tests/alerting/alerting_test.go | 2 +- go.mod | 16 +++++------ go.sum | 28 +++++++++---------- managed/cmd/pmm-managed-starlark/main.go | 4 +-- managed/cmd/pmm-managed-starlark/main_test.go | 2 +- managed/models/template_helpers.go | 2 +- managed/models/template_helpers_test.go | 4 +-- managed/models/template_model.go | 2 +- managed/services/alerting/service.go | 4 +-- managed/services/checks/checks.go | 2 +- managed/services/checks/checks_test.go | 4 +-- managed/services/checks/funcs.go | 2 +- managed/services/checks/funcs_test.go | 6 ++-- managed/services/checks/registry.go | 2 +- managed/services/checks/registry_test.go | 4 +-- managed/services/management/checks.go | 4 +-- managed/services/management/checks_test.go | 4 +-- managed/services/management/deps.go | 2 +- .../management/mock_checks_service_test.go | 2 +- .../services/telemetry/datasource_envvars.go | 2 +- .../telemetry/datasource_envvars_test.go | 2 +- .../telemetry/datasource_grafanadb_select.go | 2 +- .../telemetry/datasource_pmmdb_select.go | 2 +- .../telemetry/datasource_qandb_select.go | 2 +- .../telemetry/datasource_victoria_metrics.go | 2 +- managed/services/telemetry/datasources.go | 2 +- managed/services/telemetry/deps.go | 4 +-- managed/services/telemetry/extension.go | 2 +- .../telemetry/mock_data_source_test.go | 2 +- .../mock_distribution_util_service_test.go | 2 +- .../services/telemetry/mock_sender_test.go | 2 +- managed/services/telemetry/telemetry.go | 4 +-- managed/services/telemetry/telemetry_test.go | 4 +-- managed/services/telemetry/transform.go | 2 +- managed/services/telemetry/transform_test.go | 2 +- .../services/telemetry/uievents/uievents.go | 2 +- managed/services/types.go | 2 +- .../utils/distribution/distribution_util.go | 2 +- .../distribution/distribution_util_test.go | 2 +- managed/utils/platform/client.go | 4 +-- managed/utils/signatures/signatures.go | 2 +- 43 files changed, 78 insertions(+), 76 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 22e8b34ba8..81eb0fd788 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,7 +21,9 @@ linters-settings: - pkg: "github.com/percona/go-mysql/log/slow" desc: only use the forked parser - pkg: "github.com/percona-platform/platform" - desc: use "github.com/percona-platform/saas" instead + desc: use "github.com/percona/saas" instead + - pkg: "github.com/percona/platform" + desc: use "github.com/percona/saas" instead - pkg: "gopkg.in/yaml.v2" desc: use "gopkg.in/yaml.v3" instead diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0b9c1aca54..1920ed3c99 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,7 +18,7 @@ This project is built from several repositories: ### APIs * [percona/pmm](https://github.com/percona/pmm/tree/main/api) -* [percona-platform/saas](https://github.com/percona-platform/saas) +* [percona/saas](https://github.com/percona/saas) ### PMM Server diff --git a/api-tests/alerting/alerting_test.go b/api-tests/alerting/alerting_test.go index 3eccff32a5..504e5425ac 100644 --- a/api-tests/alerting/alerting_test.go +++ b/api-tests/alerting/alerting_test.go @@ -31,7 +31,7 @@ import ( "github.com/AlekSi/pointer" "github.com/google/uuid" gapi "github.com/grafana/grafana-api-golang-client" - "github.com/percona-platform/saas/pkg/alert" + "github.com/percona/saas/pkg/alert" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" diff --git a/go.mod b/go.mod index 9a74e01185..6be2608502 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/percona/pmm go 1.22.7 // Update saas with -// go get -v github.com/percona-platform/saas@latest +// go get -v github.com/percona/saas@latest replace github.com/grpc-ecosystem/go-grpc-prometheus => github.com/Percona-Lab/go-grpc-prometheus v0.0.0-20230116133345-3487748d4592 @@ -49,11 +49,11 @@ require ( github.com/jotaen/kong-completion v0.0.5 github.com/lib/pq v1.10.9 github.com/minio/minio-go/v7 v7.0.55 - github.com/percona-platform/saas v0.0.0-20230728161159-ad6bdeb8a3d9 github.com/percona/exporter_shared v0.7.5 github.com/percona/go-mysql v0.0.0-20210427141028-73d29c6da78c github.com/percona/percona-toolkit v3.2.1+incompatible github.com/percona/promconfig v0.2.5 + github.com/percona/saas v0.0.0-20240923141535-da19f6682c6e github.com/pganalyze/pg_query_go/v5 v5.1.0 github.com/pkg/errors v0.9.1 github.com/pkg/sftp v1.13.6 @@ -67,14 +67,14 @@ require ( github.com/stretchr/testify v1.9.0 go.mongodb.org/mongo-driver v1.16.1 go.starlark.net v0.0.0-20230717150657-8a3343210976 - golang.org/x/crypto v0.26.0 + golang.org/x/crypto v0.27.0 golang.org/x/sync v0.8.0 - golang.org/x/sys v0.24.0 - golang.org/x/text v0.17.0 + golang.org/x/sys v0.25.0 + golang.org/x/text v0.18.0 golang.org/x/tools v0.24.0 - google.golang.org/genproto/googleapis/api v0.0.0-20240723171418-e6d459c13d2a - google.golang.org/genproto/googleapis/rpc v0.0.0-20240723171418-e6d459c13d2a - google.golang.org/grpc v1.65.0 + google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 + google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 + google.golang.org/grpc v1.67.0 google.golang.org/protobuf v1.34.2 gopkg.in/alecthomas/kingpin.v2 v2.2.6 gopkg.in/reform.v1 v1.5.1 diff --git a/go.sum b/go.sum index 55b3c5e9cf..5ffdb00bba 100644 --- a/go.sum +++ b/go.sum @@ -416,8 +416,6 @@ github.com/paulmach/orb v0.11.1/go.mod h1:5mULz1xQfs3bmQm63QEJA6lNGujuRafwA5S/En github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY= github.com/percona-lab/crypto v0.0.0-20231108144114-756dfb24eaf2 h1:FaO5loTAkRzVhyKWYRHg/ii9oWXNsqv89H/kGl9Cb5I= github.com/percona-lab/crypto v0.0.0-20231108144114-756dfb24eaf2/go.mod h1:aSyBXtGhRzSMdne9jbl3+PPMVS0IgOWF6Llc+HB5uUU= -github.com/percona-platform/saas v0.0.0-20230728161159-ad6bdeb8a3d9 h1:KkOH+Y4sVRP7qvRtTDmfPFNjjQcwU2054/jNl9DZhEo= -github.com/percona-platform/saas v0.0.0-20230728161159-ad6bdeb8a3d9/go.mod h1:lZuFcqj0EoQWx28SYkTcdhJOCQEbRcAyahYPfRMY7tc= github.com/percona/exporter_shared v0.7.5 h1:sIhdDtKOfH0jsqtTAi41C7wm1R42yXYeAkK0QWhgN7k= github.com/percona/exporter_shared v0.7.5/go.mod h1:P8ZHDzveyJRGD4ZIRNiEMuAdDexBpQWf2mAVwtyVcYU= github.com/percona/go-mysql v0.0.0-20210427141028-73d29c6da78c h1:1SZ7nS+kSaO63IpaKspf/gf8602QcgP2eXNPMNOIc0M= @@ -426,6 +424,8 @@ github.com/percona/percona-toolkit v3.2.1+incompatible h1:5jLvtZKcu9fDmaLRB8qA4b github.com/percona/percona-toolkit v3.2.1+incompatible/go.mod h1:netQWdWMaF1cnmwiIS+i5uyaqNXz46yNeM6HKkR6yeI= github.com/percona/promconfig v0.2.5 h1:f/HN/CbECQs7d9RIB6MKVkuXstsrsqEDxRvf6yigquc= github.com/percona/promconfig v0.2.5/go.mod h1:Y2uXi5QNk71+ceJHuI9poank+0S1kjxd3K105fXKVkg= +github.com/percona/saas v0.0.0-20240923141535-da19f6682c6e h1:xhk5ivxlTPat0SwLBqU1UdfqJb+2R3x4yAhjCf6WMEU= +github.com/percona/saas v0.0.0-20240923141535-da19f6682c6e/go.mod h1:UP4WqGWy8xeGhEoDFaB1aPNNtNs/TYXQ8MjUrN6rXis= github.com/pganalyze/pg_query_go/v5 v5.1.0 h1:MlxQqHZnvA3cbRQYyIrjxEjzo560P6MyTgtlaf3pmXg= github.com/pganalyze/pg_query_go/v5 v5.1.0/go.mod h1:FsglvxidZsVN+Ltw3Ai6nTgPVcK2BPukH3jCDEqc1Ug= github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= @@ -598,8 +598,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= +golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -643,8 +643,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -662,8 +662,8 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -703,18 +703,18 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto/googleapis/api v0.0.0-20240723171418-e6d459c13d2a h1:YIa/rzVqMEokBkPtydCkx1VLmv3An1Uw7w1P1m6EhOY= -google.golang.org/genproto/googleapis/api v0.0.0-20240723171418-e6d459c13d2a/go.mod h1:AHT0dDg3SoMOgZGnZk29b5xTbPHMoEC8qthmBLJCpys= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240723171418-e6d459c13d2a h1:hqK4+jJZXCU4pW7jsAdGOVFIfLHQeV7LaizZKnZ84HI= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240723171418-e6d459c13d2a/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8= +google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= -google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= +google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw= +google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/managed/cmd/pmm-managed-starlark/main.go b/managed/cmd/pmm-managed-starlark/main.go index 175a78440a..9a0f56231f 100644 --- a/managed/cmd/pmm-managed-starlark/main.go +++ b/managed/cmd/pmm-managed-starlark/main.go @@ -23,8 +23,8 @@ import ( "strconv" "time" - "github.com/percona-platform/saas/pkg/check" - "github.com/percona-platform/saas/pkg/starlark" + "github.com/percona/saas/pkg/check" + "github.com/percona/saas/pkg/starlark" "github.com/pkg/errors" "github.com/sirupsen/logrus" "go.starlark.net/resolve" diff --git a/managed/cmd/pmm-managed-starlark/main_test.go b/managed/cmd/pmm-managed-starlark/main_test.go index 6053b8615a..ec9eedb3d3 100644 --- a/managed/cmd/pmm-managed-starlark/main_test.go +++ b/managed/cmd/pmm-managed-starlark/main_test.go @@ -24,7 +24,7 @@ import ( "testing" "time" - "github.com/percona-platform/saas/pkg/check" + "github.com/percona/saas/pkg/check" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/managed/models/template_helpers.go b/managed/models/template_helpers.go index 071db6e7e9..2dbe7dd1f3 100644 --- a/managed/models/template_helpers.go +++ b/managed/models/template_helpers.go @@ -19,7 +19,7 @@ import ( "time" "github.com/AlekSi/pointer" - "github.com/percona-platform/saas/pkg/alert" + "github.com/percona/saas/pkg/alert" "github.com/pkg/errors" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" diff --git a/managed/models/template_helpers_test.go b/managed/models/template_helpers_test.go index 4394cf8cce..6393592d44 100644 --- a/managed/models/template_helpers_test.go +++ b/managed/models/template_helpers_test.go @@ -22,8 +22,8 @@ import ( "github.com/AlekSi/pointer" "github.com/brianvoe/gofakeit/v6" "github.com/google/uuid" - "github.com/percona-platform/saas/pkg/alert" - "github.com/percona-platform/saas/pkg/common" + "github.com/percona/saas/pkg/alert" + "github.com/percona/saas/pkg/common" "github.com/percona/promconfig" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/managed/models/template_model.go b/managed/models/template_model.go index fc1794f6a5..e0823a0563 100644 --- a/managed/models/template_model.go +++ b/managed/models/template_model.go @@ -19,7 +19,7 @@ import ( "database/sql/driver" "time" - "github.com/percona-platform/saas/pkg/common" + "github.com/percona/saas/pkg/common" "github.com/pkg/errors" "gopkg.in/reform.v1" ) diff --git a/managed/services/alerting/service.go b/managed/services/alerting/service.go index 4214b4847b..46cdd27709 100644 --- a/managed/services/alerting/service.go +++ b/managed/services/alerting/service.go @@ -30,8 +30,8 @@ import ( "time" "github.com/AlekSi/pointer" - "github.com/percona-platform/saas/pkg/alert" - "github.com/percona-platform/saas/pkg/common" + "github.com/percona/saas/pkg/alert" + "github.com/percona/saas/pkg/common" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/grpc/codes" diff --git a/managed/services/checks/checks.go b/managed/services/checks/checks.go index 0f91051422..3144a2e07f 100644 --- a/managed/services/checks/checks.go +++ b/managed/services/checks/checks.go @@ -32,7 +32,7 @@ import ( "text/template" "time" - "github.com/percona-platform/saas/pkg/check" + "github.com/percona/saas/pkg/check" "github.com/pkg/errors" v1 "github.com/prometheus/client_golang/api/prometheus/v1" prom "github.com/prometheus/client_golang/prometheus" diff --git a/managed/services/checks/checks_test.go b/managed/services/checks/checks_test.go index 50b0a76611..8a81e503fd 100644 --- a/managed/services/checks/checks_test.go +++ b/managed/services/checks/checks_test.go @@ -24,8 +24,8 @@ import ( "github.com/AlekSi/pointer" _ "github.com/ClickHouse/clickhouse-go/v2" - "github.com/percona-platform/saas/pkg/check" - "github.com/percona-platform/saas/pkg/common" + "github.com/percona/saas/pkg/check" + "github.com/percona/saas/pkg/common" metrics "github.com/prometheus/client_golang/api" v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/sirupsen/logrus" diff --git a/managed/services/checks/funcs.go b/managed/services/checks/funcs.go index aa046777d5..df82b95adf 100644 --- a/managed/services/checks/funcs.go +++ b/managed/services/checks/funcs.go @@ -19,7 +19,7 @@ import ( "net" "strconv" - "github.com/percona-platform/saas/pkg/starlark" + "github.com/percona/saas/pkg/starlark" "github.com/pkg/errors" "github.com/sirupsen/logrus" diff --git a/managed/services/checks/funcs_test.go b/managed/services/checks/funcs_test.go index 2723d4e8c8..58797088df 100644 --- a/managed/services/checks/funcs_test.go +++ b/managed/services/checks/funcs_test.go @@ -19,9 +19,9 @@ import ( "strings" "testing" - "github.com/percona-platform/saas/pkg/check" - "github.com/percona-platform/saas/pkg/common" - "github.com/percona-platform/saas/pkg/starlark" + "github.com/percona/saas/pkg/check" + "github.com/percona/saas/pkg/common" + "github.com/percona/saas/pkg/starlark" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/managed/services/checks/registry.go b/managed/services/checks/registry.go index 2b51279eb6..5c95502239 100644 --- a/managed/services/checks/registry.go +++ b/managed/services/checks/registry.go @@ -18,7 +18,7 @@ package checks import ( "sync" - "github.com/percona-platform/saas/pkg/check" + "github.com/percona/saas/pkg/check" prom "github.com/prometheus/client_golang/prometheus" "github.com/percona/pmm/managed/services" diff --git a/managed/services/checks/registry_test.go b/managed/services/checks/registry_test.go index 47bc4c8ab5..00a800042c 100644 --- a/managed/services/checks/registry_test.go +++ b/managed/services/checks/registry_test.go @@ -18,8 +18,8 @@ package checks import ( "testing" - "github.com/percona-platform/saas/pkg/check" - "github.com/percona-platform/saas/pkg/common" + "github.com/percona/saas/pkg/check" + "github.com/percona/saas/pkg/common" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/managed/services/management/checks.go b/managed/services/management/checks.go index bb3d69de0b..42511d6693 100644 --- a/managed/services/management/checks.go +++ b/managed/services/management/checks.go @@ -20,8 +20,8 @@ import ( "strings" "github.com/AlekSi/pointer" - "github.com/percona-platform/saas/pkg/check" - "github.com/percona-platform/saas/pkg/common" + "github.com/percona/saas/pkg/check" + "github.com/percona/saas/pkg/common" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/grpc/codes" diff --git a/managed/services/management/checks_test.go b/managed/services/management/checks_test.go index 4d24997740..c7a3b78cb8 100644 --- a/managed/services/management/checks_test.go +++ b/managed/services/management/checks_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/AlekSi/pointer" - "github.com/percona-platform/saas/pkg/check" - "github.com/percona-platform/saas/pkg/common" + "github.com/percona/saas/pkg/check" + "github.com/percona/saas/pkg/common" "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" diff --git a/managed/services/management/deps.go b/managed/services/management/deps.go index dee58d918b..db929a452c 100644 --- a/managed/services/management/deps.go +++ b/managed/services/management/deps.go @@ -19,7 +19,7 @@ import ( "context" "time" - "github.com/percona-platform/saas/pkg/check" + "github.com/percona/saas/pkg/check" v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prometheus/common/model" "gopkg.in/reform.v1" diff --git a/managed/services/management/mock_checks_service_test.go b/managed/services/management/mock_checks_service_test.go index 7ea9954892..b0bd6a7b49 100644 --- a/managed/services/management/mock_checks_service_test.go +++ b/managed/services/management/mock_checks_service_test.go @@ -5,7 +5,7 @@ package management import ( context "context" - check "github.com/percona-platform/saas/pkg/check" + check "github.com/percona/saas/pkg/check" mock "github.com/stretchr/testify/mock" services "github.com/percona/pmm/managed/services" diff --git a/managed/services/telemetry/datasource_envvars.go b/managed/services/telemetry/datasource_envvars.go index 4dc320a51c..0b7a4fd764 100644 --- a/managed/services/telemetry/datasource_envvars.go +++ b/managed/services/telemetry/datasource_envvars.go @@ -20,7 +20,7 @@ import ( "context" "os" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/sirupsen/logrus" ) diff --git a/managed/services/telemetry/datasource_envvars_test.go b/managed/services/telemetry/datasource_envvars_test.go index 5139d68c48..fab2f72689 100644 --- a/managed/services/telemetry/datasource_envvars_test.go +++ b/managed/services/telemetry/datasource_envvars_test.go @@ -21,7 +21,7 @@ import ( "os" "testing" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/managed/services/telemetry/datasource_grafanadb_select.go b/managed/services/telemetry/datasource_grafanadb_select.go index 172f9acc7c..61e94e2a2c 100644 --- a/managed/services/telemetry/datasource_grafanadb_select.go +++ b/managed/services/telemetry/datasource_grafanadb_select.go @@ -23,7 +23,7 @@ import ( "time" // Events, errors and driver for grafana database. - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/managed/services/telemetry/datasource_pmmdb_select.go b/managed/services/telemetry/datasource_pmmdb_select.go index bc230cb2b9..9ac78cf050 100644 --- a/managed/services/telemetry/datasource_pmmdb_select.go +++ b/managed/services/telemetry/datasource_pmmdb_select.go @@ -22,7 +22,7 @@ import ( "net/url" "time" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/managed/services/telemetry/datasource_qandb_select.go b/managed/services/telemetry/datasource_qandb_select.go index 17e20e583c..e6517f140c 100644 --- a/managed/services/telemetry/datasource_qandb_select.go +++ b/managed/services/telemetry/datasource_qandb_select.go @@ -20,7 +20,7 @@ import ( "context" "database/sql" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/managed/services/telemetry/datasource_victoria_metrics.go b/managed/services/telemetry/datasource_victoria_metrics.go index 91d8b77659..fad001937f 100644 --- a/managed/services/telemetry/datasource_victoria_metrics.go +++ b/managed/services/telemetry/datasource_victoria_metrics.go @@ -20,7 +20,7 @@ import ( "context" "time" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/prometheus/client_golang/api" v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prometheus/common/model" diff --git a/managed/services/telemetry/datasources.go b/managed/services/telemetry/datasources.go index b239b55bff..4cbde06362 100644 --- a/managed/services/telemetry/datasources.go +++ b/managed/services/telemetry/datasources.go @@ -22,7 +22,7 @@ import ( "time" "github.com/AlekSi/pointer" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/managed/services/telemetry/deps.go b/managed/services/telemetry/deps.go index 603e669505..fd92d81d73 100644 --- a/managed/services/telemetry/deps.go +++ b/managed/services/telemetry/deps.go @@ -18,8 +18,8 @@ package telemetry import ( "context" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" - reporter "github.com/percona-platform/saas/gen/telemetry/reporter" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + reporter "github.com/percona/saas/gen/telemetry/reporter" serverv1 "github.com/percona/pmm/api/server/v1" ) diff --git a/managed/services/telemetry/extension.go b/managed/services/telemetry/extension.go index 7679b41b42..af5e60f71b 100644 --- a/managed/services/telemetry/extension.go +++ b/managed/services/telemetry/extension.go @@ -18,7 +18,7 @@ package telemetry import ( "context" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" ) // Extension provides dynamic extension point for Telemetry. diff --git a/managed/services/telemetry/mock_data_source_test.go b/managed/services/telemetry/mock_data_source_test.go index a84586e7e1..35925c66b5 100644 --- a/managed/services/telemetry/mock_data_source_test.go +++ b/managed/services/telemetry/mock_data_source_test.go @@ -5,7 +5,7 @@ package telemetry import ( context "context" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" mock "github.com/stretchr/testify/mock" ) diff --git a/managed/services/telemetry/mock_distribution_util_service_test.go b/managed/services/telemetry/mock_distribution_util_service_test.go index baa81ac8e8..d4c8871399 100644 --- a/managed/services/telemetry/mock_distribution_util_service_test.go +++ b/managed/services/telemetry/mock_distribution_util_service_test.go @@ -3,7 +3,7 @@ package telemetry import ( - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" mock "github.com/stretchr/testify/mock" serverv1 "github.com/percona/pmm/api/server/v1" diff --git a/managed/services/telemetry/mock_sender_test.go b/managed/services/telemetry/mock_sender_test.go index 41e73bd34e..a813e0a27d 100644 --- a/managed/services/telemetry/mock_sender_test.go +++ b/managed/services/telemetry/mock_sender_test.go @@ -5,7 +5,7 @@ package telemetry import ( context "context" - reporterv1 "github.com/percona-platform/saas/gen/telemetry/reporter" + reporterv1 "github.com/percona/saas/gen/telemetry/reporter" mock "github.com/stretchr/testify/mock" ) diff --git a/managed/services/telemetry/telemetry.go b/managed/services/telemetry/telemetry.go index 966ee5ec27..53393d29f0 100644 --- a/managed/services/telemetry/telemetry.go +++ b/managed/services/telemetry/telemetry.go @@ -24,8 +24,8 @@ import ( "time" "github.com/google/uuid" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" - reporter "github.com/percona-platform/saas/gen/telemetry/reporter" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + reporter "github.com/percona/saas/gen/telemetry/reporter" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/protobuf/types/known/durationpb" diff --git a/managed/services/telemetry/telemetry_test.go b/managed/services/telemetry/telemetry_test.go index ac463b6589..ae11cfdbe1 100644 --- a/managed/services/telemetry/telemetry_test.go +++ b/managed/services/telemetry/telemetry_test.go @@ -23,8 +23,8 @@ import ( "time" _ "github.com/ClickHouse/clickhouse-go/v2" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" - reporter "github.com/percona-platform/saas/gen/telemetry/reporter" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + reporter "github.com/percona/saas/gen/telemetry/reporter" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" diff --git a/managed/services/telemetry/transform.go b/managed/services/telemetry/transform.go index 2616c7317b..794917b972 100644 --- a/managed/services/telemetry/transform.go +++ b/managed/services/telemetry/transform.go @@ -18,7 +18,7 @@ package telemetry import ( "encoding/json" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/pkg/errors" ) diff --git a/managed/services/telemetry/transform_test.go b/managed/services/telemetry/transform_test.go index a991333b27..e196605da2 100644 --- a/managed/services/telemetry/transform_test.go +++ b/managed/services/telemetry/transform_test.go @@ -18,7 +18,7 @@ package telemetry import ( "testing" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/stretchr/testify/assert" ) diff --git a/managed/services/telemetry/uievents/uievents.go b/managed/services/telemetry/uievents/uievents.go index bb981fc8a5..1bee25ca8a 100644 --- a/managed/services/telemetry/uievents/uievents.go +++ b/managed/services/telemetry/uievents/uievents.go @@ -24,7 +24,7 @@ import ( "time" "github.com/HdrHistogram/hdrhistogram-go" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/sirupsen/logrus" uieventsv1 "github.com/percona/pmm/api/uievents/v1" diff --git a/managed/services/types.go b/managed/services/types.go index 805d2b7bc0..91ab54305c 100644 --- a/managed/services/types.go +++ b/managed/services/types.go @@ -16,7 +16,7 @@ package services import ( - "github.com/percona-platform/saas/pkg/check" + "github.com/percona/saas/pkg/check" "github.com/percona/pmm/managed/models" ) diff --git a/managed/utils/distribution/distribution_util.go b/managed/utils/distribution/distribution_util.go index e25f21b3b5..4a84e4c402 100644 --- a/managed/utils/distribution/distribution_util.go +++ b/managed/utils/distribution/distribution_util.go @@ -21,7 +21,7 @@ import ( "os" "regexp" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/sirupsen/logrus" serverv1 "github.com/percona/pmm/api/server/v1" diff --git a/managed/utils/distribution/distribution_util_test.go b/managed/utils/distribution/distribution_util_test.go index dca253ccd0..3aade6d0cd 100644 --- a/managed/utils/distribution/distribution_util_test.go +++ b/managed/utils/distribution/distribution_util_test.go @@ -19,7 +19,7 @@ import ( "os" "testing" - pmmv1 "github.com/percona-platform/saas/gen/telemetry/events/pmm" + pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" diff --git a/managed/utils/platform/client.go b/managed/utils/platform/client.go index 28de38aefd..dca019327a 100644 --- a/managed/utils/platform/client.go +++ b/managed/utils/platform/client.go @@ -24,8 +24,8 @@ import ( "io" "net/http" - api "github.com/percona-platform/saas/gen/check/retrieval" - reporter "github.com/percona-platform/saas/gen/telemetry/reporter" + api "github.com/percona/saas/gen/check/retrieval" + reporter "github.com/percona/saas/gen/telemetry/reporter" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/grpc/codes" diff --git a/managed/utils/signatures/signatures.go b/managed/utils/signatures/signatures.go index 8d6d905d29..a1d79d5f2e 100644 --- a/managed/utils/signatures/signatures.go +++ b/managed/utils/signatures/signatures.go @@ -17,7 +17,7 @@ package signatures import ( - "github.com/percona-platform/saas/pkg/check" + "github.com/percona/saas/pkg/check" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) From c44483576e88f9a993cf5bd6cd233598a0e42793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Thu, 10 Oct 2024 14:31:48 +0200 Subject: [PATCH 02/13] WIP on PMM-13057-new-telemetry --- go.sum | 1 - managed/models/template_helpers_test.go | 2 +- .../services/telemetry/datasource_envvars.go | 8 ++-- .../telemetry/datasource_grafanadb_select.go | 5 +- .../telemetry/datasource_pmmdb_select.go | 4 +- .../telemetry/datasource_qandb_select.go | 4 +- .../telemetry/datasource_victoria_metrics.go | 10 ++-- managed/services/telemetry/datasources.go | 8 ++-- managed/services/telemetry/deps.go | 4 +- managed/services/telemetry/extension.go | 4 +- .../telemetry/mock_data_source_test.go | 12 ++--- .../services/telemetry/mock_sender_test.go | 6 +-- managed/services/telemetry/telemetry.go | 42 ++++++++-------- managed/services/telemetry/telemetry_test.go | 16 +++---- managed/services/telemetry/transform.go | 12 ++--- managed/services/telemetry/transform_test.go | 48 +++++++++---------- .../services/telemetry/uievents/uievents.go | 20 ++++---- managed/utils/platform/client.go | 4 +- 18 files changed, 105 insertions(+), 105 deletions(-) diff --git a/go.sum b/go.sum index 5ffdb00bba..9ea2336712 100644 --- a/go.sum +++ b/go.sum @@ -645,7 +645,6 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= diff --git a/managed/models/template_helpers_test.go b/managed/models/template_helpers_test.go index 6393592d44..35d6b8b7a1 100644 --- a/managed/models/template_helpers_test.go +++ b/managed/models/template_helpers_test.go @@ -22,9 +22,9 @@ import ( "github.com/AlekSi/pointer" "github.com/brianvoe/gofakeit/v6" "github.com/google/uuid" + "github.com/percona/promconfig" "github.com/percona/saas/pkg/alert" "github.com/percona/saas/pkg/common" - "github.com/percona/promconfig" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/reform.v1" diff --git a/managed/services/telemetry/datasource_envvars.go b/managed/services/telemetry/datasource_envvars.go index 0b7a4fd764..0a90e36701 100644 --- a/managed/services/telemetry/datasource_envvars.go +++ b/managed/services/telemetry/datasource_envvars.go @@ -20,7 +20,7 @@ import ( "context" "os" - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + genericv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/sirupsen/logrus" ) @@ -51,8 +51,8 @@ func (d *dsEnvvars) Init(_ context.Context) error { return nil } -func (d *dsEnvvars) FetchMetrics(_ context.Context, config Config) ([]*pmmv1.ServerMetric_Metric, error) { - var metrics []*pmmv1.ServerMetric_Metric +func (d *dsEnvvars) FetchMetrics(_ context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { + var metrics []*genericv1.GenericReport_Metric check := make(map[string]bool, len(config.Data)) @@ -69,7 +69,7 @@ func (d *dsEnvvars) FetchMetrics(_ context.Context, config Config) ([]*pmmv1.Ser check[col.MetricName] = true - metrics = append(metrics, &pmmv1.ServerMetric_Metric{ + metrics = append(metrics, &genericv1.GenericReport_Metric{ Key: col.MetricName, Value: value, }) diff --git a/managed/services/telemetry/datasource_grafanadb_select.go b/managed/services/telemetry/datasource_grafanadb_select.go index 61e94e2a2c..41ac9800e3 100644 --- a/managed/services/telemetry/datasource_grafanadb_select.go +++ b/managed/services/telemetry/datasource_grafanadb_select.go @@ -22,8 +22,7 @@ import ( "net/url" "time" - // Events, errors and driver for grafana database. - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + genericv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -95,7 +94,7 @@ func openGrafanaDBConnection(config DSConfigGrafanaDB, l *logrus.Entry) (*sql.DB return db, nil } -func (d *dsGrafanaDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*pmmv1.ServerMetric_Metric, error) { +func (d *dsGrafanaDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { return fetchMetricsFromDB(ctx, d.l, d.config.Timeout, d.db, config) } diff --git a/managed/services/telemetry/datasource_pmmdb_select.go b/managed/services/telemetry/datasource_pmmdb_select.go index 9ac78cf050..0559f54c9f 100644 --- a/managed/services/telemetry/datasource_pmmdb_select.go +++ b/managed/services/telemetry/datasource_pmmdb_select.go @@ -22,7 +22,7 @@ import ( "net/url" "time" - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + genericv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -94,7 +94,7 @@ func openPMMDBConnection(config DSConfigPMMDB, l *logrus.Entry) (*sql.DB, error) return db, nil } -func (d *dsPmmDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*pmmv1.ServerMetric_Metric, error) { +func (d *dsPmmDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { return fetchMetricsFromDB(ctx, d.l, d.config.Timeout, d.db, config) } diff --git a/managed/services/telemetry/datasource_qandb_select.go b/managed/services/telemetry/datasource_qandb_select.go index e6517f140c..4808d576dc 100644 --- a/managed/services/telemetry/datasource_qandb_select.go +++ b/managed/services/telemetry/datasource_qandb_select.go @@ -20,7 +20,7 @@ import ( "context" "database/sql" - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + genericv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -69,7 +69,7 @@ func openQANDBConnection(dsn string, enabled bool, l *logrus.Entry) (*sql.DB, er return db, nil } -func (d *dsQanDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*pmmv1.ServerMetric_Metric, error) { +func (d *dsQanDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { return fetchMetricsFromDB(ctx, d.l, d.config.Timeout, d.db, config) } diff --git a/managed/services/telemetry/datasource_victoria_metrics.go b/managed/services/telemetry/datasource_victoria_metrics.go index fad001937f..49564b7856 100644 --- a/managed/services/telemetry/datasource_victoria_metrics.go +++ b/managed/services/telemetry/datasource_victoria_metrics.go @@ -20,7 +20,7 @@ import ( "context" "time" - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + genericv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/prometheus/client_golang/api" v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prometheus/common/model" @@ -66,7 +66,7 @@ func NewDataSourceVictoriaMetrics(config DSConfigVM, l *logrus.Entry) (DataSourc }, nil } -func (d *dataSourceVictoriaMetrics) FetchMetrics(ctx context.Context, config Config) ([]*pmmv1.ServerMetric_Metric, error) { +func (d *dataSourceVictoriaMetrics) FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { localCtx, cancel := context.WithTimeout(ctx, d.config.Timeout) defer cancel() @@ -75,20 +75,20 @@ func (d *dataSourceVictoriaMetrics) FetchMetrics(ctx context.Context, config Con return nil, err } - var metrics []*pmmv1.ServerMetric_Metric + var metrics []*genericv1.GenericReport_Metric for _, v := range result.(model.Vector) { //nolint:forcetypeassert for _, configItem := range config.Data { if configItem.Label != "" { value := v.Metric[model.LabelName(configItem.Label)] - metrics = append(metrics, &pmmv1.ServerMetric_Metric{ + metrics = append(metrics, &genericv1.GenericReport_Metric{ Key: configItem.MetricName, Value: string(value), }) } if configItem.Value != "" { - metrics = append(metrics, &pmmv1.ServerMetric_Metric{ + metrics = append(metrics, &genericv1.GenericReport_Metric{ Key: configItem.MetricName, Value: v.Value.String(), }) diff --git a/managed/services/telemetry/datasources.go b/managed/services/telemetry/datasources.go index 4cbde06362..47ea33bde5 100644 --- a/managed/services/telemetry/datasources.go +++ b/managed/services/telemetry/datasources.go @@ -22,7 +22,7 @@ import ( "time" "github.com/AlekSi/pointer" - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + genericv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -77,7 +77,7 @@ func (r *dataSourceRegistry) LocateTelemetryDataSource(name string) (DataSource, return ds, nil } -func fetchMetricsFromDB(ctx context.Context, l *logrus.Entry, timeout time.Duration, db *sql.DB, config Config) ([]*pmmv1.ServerMetric_Metric, error) { +func fetchMetricsFromDB(ctx context.Context, l *logrus.Entry, timeout time.Duration, db *sql.DB, config Config) ([]*genericv1.GenericReport_Metric, error) { localCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() tx, err := db.BeginTx(localCtx, &sql.TxOptions{}) @@ -104,7 +104,7 @@ func fetchMetricsFromDB(ctx context.Context, l *logrus.Entry, timeout time.Durat } cfgColumns := config.mapByColumn() - var metrics []*pmmv1.ServerMetric_Metric + var metrics []*genericv1.GenericReport_Metric for rows.Next() { if err := rows.Scan(values...); err != nil { l.Error(err) @@ -116,7 +116,7 @@ func fetchMetricsFromDB(ctx context.Context, l *logrus.Entry, timeout time.Durat if cols, ok := cfgColumns[column]; ok { for _, col := range cols { - metrics = append(metrics, &pmmv1.ServerMetric_Metric{ + metrics = append(metrics, &genericv1.GenericReport_Metric{ Key: col.MetricName, Value: value, }) diff --git a/managed/services/telemetry/deps.go b/managed/services/telemetry/deps.go index fd92d81d73..dca26ee7b1 100644 --- a/managed/services/telemetry/deps.go +++ b/managed/services/telemetry/deps.go @@ -19,7 +19,7 @@ import ( "context" pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" - reporter "github.com/percona/saas/gen/telemetry/reporter" + reporter "github.com/percona/saas/gen/telemetry/generic" serverv1 "github.com/percona/pmm/api/server/v1" ) @@ -42,7 +42,7 @@ type DataSourceLocator interface { // DataSource telemetry data source. type DataSource interface { Init(ctx context.Context) error - FetchMetrics(ctx context.Context, config Config) ([]*pmmv1.ServerMetric_Metric, error) + FetchMetrics(ctx context.Context, config Config) ([]*reporter.GenericReport_Metric, error) Dispose(ctx context.Context) error Enabled() bool } diff --git a/managed/services/telemetry/extension.go b/managed/services/telemetry/extension.go index af5e60f71b..1250c61463 100644 --- a/managed/services/telemetry/extension.go +++ b/managed/services/telemetry/extension.go @@ -18,10 +18,10 @@ package telemetry import ( "context" - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + genericv1 "github.com/percona/saas/gen/telemetry/generic" ) // Extension provides dynamic extension point for Telemetry. type Extension interface { - FetchMetrics(ctx context.Context, config Config) ([]*pmmv1.ServerMetric_Metric, error) + FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) } diff --git a/managed/services/telemetry/mock_data_source_test.go b/managed/services/telemetry/mock_data_source_test.go index 35925c66b5..e6b004ebb5 100644 --- a/managed/services/telemetry/mock_data_source_test.go +++ b/managed/services/telemetry/mock_data_source_test.go @@ -5,7 +5,7 @@ package telemetry import ( context "context" - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + genericv1 "github.com/percona/saas/gen/telemetry/generic" mock "github.com/stretchr/testify/mock" ) @@ -51,23 +51,23 @@ func (_m *mockDataSource) Enabled() bool { } // FetchMetrics provides a mock function with given fields: ctx, config -func (_m *mockDataSource) FetchMetrics(ctx context.Context, config Config) ([]*pmmv1.ServerMetric_Metric, error) { +func (_m *mockDataSource) FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { ret := _m.Called(ctx, config) if len(ret) == 0 { panic("no return value specified for FetchMetrics") } - var r0 []*pmmv1.ServerMetric_Metric + var r0 []*genericv1.GenericReport_Metric var r1 error - if rf, ok := ret.Get(0).(func(context.Context, Config) ([]*pmmv1.ServerMetric_Metric, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, Config) ([]*genericv1.GenericReport_Metric, error)); ok { return rf(ctx, config) } - if rf, ok := ret.Get(0).(func(context.Context, Config) []*pmmv1.ServerMetric_Metric); ok { + if rf, ok := ret.Get(0).(func(context.Context, Config) []*genericv1.GenericReport_Metric); ok { r0 = rf(ctx, config) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*pmmv1.ServerMetric_Metric) + r0 = ret.Get(0).([]*genericv1.GenericReport_Metric) } } diff --git a/managed/services/telemetry/mock_sender_test.go b/managed/services/telemetry/mock_sender_test.go index a813e0a27d..3c943e8de4 100644 --- a/managed/services/telemetry/mock_sender_test.go +++ b/managed/services/telemetry/mock_sender_test.go @@ -5,7 +5,7 @@ package telemetry import ( context "context" - reporterv1 "github.com/percona/saas/gen/telemetry/reporter" + genericv1 "github.com/percona/saas/gen/telemetry/generic" mock "github.com/stretchr/testify/mock" ) @@ -15,7 +15,7 @@ type mockSender struct { } // SendTelemetry provides a mock function with given fields: ctx, report -func (_m *mockSender) SendTelemetry(ctx context.Context, report *reporterv1.ReportRequest) error { +func (_m *mockSender) SendTelemetry(ctx context.Context, report *genericv1.ReportRequest) error { ret := _m.Called(ctx, report) if len(ret) == 0 { @@ -23,7 +23,7 @@ func (_m *mockSender) SendTelemetry(ctx context.Context, report *reporterv1.Repo } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *reporterv1.ReportRequest) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *genericv1.ReportRequest) error); ok { r0 = rf(ctx, report) } else { r0 = ret.Error(0) diff --git a/managed/services/telemetry/telemetry.go b/managed/services/telemetry/telemetry.go index 53393d29f0..c5ab41c72d 100644 --- a/managed/services/telemetry/telemetry.go +++ b/managed/services/telemetry/telemetry.go @@ -25,10 +25,9 @@ import ( "github.com/google/uuid" pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" - reporter "github.com/percona/saas/gen/telemetry/reporter" + genericv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" "gopkg.in/reform.v1" @@ -53,7 +52,7 @@ type Service struct { os string sDistributionMethod serverv1.DistributionMethod tDistributionMethod pmmv1.DistributionMethod - sendCh chan *pmmv1.ServerMetric + sendCh chan *genericv1.GenericReport dataSourcesMap map[DataSourceName]DataSource extensions map[ExtensionType]Extension @@ -89,7 +88,7 @@ func NewService(db *reform.DB, portalClient *platform.Client, pmmVersion string, config: config, dsRegistry: registry, dus: dus, - sendCh: make(chan *pmmv1.ServerMetric, sendChSize), + sendCh: make(chan *genericv1.GenericReport, sendChSize), extensions: extensions, } @@ -167,7 +166,7 @@ func (s *Service) DistributionMethod() serverv1.DistributionMethod { func (s *Service) processSendCh(ctx context.Context) { var reportsBufSync sync.Mutex - var reportsBuf []*pmmv1.ServerMetric + var reportsBuf []*genericv1.GenericReport var sendCtx context.Context //nolint:contextcheck var cancel context.CancelFunc @@ -184,12 +183,12 @@ func (s *Service) processSendCh(ctx context.Context) { reportsBufSync.Lock() reportsBuf = append(reportsBuf, report) reportsToSend := reportsBuf - reportsBuf = []*pmmv1.ServerMetric{} + reportsBuf = []*genericv1.GenericReport{} reportsBufSync.Unlock() go func(ctx context.Context) { - err := s.send(ctx, &reporter.ReportRequest{ - Metrics: reportsToSend, + err := s.send(ctx, &genericv1.ReportRequest{ + Reports: reportsToSend, }) if err != nil { s.l.Debugf("Telemetry info not sent, due to error: %s.", err) @@ -211,7 +210,7 @@ func (s *Service) processSendCh(ctx context.Context) { } } -func (s *Service) prepareReport(ctx context.Context) *pmmv1.ServerMetric { +func (s *Service) prepareReport(ctx context.Context) *genericv1.GenericReport { initializedDataSources := make(map[DataSourceName]DataSource) telemetryMetric, _ := s.makeMetric(ctx) var totalTime time.Duration @@ -324,7 +323,7 @@ func (s *Service) locateDataSources(telemetryConfig []Config) map[DataSourceName return dataSources } -func (s *Service) makeMetric(ctx context.Context) (*pmmv1.ServerMetric, error) { +func (s *Service) makeMetric(ctx context.Context) (*genericv1.GenericReport, error) { var settings *models.Settings useServerID := false err := s.db.InTransaction(func(tx *reform.TX) error { @@ -359,16 +358,19 @@ func (s *Service) makeMetric(ctx context.Context) (*pmmv1.ServerMetric, error) { if err != nil { return nil, errors.Wrapf(err, "failed to decode UUID %s", serverIDToUse) } - _, distMethod, _ := s.dus.GetDistributionMethodAndOS() + //_, distMethod, _ := s.dus.GetDistributionMethodAndOS() + + // todo + // PmmServerVersion: s.pmmVersion, + // UpDuration: durationpb.New(time.Since(s.start)), + // DistributionMethod: distMethod, eventID := uuid.New() - return &pmmv1.ServerMetric{ - Id: eventID[:], - Time: timestamppb.New(time.Now()), - PmmServerTelemetryId: serverID, - PmmServerVersion: s.pmmVersion, - UpDuration: durationpb.New(time.Since(s.start)), - DistributionMethod: distMethod, + return &genericv1.GenericReport{ + Id: string(eventID[:]), + CreateTime: timestamppb.New(time.Now()), + InstanceId: string(serverID), + ProductFamily: genericv1.ProductFamily_PRODUCT_FAMILY_PMM, }, nil } @@ -383,7 +385,7 @@ func generateUUID() (string, error) { return cleanUUID, nil } -func (s *Service) send(ctx context.Context, report *reporter.ReportRequest) error { +func (s *Service) send(ctx context.Context, report *genericv1.ReportRequest) error { var err error var attempt int for { @@ -412,7 +414,7 @@ func (s *Service) send(ctx context.Context, report *reporter.ReportRequest) erro } // Format returns the formatted representation of the provided server metric. -func (s *Service) Format(report *pmmv1.ServerMetric) string { +func (s *Service) Format(report *genericv1.GenericReport) string { var builder strings.Builder for _, m := range report.Metrics { builder.WriteString(m.Key) diff --git a/managed/services/telemetry/telemetry_test.go b/managed/services/telemetry/telemetry_test.go index ae11cfdbe1..2b0401b83d 100644 --- a/managed/services/telemetry/telemetry_test.go +++ b/managed/services/telemetry/telemetry_test.go @@ -24,7 +24,7 @@ import ( _ "github.com/ClickHouse/clickhouse-go/v2" pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" - reporter "github.com/percona/saas/gen/telemetry/reporter" + reporter "github.com/percona/saas/gen/telemetry/generic" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -82,7 +82,7 @@ func TestRunTelemetryService(t *testing.T) { logger.SetLevel(logrus.DebugLevel) logEntry := logrus.NewEntry(logger) - expectedServerMetrics := []*pmmv1.ServerMetric_Metric{ + expectedServerMetrics := []*reporter.GenericReport_Metric{ { Key: "key", Value: "value", @@ -97,10 +97,10 @@ func TestRunTelemetryService(t *testing.T) { }, } expectedReport := &reporter.ReportRequest{ - Metrics: []*pmmv1.ServerMetric{ + Reports: []*reporter.GenericReport{ { - DistributionMethod: pmmv1.DistributionMethod_AMI, - Metrics: expectedServerMetrics, + // DistributionMethod: pmmv1.DistributionMethod_AMI, + Metrics: expectedServerMetrics, }, }, } @@ -176,7 +176,7 @@ func TestRunTelemetryService(t *testing.T) { tDistributionMethod: 0, dus: tt.fields.dus, portalClient: tt.mockTelemetrySender(), - sendCh: make(chan *pmmv1.ServerMetric, sendChSize), + sendCh: make(chan *reporter.GenericReport, sendChSize), } s.Run(ctx) }) @@ -296,8 +296,8 @@ func initMockTelemetrySender(t *testing.T, expectedReport *reporter.ReportReques } func matchExpectedReport(report *reporter.ReportRequest, expectedReport *reporter.ReportRequest) bool { - return len(report.Metrics) == 1 && - expectedReport.Metrics[0].DistributionMethod.String() == "AMI" + return len(report.Reports) == 1 //&& + // expectedReport.Reports[0].Metrics.DistributionMethod.String() == "AMI" } func getTestConfig(sendOnStart bool, testSourceName string, reportingInterval time.Duration) ServiceConfig { diff --git a/managed/services/telemetry/transform.go b/managed/services/telemetry/transform.go index 794917b972..6543354223 100644 --- a/managed/services/telemetry/transform.go +++ b/managed/services/telemetry/transform.go @@ -18,13 +18,13 @@ package telemetry import ( "encoding/json" - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + reporter "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" ) type itemsType []map[string]any -func transformToJSON(config *Config, metrics []*pmmv1.ServerMetric_Metric) ([]*pmmv1.ServerMetric_Metric, error) { +func transformToJSON(config *Config, metrics []*reporter.GenericReport_Metric) ([]*reporter.GenericReport_Metric, error) { if len(metrics) == 0 { return metrics, nil } @@ -78,7 +78,7 @@ func transformToJSON(config *Config, metrics []*pmmv1.ServerMetric_Metric) ([]*p return nil, err } - return []*pmmv1.ServerMetric_Metric{ + return []*reporter.GenericReport_Metric{ { Key: config.Transform.Metric, Value: string(resultAsJSON), @@ -86,7 +86,7 @@ func transformToJSON(config *Config, metrics []*pmmv1.ServerMetric_Metric) ([]*p }, nil } -func transformExportValues(config *Config, metrics []*pmmv1.ServerMetric_Metric) ([]*pmmv1.ServerMetric_Metric, error) { +func transformExportValues(config *Config, metrics []*reporter.GenericReport_Metric) ([]*reporter.GenericReport_Metric, error) { if len(metrics) == 0 { return metrics, nil } @@ -107,8 +107,8 @@ func transformExportValues(config *Config, metrics []*pmmv1.ServerMetric_Metric) return metrics, nil } -func removeEmpty(metrics []*pmmv1.ServerMetric_Metric) []*pmmv1.ServerMetric_Metric { - result := make([]*pmmv1.ServerMetric_Metric, 0, len(metrics)) +func removeEmpty(metrics []*reporter.GenericReport_Metric) []*reporter.GenericReport_Metric { + result := make([]*reporter.GenericReport_Metric, 0, len(metrics)) for _, metric := range metrics { if metric.Value != "" { diff --git a/managed/services/telemetry/transform_test.go b/managed/services/telemetry/transform_test.go index e196605da2..ebaaf25c27 100644 --- a/managed/services/telemetry/transform_test.go +++ b/managed/services/telemetry/transform_test.go @@ -18,22 +18,22 @@ package telemetry import ( "testing" - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + genericv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/stretchr/testify/assert" ) func TestTransformToJSON(t *testing.T) { type args struct { config *Config - metrics []*pmmv1.ServerMetric_Metric + metrics []*genericv1.GenericReport_Metric } - noMetrics := []*pmmv1.ServerMetric_Metric{} + noMetrics := []*genericv1.GenericReport_Metric{} tests := []struct { name string args args - want []*pmmv1.ServerMetric_Metric + want []*genericv1.GenericReport_Metric wantErr assert.ErrorAssertionFunc }{ { @@ -85,7 +85,7 @@ func TestTransformToJSON(t *testing.T) { name: "invalid seq", args: args{ config: configJSON(), - metrics: []*pmmv1.ServerMetric_Metric{ + metrics: []*genericv1.GenericReport_Metric{ {Key: "my-metric", Value: "v1"}, {Key: "b", Value: "v1"}, {Key: "b", Value: "v1"}, // <--- will override second metric @@ -99,14 +99,14 @@ func TestTransformToJSON(t *testing.T) { name: "correct seq", args: args{ config: configJSON(), - metrics: []*pmmv1.ServerMetric_Metric{ + metrics: []*genericv1.GenericReport_Metric{ {Key: "my-metric", Value: "v1"}, {Key: "b", Value: "v1"}, {Key: "my-metric", Value: "v1"}, {Key: "b", Value: "v1"}, }, }, - want: []*pmmv1.ServerMetric_Metric{ + want: []*genericv1.GenericReport_Metric{ {Key: configJSON().Transform.Metric, Value: `{"v":[{"b":"v1","my-metric":"v1"},{"b":"v1","my-metric":"v1"}]}`}, }, wantErr: assert.NoError, @@ -115,12 +115,12 @@ func TestTransformToJSON(t *testing.T) { name: "happy path", args: args{ config: configJSON(), - metrics: []*pmmv1.ServerMetric_Metric{ + metrics: []*genericv1.GenericReport_Metric{ {Key: configJSON().Data[0].MetricName, Value: "v1"}, {Key: configJSON().Data[0].MetricName, Value: "v2"}, }, }, - want: []*pmmv1.ServerMetric_Metric{ + want: []*genericv1.GenericReport_Metric{ {Key: configJSON().Transform.Metric, Value: `{"v":[{"my-metric":"v1"},{"my-metric":"v2"}]}`}, }, wantErr: assert.NoError, @@ -135,14 +135,14 @@ func TestTransformToJSON(t *testing.T) { {MetricName: "4", Label: "status"}, {MetricName: "5", Label: "type"}, }), - metrics: []*pmmv1.ServerMetric_Metric{ + metrics: []*genericv1.GenericReport_Metric{ {Key: "licence", Value: `GPL`}, {Key: "name", Value: `INNODB_TABLES`}, {Key: "status", Value: `ACTIVE`}, {Key: "type", Value: `INFORMATION SCHEMA`}, }, }, - want: []*pmmv1.ServerMetric_Metric{ + want: []*genericv1.GenericReport_Metric{ {Key: "metric", Value: `{"v":[{"licence":"GPL","name":"INNODB_TABLES","status":"ACTIVE","type":"INFORMATION SCHEMA"}]}`}, }, wantErr: assert.NoError, @@ -164,15 +164,15 @@ func TestTransformToJSON(t *testing.T) { func TestTransformExportValues(t *testing.T) { type args struct { config *Config - metrics []*pmmv1.ServerMetric_Metric + metrics []*genericv1.GenericReport_Metric } - noMetrics := []*pmmv1.ServerMetric_Metric{} + noMetrics := []*genericv1.GenericReport_Metric{} tests := []struct { name string args args - want []*pmmv1.ServerMetric_Metric + want []*genericv1.GenericReport_Metric wantErr assert.ErrorAssertionFunc }{ { @@ -215,7 +215,7 @@ func TestTransformExportValues(t *testing.T) { name: "invalid data source", args: args{ config: configEnvVars().changeDataSource(dsPMMDBSelect), - metrics: []*pmmv1.ServerMetric_Metric{ + metrics: []*genericv1.GenericReport_Metric{ {Key: "metric-a", Value: "v1"}, {Key: "metric-b", Value: "v2"}, }, @@ -227,12 +227,12 @@ func TestTransformExportValues(t *testing.T) { name: "happy path", args: args{ config: configEnvVars(), - metrics: []*pmmv1.ServerMetric_Metric{ + metrics: []*genericv1.GenericReport_Metric{ {Key: "metric-a", Value: "v1"}, {Key: "metric-b", Value: "v2"}, }, }, - want: []*pmmv1.ServerMetric_Metric{ + want: []*genericv1.GenericReport_Metric{ {Key: "metric-a", Value: "1"}, {Key: "metric-b", Value: "1"}, }, @@ -300,16 +300,16 @@ func (c *Config) changeData(d []ConfigData) *Config { func TestRemoveEmpty(t *testing.T) { type args struct { - metrics []*pmmv1.ServerMetric_Metric + metrics []*genericv1.GenericReport_Metric } tests := []struct { name string args args - want []*pmmv1.ServerMetric_Metric + want []*genericv1.GenericReport_Metric }{ { name: "should remove metrics with empty values", - args: args{metrics: []*pmmv1.ServerMetric_Metric{ + args: args{metrics: []*genericv1.GenericReport_Metric{ { Key: "empty_value", Value: "", @@ -323,7 +323,7 @@ func TestRemoveEmpty(t *testing.T) { Value: "", }, }}, - want: []*pmmv1.ServerMetric_Metric{ + want: []*genericv1.GenericReport_Metric{ { Key: "not_empty", Value: "not_empty", @@ -332,7 +332,7 @@ func TestRemoveEmpty(t *testing.T) { }, { name: "should not remove anything if metrics are not empty", - args: args{metrics: []*pmmv1.ServerMetric_Metric{ + args: args{metrics: []*genericv1.GenericReport_Metric{ { Key: "not_empty", Value: "not_empty", @@ -342,7 +342,7 @@ func TestRemoveEmpty(t *testing.T) { Value: "not_empty", }, }}, - want: []*pmmv1.ServerMetric_Metric{ + want: []*genericv1.GenericReport_Metric{ { Key: "not_empty", Value: "not_empty", @@ -356,7 +356,7 @@ func TestRemoveEmpty(t *testing.T) { { name: "should not remove anything if metrics are not empty", args: args{metrics: nil}, - want: []*pmmv1.ServerMetric_Metric{}, + want: []*genericv1.GenericReport_Metric{}, }, } diff --git a/managed/services/telemetry/uievents/uievents.go b/managed/services/telemetry/uievents/uievents.go index 1bee25ca8a..24f81cc5ad 100644 --- a/managed/services/telemetry/uievents/uievents.go +++ b/managed/services/telemetry/uievents/uievents.go @@ -24,7 +24,7 @@ import ( "time" "github.com/HdrHistogram/hdrhistogram-go" - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + genericv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/sirupsen/logrus" uieventsv1 "github.com/percona/pmm/api/uievents/v1" @@ -96,11 +96,11 @@ func (s *Service) ScheduleCleanup(ctx context.Context) { } // FetchMetrics fetches metrics for the service based on the provided context and telemetry configuration. -func (s *Service) FetchMetrics(_ context.Context, _ telemetry.Config) ([]*pmmv1.ServerMetric_Metric, error) { //nolint:unparam +func (s *Service) FetchMetrics(_ context.Context, _ telemetry.Config) ([]*genericv1.GenericReport_Metric, error) { //nolint:unparam s.stateM.RLock() defer s.stateM.RUnlock() - var result []*pmmv1.ServerMetric_Metric + var result []*genericv1.GenericReport_Metric if metric := s.processDashboardMetrics(); metric != nil { result = append(result, metric) } @@ -114,7 +114,7 @@ func (s *Service) FetchMetrics(_ context.Context, _ telemetry.Config) ([]*pmmv1. return result, nil } -func (s *Service) processDashboardMetrics() *pmmv1.ServerMetric_Metric { +func (s *Service) processDashboardMetrics() *genericv1.GenericReport_Metric { type Stat struct { TopDashboards []string `json:"top_dashboards"` SlowDashboardsP95_1s []string `json:"slow_dashboards_p95_1s"` @@ -170,13 +170,13 @@ func (s *Service) processDashboardMetrics() *pmmv1.ServerMetric_Metric { s.l.Error("failed to marshal to JSON") } - return &pmmv1.ServerMetric_Metric{ + return &genericv1.GenericReport_Metric{ Key: "ui-events-dashboards", Value: string(serializedDashboardStat), } } -func (s *Service) processComponentMetrics() *pmmv1.ServerMetric_Metric { +func (s *Service) processComponentMetrics() *genericv1.GenericReport_Metric { type Stat struct { SlowComponentsP95_1s []string `json:"slow_components_p95_1s"` SlowComponentsP95_5s []string `json:"slow_components_p95_5s"` @@ -220,20 +220,20 @@ func (s *Service) processComponentMetrics() *pmmv1.ServerMetric_Metric { if err != nil { s.l.Error("failed to marshal to JSON") } - return &pmmv1.ServerMetric_Metric{ + return &genericv1.GenericReport_Metric{ Key: "ui-events-components", Value: string(serializedComponentsStat), } } -func (s *Service) processUserFlowEvents() []*pmmv1.ServerMetric_Metric { - result := make([]*pmmv1.ServerMetric_Metric, 0, len(s.userFlowEvents)) +func (s *Service) processUserFlowEvents() []*genericv1.GenericReport_Metric { + result := make([]*genericv1.GenericReport_Metric, 0, len(s.userFlowEvents)) for _, event := range s.userFlowEvents { marshal, err := json.Marshal(event) if err != nil { s.l.Error("failed to marshal to JSON") } - result = append(result, &pmmv1.ServerMetric_Metric{ + result = append(result, &genericv1.GenericReport_Metric{ Key: "ui-events-user-flow", Value: string(marshal), }) diff --git a/managed/utils/platform/client.go b/managed/utils/platform/client.go index dca019327a..1926b949aa 100644 --- a/managed/utils/platform/client.go +++ b/managed/utils/platform/client.go @@ -25,7 +25,7 @@ import ( "net/http" api "github.com/percona/saas/gen/check/retrieval" - reporter "github.com/percona/saas/gen/telemetry/reporter" + reporter "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/grpc/codes" @@ -119,7 +119,7 @@ func (c *Client) GetTemplates(ctx context.Context) (*api.GetAllAlertRuleTemplate // SendTelemetry sends telemetry data to Percona Platform. func (c *Client) SendTelemetry(ctx context.Context, report *reporter.ReportRequest) error { - const path = "/v1/telemetry/Report" + const path = "/v1/telemetry/GenericReport" var accessToken string if ssoDetails, err := models.GetPerconaSSODetails(ctx, c.db.Querier); err == nil { From 4cb7eb95913ccb2a69ac101dec784dbe930f8829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Thu, 10 Oct 2024 14:58:23 +0200 Subject: [PATCH 03/13] PMM-13057 Changes. --- managed/services/telemetry/telemetry.go | 20 ++++++++++---------- managed/services/telemetry/telemetry_test.go | 19 +++++++++++++++++-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/managed/services/telemetry/telemetry.go b/managed/services/telemetry/telemetry.go index c5ab41c72d..ab1480b2c7 100644 --- a/managed/services/telemetry/telemetry.go +++ b/managed/services/telemetry/telemetry.go @@ -28,6 +28,7 @@ import ( genericv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" + "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" "gopkg.in/reform.v1" @@ -358,19 +359,18 @@ func (s *Service) makeMetric(ctx context.Context) (*genericv1.GenericReport, err if err != nil { return nil, errors.Wrapf(err, "failed to decode UUID %s", serverIDToUse) } - //_, distMethod, _ := s.dus.GetDistributionMethodAndOS() - - // todo - // PmmServerVersion: s.pmmVersion, - // UpDuration: durationpb.New(time.Since(s.start)), - // DistributionMethod: distMethod, + _, distMethod, _ := s.dus.GetDistributionMethodAndOS() eventID := uuid.New() return &genericv1.GenericReport{ - Id: string(eventID[:]), - CreateTime: timestamppb.New(time.Now()), - InstanceId: string(serverID), - ProductFamily: genericv1.ProductFamily_PRODUCT_FAMILY_PMM, + Id: string(eventID[:]), + CreateTime: timestamppb.New(time.Now()), + InstanceId: string(serverID), + Metrics: []*genericv1.GenericReport_Metric{ + {Key: "PMMServerVersion", Value: s.pmmVersion}, + {Key: "UpDuration", Value: durationpb.New(time.Since(s.start)).String()}, + {Key: "DistributionMethod", Value: distMethod.String()}, + }, }, nil } diff --git a/managed/services/telemetry/telemetry_test.go b/managed/services/telemetry/telemetry_test.go index 2b0401b83d..86e5ac498a 100644 --- a/managed/services/telemetry/telemetry_test.go +++ b/managed/services/telemetry/telemetry_test.go @@ -17,6 +17,7 @@ package telemetry import ( "context" + "fmt" "io/fs" "os" "testing" @@ -83,6 +84,10 @@ func TestRunTelemetryService(t *testing.T) { logEntry := logrus.NewEntry(logger) expectedServerMetrics := []*reporter.GenericReport_Metric{ + { + Key: "DistributionMethod", + Value: pmmv1.DistributionMethod_AMI.String(), + }, { Key: "key", Value: "value", @@ -295,9 +300,19 @@ func initMockTelemetrySender(t *testing.T, expectedReport *reporter.ReportReques } } +func valueIsInArray(items []*reporter.GenericReport_Metric, value string) bool { + for _, item := range items { + if item.Value == value { + return true + } + } + + return false +} + func matchExpectedReport(report *reporter.ReportRequest, expectedReport *reporter.ReportRequest) bool { - return len(report.Reports) == 1 //&& - // expectedReport.Reports[0].Metrics.DistributionMethod.String() == "AMI" + fmt.Println(expectedReport) + return len(report.Reports) == 1 && valueIsInArray(expectedReport.Reports[0].Metrics, "AMI") } func getTestConfig(sendOnStart bool, testSourceName string, reportingInterval time.Duration) ServiceConfig { From 94e377d2ffcf66eabcb4e597124349aaf6c2c56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Thu, 10 Oct 2024 15:03:02 +0200 Subject: [PATCH 04/13] PMM-13057 Tidy. --- go.sum | 1 + managed/services/telemetry/telemetry_test.go | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/go.sum b/go.sum index 9ea2336712..5ffdb00bba 100644 --- a/go.sum +++ b/go.sum @@ -645,6 +645,7 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= diff --git a/managed/services/telemetry/telemetry_test.go b/managed/services/telemetry/telemetry_test.go index 86e5ac498a..555f75888f 100644 --- a/managed/services/telemetry/telemetry_test.go +++ b/managed/services/telemetry/telemetry_test.go @@ -104,7 +104,6 @@ func TestRunTelemetryService(t *testing.T) { expectedReport := &reporter.ReportRequest{ Reports: []*reporter.GenericReport{ { - // DistributionMethod: pmmv1.DistributionMethod_AMI, Metrics: expectedServerMetrics, }, }, From 85b0b9a487c028ae48ef8815ecc855b5ca4f5225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Thu, 10 Oct 2024 15:05:42 +0200 Subject: [PATCH 05/13] PMM-13057 Tidy. --- go.sum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index 4257f0a7e4..9801821967 100644 --- a/go.sum +++ b/go.sum @@ -643,8 +643,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= From a23b1794f0c510ec33cae9e4936efcd7d810724a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Thu, 10 Oct 2024 15:17:49 +0200 Subject: [PATCH 06/13] PMM-13057 Remove print. --- managed/services/telemetry/telemetry_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/managed/services/telemetry/telemetry_test.go b/managed/services/telemetry/telemetry_test.go index 555f75888f..152373a9ad 100644 --- a/managed/services/telemetry/telemetry_test.go +++ b/managed/services/telemetry/telemetry_test.go @@ -17,7 +17,6 @@ package telemetry import ( "context" - "fmt" "io/fs" "os" "testing" @@ -310,7 +309,6 @@ func valueIsInArray(items []*reporter.GenericReport_Metric, value string) bool { } func matchExpectedReport(report *reporter.ReportRequest, expectedReport *reporter.ReportRequest) bool { - fmt.Println(expectedReport) return len(report.Reports) == 1 && valueIsInArray(expectedReport.Reports[0].Metrics, "AMI") } From 4c996e50472fea5438965159854ddd33b24553b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Thu, 10 Oct 2024 15:20:20 +0200 Subject: [PATCH 07/13] PMM-13057 Fix test. --- managed/services/telemetry/datasource_envvars_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/managed/services/telemetry/datasource_envvars_test.go b/managed/services/telemetry/datasource_envvars_test.go index fab2f72689..340a549a75 100644 --- a/managed/services/telemetry/datasource_envvars_test.go +++ b/managed/services/telemetry/datasource_envvars_test.go @@ -21,7 +21,7 @@ import ( "os" "testing" - pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + genericv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -94,7 +94,7 @@ func TestEnvVarsDatasource(t *testing.T) { metrics, err := dsEnvVars.FetchMetrics(ctx, *config) require.NoError(t, err) - expected := []*pmmv1.ServerMetric_Metric{ + expected := []*genericv1.GenericReport_Metric{ {Key: "test_env_var1", Value: "1"}, {Key: "test_env_var2", Value: "test"}, {Key: "test_env_var3", Value: "true"}, @@ -138,7 +138,7 @@ func TestEnvVarsDatasource(t *testing.T) { metrics, err := dsEnvVars.FetchMetrics(ctx, *config) require.NoError(t, err) - expected := []*pmmv1.ServerMetric_Metric{ + expected := []*genericv1.GenericReport_Metric{ {Key: "test_env_var6", Value: "1"}, {Key: "test_env_var7", Value: "1"}, {Key: "test_env_var8", Value: "1"}, From f450b11734fc3987f7956597a100f9a3bfe721c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Thu, 10 Oct 2024 15:26:35 +0200 Subject: [PATCH 08/13] PMM-13057 Refactor. --- managed/services/telemetry/telemetry.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/managed/services/telemetry/telemetry.go b/managed/services/telemetry/telemetry.go index ab1480b2c7..3e90864cb3 100644 --- a/managed/services/telemetry/telemetry.go +++ b/managed/services/telemetry/telemetry.go @@ -25,7 +25,7 @@ import ( "github.com/google/uuid" pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + reporter "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/protobuf/types/known/durationpb" @@ -53,7 +53,7 @@ type Service struct { os string sDistributionMethod serverv1.DistributionMethod tDistributionMethod pmmv1.DistributionMethod - sendCh chan *genericv1.GenericReport + sendCh chan *reporter.GenericReport dataSourcesMap map[DataSourceName]DataSource extensions map[ExtensionType]Extension @@ -89,7 +89,7 @@ func NewService(db *reform.DB, portalClient *platform.Client, pmmVersion string, config: config, dsRegistry: registry, dus: dus, - sendCh: make(chan *genericv1.GenericReport, sendChSize), + sendCh: make(chan *reporter.GenericReport, sendChSize), extensions: extensions, } @@ -167,7 +167,7 @@ func (s *Service) DistributionMethod() serverv1.DistributionMethod { func (s *Service) processSendCh(ctx context.Context) { var reportsBufSync sync.Mutex - var reportsBuf []*genericv1.GenericReport + var reportsBuf []*reporter.GenericReport var sendCtx context.Context //nolint:contextcheck var cancel context.CancelFunc @@ -184,11 +184,11 @@ func (s *Service) processSendCh(ctx context.Context) { reportsBufSync.Lock() reportsBuf = append(reportsBuf, report) reportsToSend := reportsBuf - reportsBuf = []*genericv1.GenericReport{} + reportsBuf = []*reporter.GenericReport{} reportsBufSync.Unlock() go func(ctx context.Context) { - err := s.send(ctx, &genericv1.ReportRequest{ + err := s.send(ctx, &reporter.ReportRequest{ Reports: reportsToSend, }) if err != nil { @@ -211,7 +211,7 @@ func (s *Service) processSendCh(ctx context.Context) { } } -func (s *Service) prepareReport(ctx context.Context) *genericv1.GenericReport { +func (s *Service) prepareReport(ctx context.Context) *reporter.GenericReport { initializedDataSources := make(map[DataSourceName]DataSource) telemetryMetric, _ := s.makeMetric(ctx) var totalTime time.Duration @@ -324,7 +324,7 @@ func (s *Service) locateDataSources(telemetryConfig []Config) map[DataSourceName return dataSources } -func (s *Service) makeMetric(ctx context.Context) (*genericv1.GenericReport, error) { +func (s *Service) makeMetric(ctx context.Context) (*reporter.GenericReport, error) { var settings *models.Settings useServerID := false err := s.db.InTransaction(func(tx *reform.TX) error { @@ -362,11 +362,11 @@ func (s *Service) makeMetric(ctx context.Context) (*genericv1.GenericReport, err _, distMethod, _ := s.dus.GetDistributionMethodAndOS() eventID := uuid.New() - return &genericv1.GenericReport{ + return &reporter.GenericReport{ Id: string(eventID[:]), CreateTime: timestamppb.New(time.Now()), InstanceId: string(serverID), - Metrics: []*genericv1.GenericReport_Metric{ + Metrics: []*reporter.GenericReport_Metric{ {Key: "PMMServerVersion", Value: s.pmmVersion}, {Key: "UpDuration", Value: durationpb.New(time.Since(s.start)).String()}, {Key: "DistributionMethod", Value: distMethod.String()}, @@ -385,7 +385,7 @@ func generateUUID() (string, error) { return cleanUUID, nil } -func (s *Service) send(ctx context.Context, report *genericv1.ReportRequest) error { +func (s *Service) send(ctx context.Context, report *reporter.ReportRequest) error { var err error var attempt int for { @@ -414,7 +414,7 @@ func (s *Service) send(ctx context.Context, report *genericv1.ReportRequest) err } // Format returns the formatted representation of the provided server metric. -func (s *Service) Format(report *genericv1.GenericReport) string { +func (s *Service) Format(report *reporter.GenericReport) string { var builder strings.Builder for _, m := range report.Metrics { builder.WriteString(m.Key) From 575f0f639cb7f5c45ce15c0909da2823cb4474fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Mon, 21 Oct 2024 09:02:18 +0200 Subject: [PATCH 09/13] PMM-13057 Format. --- managed/cmd/pmm-managed-starlark/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/managed/cmd/pmm-managed-starlark/main.go b/managed/cmd/pmm-managed-starlark/main.go index 3e89d4463f..71d891a0cd 100644 --- a/managed/cmd/pmm-managed-starlark/main.go +++ b/managed/cmd/pmm-managed-starlark/main.go @@ -24,8 +24,8 @@ import ( "time" "github.com/alecthomas/kingpin/v2" - "github.com/percona-platform/saas/pkg/check" - "github.com/percona-platform/saas/pkg/starlark" + "github.com/percona/saas/pkg/check" + "github.com/percona/saas/pkg/starlark" "github.com/pkg/errors" "github.com/sirupsen/logrus" "go.starlark.net/resolve" From 2eed88045b18cc4366b03c84543fbf23717ad63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Tue, 22 Oct 2024 09:21:56 +0200 Subject: [PATCH 10/13] PMM-13057 Fix for UUIDs format. --- managed/services/telemetry/telemetry.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/managed/services/telemetry/telemetry.go b/managed/services/telemetry/telemetry.go index 3e90864cb3..77f4aeee25 100644 --- a/managed/services/telemetry/telemetry.go +++ b/managed/services/telemetry/telemetry.go @@ -18,7 +18,6 @@ package telemetry import ( "context" - "encoding/hex" "strings" "sync" "time" @@ -348,24 +347,19 @@ func (s *Service) makeMetric(ctx context.Context) (*reporter.GenericReport, erro return nil, err } - var serverIDToUse string + var serverID string if useServerID { - serverIDToUse = strings.ReplaceAll(settings.PMMServerID, "-", "") + serverID = settings.PMMServerID } else { - serverIDToUse = settings.Telemetry.UUID + serverID = settings.Telemetry.UUID } - serverID, err := hex.DecodeString(serverIDToUse) - if err != nil { - return nil, errors.Wrapf(err, "failed to decode UUID %s", serverIDToUse) - } _, distMethod, _ := s.dus.GetDistributionMethodAndOS() - eventID := uuid.New() return &reporter.GenericReport{ - Id: string(eventID[:]), + Id: uuid.New().String(), CreateTime: timestamppb.New(time.Now()), - InstanceId: string(serverID), + InstanceId: uuid.MustParse(serverID).String(), Metrics: []*reporter.GenericReport_Metric{ {Key: "PMMServerVersion", Value: s.pmmVersion}, {Key: "UpDuration", Value: durationpb.New(time.Since(s.start)).String()}, @@ -380,9 +374,7 @@ func generateUUID() (string, error) { return "", errors.Wrap(err, "can't generate UUID") } - // Old telemetry IDs have only 32 chars in the table but UUIDs + "-" = 36 - cleanUUID := strings.ReplaceAll(uuid.String(), "-", "") - return cleanUUID, nil + return uuid.String(), nil } func (s *Service) send(ctx context.Context, report *reporter.ReportRequest) error { From 8ed1997a2d5857bcf53279b46fa39ea71914e3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Tue, 22 Oct 2024 10:03:47 +0200 Subject: [PATCH 11/13] PMM-13057 Add product family field. --- managed/services/telemetry/telemetry.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/managed/services/telemetry/telemetry.go b/managed/services/telemetry/telemetry.go index 77f4aeee25..c20029fa3b 100644 --- a/managed/services/telemetry/telemetry.go +++ b/managed/services/telemetry/telemetry.go @@ -357,9 +357,10 @@ func (s *Service) makeMetric(ctx context.Context) (*reporter.GenericReport, erro _, distMethod, _ := s.dus.GetDistributionMethodAndOS() return &reporter.GenericReport{ - Id: uuid.New().String(), - CreateTime: timestamppb.New(time.Now()), - InstanceId: uuid.MustParse(serverID).String(), + Id: uuid.New().String(), + CreateTime: timestamppb.New(time.Now()), + InstanceId: uuid.MustParse(serverID).String(), + ProductFamily: reporter.ProductFamily_PRODUCT_FAMILY_PMM, Metrics: []*reporter.GenericReport_Metric{ {Key: "PMMServerVersion", Value: s.pmmVersion}, {Key: "UpDuration", Value: durationpb.New(time.Since(s.start)).String()}, From 591a26f5ff6db9cec779cdad25a2d3b34d5aa063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Thu, 31 Oct 2024 10:39:15 +0100 Subject: [PATCH 12/13] PMM-13057 Requested renaming. --- .../services/telemetry/datasource_envvars.go | 8 ++-- .../telemetry/datasource_envvars_test.go | 6 +-- .../telemetry/datasource_grafanadb_select.go | 4 +- .../telemetry/datasource_pmmdb_select.go | 4 +- .../telemetry/datasource_qandb_select.go | 4 +- .../telemetry/datasource_victoria_metrics.go | 10 ++-- managed/services/telemetry/datasources.go | 8 ++-- managed/services/telemetry/deps.go | 6 +-- managed/services/telemetry/extension.go | 4 +- .../telemetry/mock_data_source_test.go | 12 ++--- .../services/telemetry/mock_sender_test.go | 6 +-- managed/services/telemetry/telemetry.go | 25 +++++----- managed/services/telemetry/telemetry_test.go | 18 +++---- managed/services/telemetry/transform.go | 12 ++--- managed/services/telemetry/transform_test.go | 48 +++++++++---------- .../services/telemetry/uievents/uievents.go | 20 ++++---- managed/utils/platform/client.go | 3 +- 17 files changed, 98 insertions(+), 100 deletions(-) diff --git a/managed/services/telemetry/datasource_envvars.go b/managed/services/telemetry/datasource_envvars.go index 0a90e36701..0e2fe89a24 100644 --- a/managed/services/telemetry/datasource_envvars.go +++ b/managed/services/telemetry/datasource_envvars.go @@ -20,7 +20,7 @@ import ( "context" "os" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/sirupsen/logrus" ) @@ -51,8 +51,8 @@ func (d *dsEnvvars) Init(_ context.Context) error { return nil } -func (d *dsEnvvars) FetchMetrics(_ context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { - var metrics []*genericv1.GenericReport_Metric +func (d *dsEnvvars) FetchMetrics(_ context.Context, config Config) ([]*telemetryv1.GenericReport_Metric, error) { + var metrics []*telemetryv1.GenericReport_Metric check := make(map[string]bool, len(config.Data)) @@ -69,7 +69,7 @@ func (d *dsEnvvars) FetchMetrics(_ context.Context, config Config) ([]*genericv1 check[col.MetricName] = true - metrics = append(metrics, &genericv1.GenericReport_Metric{ + metrics = append(metrics, &telemetryv1.GenericReport_Metric{ Key: col.MetricName, Value: value, }) diff --git a/managed/services/telemetry/datasource_envvars_test.go b/managed/services/telemetry/datasource_envvars_test.go index 340a549a75..8bd152eb09 100644 --- a/managed/services/telemetry/datasource_envvars_test.go +++ b/managed/services/telemetry/datasource_envvars_test.go @@ -21,7 +21,7 @@ import ( "os" "testing" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -94,7 +94,7 @@ func TestEnvVarsDatasource(t *testing.T) { metrics, err := dsEnvVars.FetchMetrics(ctx, *config) require.NoError(t, err) - expected := []*genericv1.GenericReport_Metric{ + expected := []*telemetryv1.GenericReport_Metric{ {Key: "test_env_var1", Value: "1"}, {Key: "test_env_var2", Value: "test"}, {Key: "test_env_var3", Value: "true"}, @@ -138,7 +138,7 @@ func TestEnvVarsDatasource(t *testing.T) { metrics, err := dsEnvVars.FetchMetrics(ctx, *config) require.NoError(t, err) - expected := []*genericv1.GenericReport_Metric{ + expected := []*telemetryv1.GenericReport_Metric{ {Key: "test_env_var6", Value: "1"}, {Key: "test_env_var7", Value: "1"}, {Key: "test_env_var8", Value: "1"}, diff --git a/managed/services/telemetry/datasource_grafanadb_select.go b/managed/services/telemetry/datasource_grafanadb_select.go index 41ac9800e3..2e46b02ca7 100644 --- a/managed/services/telemetry/datasource_grafanadb_select.go +++ b/managed/services/telemetry/datasource_grafanadb_select.go @@ -22,7 +22,7 @@ import ( "net/url" "time" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -94,7 +94,7 @@ func openGrafanaDBConnection(config DSConfigGrafanaDB, l *logrus.Entry) (*sql.DB return db, nil } -func (d *dsGrafanaDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { +func (d *dsGrafanaDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*telemetryv1.GenericReport_Metric, error) { return fetchMetricsFromDB(ctx, d.l, d.config.Timeout, d.db, config) } diff --git a/managed/services/telemetry/datasource_pmmdb_select.go b/managed/services/telemetry/datasource_pmmdb_select.go index 0559f54c9f..0a5276b383 100644 --- a/managed/services/telemetry/datasource_pmmdb_select.go +++ b/managed/services/telemetry/datasource_pmmdb_select.go @@ -22,7 +22,7 @@ import ( "net/url" "time" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -94,7 +94,7 @@ func openPMMDBConnection(config DSConfigPMMDB, l *logrus.Entry) (*sql.DB, error) return db, nil } -func (d *dsPmmDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { +func (d *dsPmmDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*telemetryv1.GenericReport_Metric, error) { return fetchMetricsFromDB(ctx, d.l, d.config.Timeout, d.db, config) } diff --git a/managed/services/telemetry/datasource_qandb_select.go b/managed/services/telemetry/datasource_qandb_select.go index 4808d576dc..94fff62d31 100644 --- a/managed/services/telemetry/datasource_qandb_select.go +++ b/managed/services/telemetry/datasource_qandb_select.go @@ -20,7 +20,7 @@ import ( "context" "database/sql" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -69,7 +69,7 @@ func openQANDBConnection(dsn string, enabled bool, l *logrus.Entry) (*sql.DB, er return db, nil } -func (d *dsQanDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { +func (d *dsQanDBSelect) FetchMetrics(ctx context.Context, config Config) ([]*telemetryv1.GenericReport_Metric, error) { return fetchMetricsFromDB(ctx, d.l, d.config.Timeout, d.db, config) } diff --git a/managed/services/telemetry/datasource_victoria_metrics.go b/managed/services/telemetry/datasource_victoria_metrics.go index 49564b7856..8a8efd3b89 100644 --- a/managed/services/telemetry/datasource_victoria_metrics.go +++ b/managed/services/telemetry/datasource_victoria_metrics.go @@ -20,7 +20,7 @@ import ( "context" "time" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/prometheus/client_golang/api" v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prometheus/common/model" @@ -66,7 +66,7 @@ func NewDataSourceVictoriaMetrics(config DSConfigVM, l *logrus.Entry) (DataSourc }, nil } -func (d *dataSourceVictoriaMetrics) FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { +func (d *dataSourceVictoriaMetrics) FetchMetrics(ctx context.Context, config Config) ([]*telemetryv1.GenericReport_Metric, error) { localCtx, cancel := context.WithTimeout(ctx, d.config.Timeout) defer cancel() @@ -75,20 +75,20 @@ func (d *dataSourceVictoriaMetrics) FetchMetrics(ctx context.Context, config Con return nil, err } - var metrics []*genericv1.GenericReport_Metric + var metrics []*telemetryv1.GenericReport_Metric for _, v := range result.(model.Vector) { //nolint:forcetypeassert for _, configItem := range config.Data { if configItem.Label != "" { value := v.Metric[model.LabelName(configItem.Label)] - metrics = append(metrics, &genericv1.GenericReport_Metric{ + metrics = append(metrics, &telemetryv1.GenericReport_Metric{ Key: configItem.MetricName, Value: string(value), }) } if configItem.Value != "" { - metrics = append(metrics, &genericv1.GenericReport_Metric{ + metrics = append(metrics, &telemetryv1.GenericReport_Metric{ Key: configItem.MetricName, Value: v.Value.String(), }) diff --git a/managed/services/telemetry/datasources.go b/managed/services/telemetry/datasources.go index 47ea33bde5..0529fb2ebe 100644 --- a/managed/services/telemetry/datasources.go +++ b/managed/services/telemetry/datasources.go @@ -22,7 +22,7 @@ import ( "time" "github.com/AlekSi/pointer" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -77,7 +77,7 @@ func (r *dataSourceRegistry) LocateTelemetryDataSource(name string) (DataSource, return ds, nil } -func fetchMetricsFromDB(ctx context.Context, l *logrus.Entry, timeout time.Duration, db *sql.DB, config Config) ([]*genericv1.GenericReport_Metric, error) { +func fetchMetricsFromDB(ctx context.Context, l *logrus.Entry, timeout time.Duration, db *sql.DB, config Config) ([]*telemetryv1.GenericReport_Metric, error) { localCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() tx, err := db.BeginTx(localCtx, &sql.TxOptions{}) @@ -104,7 +104,7 @@ func fetchMetricsFromDB(ctx context.Context, l *logrus.Entry, timeout time.Durat } cfgColumns := config.mapByColumn() - var metrics []*genericv1.GenericReport_Metric + var metrics []*telemetryv1.GenericReport_Metric for rows.Next() { if err := rows.Scan(values...); err != nil { l.Error(err) @@ -116,7 +116,7 @@ func fetchMetricsFromDB(ctx context.Context, l *logrus.Entry, timeout time.Durat if cols, ok := cfgColumns[column]; ok { for _, col := range cols { - metrics = append(metrics, &genericv1.GenericReport_Metric{ + metrics = append(metrics, &telemetryv1.GenericReport_Metric{ Key: col.MetricName, Value: value, }) diff --git a/managed/services/telemetry/deps.go b/managed/services/telemetry/deps.go index dca26ee7b1..8e97ec58fa 100644 --- a/managed/services/telemetry/deps.go +++ b/managed/services/telemetry/deps.go @@ -19,7 +19,7 @@ import ( "context" pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" - reporter "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" serverv1 "github.com/percona/pmm/api/server/v1" ) @@ -31,7 +31,7 @@ type distributionUtilService interface { // sender is interface which defines method for client which sends report with metrics. type sender interface { - SendTelemetry(ctx context.Context, report *reporter.ReportRequest) error + SendTelemetry(ctx context.Context, report *telemetryv1.ReportRequest) error } // DataSourceLocator locates data source by name. @@ -42,7 +42,7 @@ type DataSourceLocator interface { // DataSource telemetry data source. type DataSource interface { Init(ctx context.Context) error - FetchMetrics(ctx context.Context, config Config) ([]*reporter.GenericReport_Metric, error) + FetchMetrics(ctx context.Context, config Config) ([]*telemetryv1.GenericReport_Metric, error) Dispose(ctx context.Context) error Enabled() bool } diff --git a/managed/services/telemetry/extension.go b/managed/services/telemetry/extension.go index 1250c61463..ebe4e40c9f 100644 --- a/managed/services/telemetry/extension.go +++ b/managed/services/telemetry/extension.go @@ -18,10 +18,10 @@ package telemetry import ( "context" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" ) // Extension provides dynamic extension point for Telemetry. type Extension interface { - FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) + FetchMetrics(ctx context.Context, config Config) ([]*telemetryv1.GenericReport_Metric, error) } diff --git a/managed/services/telemetry/mock_data_source_test.go b/managed/services/telemetry/mock_data_source_test.go index e6b004ebb5..8c0b53e3a5 100644 --- a/managed/services/telemetry/mock_data_source_test.go +++ b/managed/services/telemetry/mock_data_source_test.go @@ -5,7 +5,7 @@ package telemetry import ( context "context" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" mock "github.com/stretchr/testify/mock" ) @@ -51,23 +51,23 @@ func (_m *mockDataSource) Enabled() bool { } // FetchMetrics provides a mock function with given fields: ctx, config -func (_m *mockDataSource) FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { +func (_m *mockDataSource) FetchMetrics(ctx context.Context, config Config) ([]*telemetryv1.GenericReport_Metric, error) { ret := _m.Called(ctx, config) if len(ret) == 0 { panic("no return value specified for FetchMetrics") } - var r0 []*genericv1.GenericReport_Metric + var r0 []*telemetryv1.GenericReport_Metric var r1 error - if rf, ok := ret.Get(0).(func(context.Context, Config) ([]*genericv1.GenericReport_Metric, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, Config) ([]*telemetryv1.GenericReport_Metric, error)); ok { return rf(ctx, config) } - if rf, ok := ret.Get(0).(func(context.Context, Config) []*genericv1.GenericReport_Metric); ok { + if rf, ok := ret.Get(0).(func(context.Context, Config) []*telemetryv1.GenericReport_Metric); ok { r0 = rf(ctx, config) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*genericv1.GenericReport_Metric) + r0 = ret.Get(0).([]*telemetryv1.GenericReport_Metric) } } diff --git a/managed/services/telemetry/mock_sender_test.go b/managed/services/telemetry/mock_sender_test.go index 3c943e8de4..8230bff6ed 100644 --- a/managed/services/telemetry/mock_sender_test.go +++ b/managed/services/telemetry/mock_sender_test.go @@ -5,7 +5,7 @@ package telemetry import ( context "context" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" mock "github.com/stretchr/testify/mock" ) @@ -15,7 +15,7 @@ type mockSender struct { } // SendTelemetry provides a mock function with given fields: ctx, report -func (_m *mockSender) SendTelemetry(ctx context.Context, report *genericv1.ReportRequest) error { +func (_m *mockSender) SendTelemetry(ctx context.Context, report *telemetryv1.ReportRequest) error { ret := _m.Called(ctx, report) if len(ret) == 0 { @@ -23,7 +23,7 @@ func (_m *mockSender) SendTelemetry(ctx context.Context, report *genericv1.Repor } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *genericv1.ReportRequest) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *telemetryv1.ReportRequest) error); ok { r0 = rf(ctx, report) } else { r0 = ret.Error(0) diff --git a/managed/services/telemetry/telemetry.go b/managed/services/telemetry/telemetry.go index c20029fa3b..4e49bb20a3 100644 --- a/managed/services/telemetry/telemetry.go +++ b/managed/services/telemetry/telemetry.go @@ -24,7 +24,6 @@ import ( "github.com/google/uuid" pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" - reporter "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/protobuf/types/known/durationpb" @@ -52,7 +51,7 @@ type Service struct { os string sDistributionMethod serverv1.DistributionMethod tDistributionMethod pmmv1.DistributionMethod - sendCh chan *reporter.GenericReport + sendCh chan *telemetryv1.GenericReport dataSourcesMap map[DataSourceName]DataSource extensions map[ExtensionType]Extension @@ -88,7 +87,7 @@ func NewService(db *reform.DB, portalClient *platform.Client, pmmVersion string, config: config, dsRegistry: registry, dus: dus, - sendCh: make(chan *reporter.GenericReport, sendChSize), + sendCh: make(chan *telemetryv1.GenericReport, sendChSize), extensions: extensions, } @@ -166,7 +165,7 @@ func (s *Service) DistributionMethod() serverv1.DistributionMethod { func (s *Service) processSendCh(ctx context.Context) { var reportsBufSync sync.Mutex - var reportsBuf []*reporter.GenericReport + var reportsBuf []*telemetryv1.GenericReport var sendCtx context.Context //nolint:contextcheck var cancel context.CancelFunc @@ -183,11 +182,11 @@ func (s *Service) processSendCh(ctx context.Context) { reportsBufSync.Lock() reportsBuf = append(reportsBuf, report) reportsToSend := reportsBuf - reportsBuf = []*reporter.GenericReport{} + reportsBuf = []*telemetryv1.GenericReport{} reportsBufSync.Unlock() go func(ctx context.Context) { - err := s.send(ctx, &reporter.ReportRequest{ + err := s.send(ctx, &telemetryv1.ReportRequest{ Reports: reportsToSend, }) if err != nil { @@ -210,7 +209,7 @@ func (s *Service) processSendCh(ctx context.Context) { } } -func (s *Service) prepareReport(ctx context.Context) *reporter.GenericReport { +func (s *Service) prepareReport(ctx context.Context) *telemetryv1.GenericReport { initializedDataSources := make(map[DataSourceName]DataSource) telemetryMetric, _ := s.makeMetric(ctx) var totalTime time.Duration @@ -323,7 +322,7 @@ func (s *Service) locateDataSources(telemetryConfig []Config) map[DataSourceName return dataSources } -func (s *Service) makeMetric(ctx context.Context) (*reporter.GenericReport, error) { +func (s *Service) makeMetric(ctx context.Context) (*telemetryv1.GenericReport, error) { var settings *models.Settings useServerID := false err := s.db.InTransaction(func(tx *reform.TX) error { @@ -356,12 +355,12 @@ func (s *Service) makeMetric(ctx context.Context) (*reporter.GenericReport, erro _, distMethod, _ := s.dus.GetDistributionMethodAndOS() - return &reporter.GenericReport{ + return &telemetryv1.GenericReport{ Id: uuid.New().String(), CreateTime: timestamppb.New(time.Now()), InstanceId: uuid.MustParse(serverID).String(), - ProductFamily: reporter.ProductFamily_PRODUCT_FAMILY_PMM, - Metrics: []*reporter.GenericReport_Metric{ + ProductFamily: telemetryv1.ProductFamily_PRODUCT_FAMILY_PMM, + Metrics: []*telemetryv1.GenericReport_Metric{ {Key: "PMMServerVersion", Value: s.pmmVersion}, {Key: "UpDuration", Value: durationpb.New(time.Since(s.start)).String()}, {Key: "DistributionMethod", Value: distMethod.String()}, @@ -378,7 +377,7 @@ func generateUUID() (string, error) { return uuid.String(), nil } -func (s *Service) send(ctx context.Context, report *reporter.ReportRequest) error { +func (s *Service) send(ctx context.Context, report *telemetryv1.ReportRequest) error { var err error var attempt int for { @@ -407,7 +406,7 @@ func (s *Service) send(ctx context.Context, report *reporter.ReportRequest) erro } // Format returns the formatted representation of the provided server metric. -func (s *Service) Format(report *reporter.GenericReport) string { +func (s *Service) Format(report *telemetryv1.GenericReport) string { var builder strings.Builder for _, m := range report.Metrics { builder.WriteString(m.Key) diff --git a/managed/services/telemetry/telemetry_test.go b/managed/services/telemetry/telemetry_test.go index 152373a9ad..fe13e1a968 100644 --- a/managed/services/telemetry/telemetry_test.go +++ b/managed/services/telemetry/telemetry_test.go @@ -24,7 +24,7 @@ import ( _ "github.com/ClickHouse/clickhouse-go/v2" pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" - reporter "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -82,7 +82,7 @@ func TestRunTelemetryService(t *testing.T) { logger.SetLevel(logrus.DebugLevel) logEntry := logrus.NewEntry(logger) - expectedServerMetrics := []*reporter.GenericReport_Metric{ + expectedServerMetrics := []*telemetryv1.GenericReport_Metric{ { Key: "DistributionMethod", Value: pmmv1.DistributionMethod_AMI.String(), @@ -100,8 +100,8 @@ func TestRunTelemetryService(t *testing.T) { Value: "value3", }, } - expectedReport := &reporter.ReportRequest{ - Reports: []*reporter.GenericReport{ + expectedReport := &telemetryv1.ReportRequest{ + Reports: []*telemetryv1.GenericReport{ { Metrics: expectedServerMetrics, }, @@ -179,7 +179,7 @@ func TestRunTelemetryService(t *testing.T) { tDistributionMethod: 0, dus: tt.fields.dus, portalClient: tt.mockTelemetrySender(), - sendCh: make(chan *reporter.GenericReport, sendChSize), + sendCh: make(chan *telemetryv1.GenericReport, sendChSize), } s.Run(ctx) }) @@ -277,14 +277,14 @@ func getDistributionUtilService(t *testing.T, l *logrus.Entry) distributionUtilS return dus } -func initMockTelemetrySender(t *testing.T, expectedReport *reporter.ReportRequest, timesCall int) func() sender { +func initMockTelemetrySender(t *testing.T, expectedReport *telemetryv1.ReportRequest, timesCall int) func() sender { t.Helper() return func() sender { var mockTelemetrySender mockSender mockTelemetrySender.Test(t) mockTelemetrySender.On("SendTelemetry", mock.Anything, - mock.MatchedBy(func(report *reporter.ReportRequest) bool { + mock.MatchedBy(func(report *telemetryv1.ReportRequest) bool { return matchExpectedReport(report, expectedReport) }), ). @@ -298,7 +298,7 @@ func initMockTelemetrySender(t *testing.T, expectedReport *reporter.ReportReques } } -func valueIsInArray(items []*reporter.GenericReport_Metric, value string) bool { +func valueIsInArray(items []*telemetryv1.GenericReport_Metric, value string) bool { for _, item := range items { if item.Value == value { return true @@ -308,7 +308,7 @@ func valueIsInArray(items []*reporter.GenericReport_Metric, value string) bool { return false } -func matchExpectedReport(report *reporter.ReportRequest, expectedReport *reporter.ReportRequest) bool { +func matchExpectedReport(report *telemetryv1.ReportRequest, expectedReport *telemetryv1.ReportRequest) bool { return len(report.Reports) == 1 && valueIsInArray(expectedReport.Reports[0].Metrics, "AMI") } diff --git a/managed/services/telemetry/transform.go b/managed/services/telemetry/transform.go index 6543354223..da20fa6508 100644 --- a/managed/services/telemetry/transform.go +++ b/managed/services/telemetry/transform.go @@ -18,13 +18,13 @@ package telemetry import ( "encoding/json" - reporter "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" ) type itemsType []map[string]any -func transformToJSON(config *Config, metrics []*reporter.GenericReport_Metric) ([]*reporter.GenericReport_Metric, error) { +func transformToJSON(config *Config, metrics []*telemetryv1.GenericReport_Metric) ([]*telemetryv1.GenericReport_Metric, error) { if len(metrics) == 0 { return metrics, nil } @@ -78,7 +78,7 @@ func transformToJSON(config *Config, metrics []*reporter.GenericReport_Metric) ( return nil, err } - return []*reporter.GenericReport_Metric{ + return []*telemetryv1.GenericReport_Metric{ { Key: config.Transform.Metric, Value: string(resultAsJSON), @@ -86,7 +86,7 @@ func transformToJSON(config *Config, metrics []*reporter.GenericReport_Metric) ( }, nil } -func transformExportValues(config *Config, metrics []*reporter.GenericReport_Metric) ([]*reporter.GenericReport_Metric, error) { +func transformExportValues(config *Config, metrics []*telemetryv1.GenericReport_Metric) ([]*telemetryv1.GenericReport_Metric, error) { if len(metrics) == 0 { return metrics, nil } @@ -107,8 +107,8 @@ func transformExportValues(config *Config, metrics []*reporter.GenericReport_Met return metrics, nil } -func removeEmpty(metrics []*reporter.GenericReport_Metric) []*reporter.GenericReport_Metric { - result := make([]*reporter.GenericReport_Metric, 0, len(metrics)) +func removeEmpty(metrics []*telemetryv1.GenericReport_Metric) []*telemetryv1.GenericReport_Metric { + result := make([]*telemetryv1.GenericReport_Metric, 0, len(metrics)) for _, metric := range metrics { if metric.Value != "" { diff --git a/managed/services/telemetry/transform_test.go b/managed/services/telemetry/transform_test.go index ebaaf25c27..06018f3a87 100644 --- a/managed/services/telemetry/transform_test.go +++ b/managed/services/telemetry/transform_test.go @@ -18,22 +18,22 @@ package telemetry import ( "testing" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/stretchr/testify/assert" ) func TestTransformToJSON(t *testing.T) { type args struct { config *Config - metrics []*genericv1.GenericReport_Metric + metrics []*telemetryv1.GenericReport_Metric } - noMetrics := []*genericv1.GenericReport_Metric{} + noMetrics := []*telemetryv1.GenericReport_Metric{} tests := []struct { name string args args - want []*genericv1.GenericReport_Metric + want []*telemetryv1.GenericReport_Metric wantErr assert.ErrorAssertionFunc }{ { @@ -85,7 +85,7 @@ func TestTransformToJSON(t *testing.T) { name: "invalid seq", args: args{ config: configJSON(), - metrics: []*genericv1.GenericReport_Metric{ + metrics: []*telemetryv1.GenericReport_Metric{ {Key: "my-metric", Value: "v1"}, {Key: "b", Value: "v1"}, {Key: "b", Value: "v1"}, // <--- will override second metric @@ -99,14 +99,14 @@ func TestTransformToJSON(t *testing.T) { name: "correct seq", args: args{ config: configJSON(), - metrics: []*genericv1.GenericReport_Metric{ + metrics: []*telemetryv1.GenericReport_Metric{ {Key: "my-metric", Value: "v1"}, {Key: "b", Value: "v1"}, {Key: "my-metric", Value: "v1"}, {Key: "b", Value: "v1"}, }, }, - want: []*genericv1.GenericReport_Metric{ + want: []*telemetryv1.GenericReport_Metric{ {Key: configJSON().Transform.Metric, Value: `{"v":[{"b":"v1","my-metric":"v1"},{"b":"v1","my-metric":"v1"}]}`}, }, wantErr: assert.NoError, @@ -115,12 +115,12 @@ func TestTransformToJSON(t *testing.T) { name: "happy path", args: args{ config: configJSON(), - metrics: []*genericv1.GenericReport_Metric{ + metrics: []*telemetryv1.GenericReport_Metric{ {Key: configJSON().Data[0].MetricName, Value: "v1"}, {Key: configJSON().Data[0].MetricName, Value: "v2"}, }, }, - want: []*genericv1.GenericReport_Metric{ + want: []*telemetryv1.GenericReport_Metric{ {Key: configJSON().Transform.Metric, Value: `{"v":[{"my-metric":"v1"},{"my-metric":"v2"}]}`}, }, wantErr: assert.NoError, @@ -135,14 +135,14 @@ func TestTransformToJSON(t *testing.T) { {MetricName: "4", Label: "status"}, {MetricName: "5", Label: "type"}, }), - metrics: []*genericv1.GenericReport_Metric{ + metrics: []*telemetryv1.GenericReport_Metric{ {Key: "licence", Value: `GPL`}, {Key: "name", Value: `INNODB_TABLES`}, {Key: "status", Value: `ACTIVE`}, {Key: "type", Value: `INFORMATION SCHEMA`}, }, }, - want: []*genericv1.GenericReport_Metric{ + want: []*telemetryv1.GenericReport_Metric{ {Key: "metric", Value: `{"v":[{"licence":"GPL","name":"INNODB_TABLES","status":"ACTIVE","type":"INFORMATION SCHEMA"}]}`}, }, wantErr: assert.NoError, @@ -164,15 +164,15 @@ func TestTransformToJSON(t *testing.T) { func TestTransformExportValues(t *testing.T) { type args struct { config *Config - metrics []*genericv1.GenericReport_Metric + metrics []*telemetryv1.GenericReport_Metric } - noMetrics := []*genericv1.GenericReport_Metric{} + noMetrics := []*telemetryv1.GenericReport_Metric{} tests := []struct { name string args args - want []*genericv1.GenericReport_Metric + want []*telemetryv1.GenericReport_Metric wantErr assert.ErrorAssertionFunc }{ { @@ -215,7 +215,7 @@ func TestTransformExportValues(t *testing.T) { name: "invalid data source", args: args{ config: configEnvVars().changeDataSource(dsPMMDBSelect), - metrics: []*genericv1.GenericReport_Metric{ + metrics: []*telemetryv1.GenericReport_Metric{ {Key: "metric-a", Value: "v1"}, {Key: "metric-b", Value: "v2"}, }, @@ -227,12 +227,12 @@ func TestTransformExportValues(t *testing.T) { name: "happy path", args: args{ config: configEnvVars(), - metrics: []*genericv1.GenericReport_Metric{ + metrics: []*telemetryv1.GenericReport_Metric{ {Key: "metric-a", Value: "v1"}, {Key: "metric-b", Value: "v2"}, }, }, - want: []*genericv1.GenericReport_Metric{ + want: []*telemetryv1.GenericReport_Metric{ {Key: "metric-a", Value: "1"}, {Key: "metric-b", Value: "1"}, }, @@ -300,16 +300,16 @@ func (c *Config) changeData(d []ConfigData) *Config { func TestRemoveEmpty(t *testing.T) { type args struct { - metrics []*genericv1.GenericReport_Metric + metrics []*telemetryv1.GenericReport_Metric } tests := []struct { name string args args - want []*genericv1.GenericReport_Metric + want []*telemetryv1.GenericReport_Metric }{ { name: "should remove metrics with empty values", - args: args{metrics: []*genericv1.GenericReport_Metric{ + args: args{metrics: []*telemetryv1.GenericReport_Metric{ { Key: "empty_value", Value: "", @@ -323,7 +323,7 @@ func TestRemoveEmpty(t *testing.T) { Value: "", }, }}, - want: []*genericv1.GenericReport_Metric{ + want: []*telemetryv1.GenericReport_Metric{ { Key: "not_empty", Value: "not_empty", @@ -332,7 +332,7 @@ func TestRemoveEmpty(t *testing.T) { }, { name: "should not remove anything if metrics are not empty", - args: args{metrics: []*genericv1.GenericReport_Metric{ + args: args{metrics: []*telemetryv1.GenericReport_Metric{ { Key: "not_empty", Value: "not_empty", @@ -342,7 +342,7 @@ func TestRemoveEmpty(t *testing.T) { Value: "not_empty", }, }}, - want: []*genericv1.GenericReport_Metric{ + want: []*telemetryv1.GenericReport_Metric{ { Key: "not_empty", Value: "not_empty", @@ -356,7 +356,7 @@ func TestRemoveEmpty(t *testing.T) { { name: "should not remove anything if metrics are not empty", args: args{metrics: nil}, - want: []*genericv1.GenericReport_Metric{}, + want: []*telemetryv1.GenericReport_Metric{}, }, } diff --git a/managed/services/telemetry/uievents/uievents.go b/managed/services/telemetry/uievents/uievents.go index 24f81cc5ad..6d711616d3 100644 --- a/managed/services/telemetry/uievents/uievents.go +++ b/managed/services/telemetry/uievents/uievents.go @@ -24,7 +24,7 @@ import ( "time" "github.com/HdrHistogram/hdrhistogram-go" - genericv1 "github.com/percona/saas/gen/telemetry/generic" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/sirupsen/logrus" uieventsv1 "github.com/percona/pmm/api/uievents/v1" @@ -96,11 +96,11 @@ func (s *Service) ScheduleCleanup(ctx context.Context) { } // FetchMetrics fetches metrics for the service based on the provided context and telemetry configuration. -func (s *Service) FetchMetrics(_ context.Context, _ telemetry.Config) ([]*genericv1.GenericReport_Metric, error) { //nolint:unparam +func (s *Service) FetchMetrics(_ context.Context, _ telemetry.Config) ([]*telemetryv1.GenericReport_Metric, error) { //nolint:unparam s.stateM.RLock() defer s.stateM.RUnlock() - var result []*genericv1.GenericReport_Metric + var result []*telemetryv1.GenericReport_Metric if metric := s.processDashboardMetrics(); metric != nil { result = append(result, metric) } @@ -114,7 +114,7 @@ func (s *Service) FetchMetrics(_ context.Context, _ telemetry.Config) ([]*generi return result, nil } -func (s *Service) processDashboardMetrics() *genericv1.GenericReport_Metric { +func (s *Service) processDashboardMetrics() *telemetryv1.GenericReport_Metric { type Stat struct { TopDashboards []string `json:"top_dashboards"` SlowDashboardsP95_1s []string `json:"slow_dashboards_p95_1s"` @@ -170,13 +170,13 @@ func (s *Service) processDashboardMetrics() *genericv1.GenericReport_Metric { s.l.Error("failed to marshal to JSON") } - return &genericv1.GenericReport_Metric{ + return &telemetryv1.GenericReport_Metric{ Key: "ui-events-dashboards", Value: string(serializedDashboardStat), } } -func (s *Service) processComponentMetrics() *genericv1.GenericReport_Metric { +func (s *Service) processComponentMetrics() *telemetryv1.GenericReport_Metric { type Stat struct { SlowComponentsP95_1s []string `json:"slow_components_p95_1s"` SlowComponentsP95_5s []string `json:"slow_components_p95_5s"` @@ -220,20 +220,20 @@ func (s *Service) processComponentMetrics() *genericv1.GenericReport_Metric { if err != nil { s.l.Error("failed to marshal to JSON") } - return &genericv1.GenericReport_Metric{ + return &telemetryv1.GenericReport_Metric{ Key: "ui-events-components", Value: string(serializedComponentsStat), } } -func (s *Service) processUserFlowEvents() []*genericv1.GenericReport_Metric { - result := make([]*genericv1.GenericReport_Metric, 0, len(s.userFlowEvents)) +func (s *Service) processUserFlowEvents() []*telemetryv1.GenericReport_Metric { + result := make([]*telemetryv1.GenericReport_Metric, 0, len(s.userFlowEvents)) for _, event := range s.userFlowEvents { marshal, err := json.Marshal(event) if err != nil { s.l.Error("failed to marshal to JSON") } - result = append(result, &genericv1.GenericReport_Metric{ + result = append(result, &telemetryv1.GenericReport_Metric{ Key: "ui-events-user-flow", Value: string(marshal), }) diff --git a/managed/utils/platform/client.go b/managed/utils/platform/client.go index 1926b949aa..c045ee8f3b 100644 --- a/managed/utils/platform/client.go +++ b/managed/utils/platform/client.go @@ -25,7 +25,6 @@ import ( "net/http" api "github.com/percona/saas/gen/check/retrieval" - reporter "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/grpc/codes" @@ -118,7 +117,7 @@ func (c *Client) GetTemplates(ctx context.Context) (*api.GetAllAlertRuleTemplate } // SendTelemetry sends telemetry data to Percona Platform. -func (c *Client) SendTelemetry(ctx context.Context, report *reporter.ReportRequest) error { +func (c *Client) SendTelemetry(ctx context.Context, report *telemetryv1.ReportRequest) error { const path = "/v1/telemetry/GenericReport" var accessToken string From 15d411fd10c5d3b82b5dfc14d6134602aba75988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Thu, 31 Oct 2024 10:47:19 +0100 Subject: [PATCH 13/13] PMM-13057 Fix for changes. --- managed/services/telemetry/mock_data_source_test.go | 12 ++++++------ managed/services/telemetry/mock_sender_test.go | 6 +++--- managed/services/telemetry/telemetry.go | 1 + managed/utils/platform/client.go | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/managed/services/telemetry/mock_data_source_test.go b/managed/services/telemetry/mock_data_source_test.go index 8c0b53e3a5..e6b004ebb5 100644 --- a/managed/services/telemetry/mock_data_source_test.go +++ b/managed/services/telemetry/mock_data_source_test.go @@ -5,7 +5,7 @@ package telemetry import ( context "context" - telemetryv1 "github.com/percona/saas/gen/telemetry/generic" + genericv1 "github.com/percona/saas/gen/telemetry/generic" mock "github.com/stretchr/testify/mock" ) @@ -51,23 +51,23 @@ func (_m *mockDataSource) Enabled() bool { } // FetchMetrics provides a mock function with given fields: ctx, config -func (_m *mockDataSource) FetchMetrics(ctx context.Context, config Config) ([]*telemetryv1.GenericReport_Metric, error) { +func (_m *mockDataSource) FetchMetrics(ctx context.Context, config Config) ([]*genericv1.GenericReport_Metric, error) { ret := _m.Called(ctx, config) if len(ret) == 0 { panic("no return value specified for FetchMetrics") } - var r0 []*telemetryv1.GenericReport_Metric + var r0 []*genericv1.GenericReport_Metric var r1 error - if rf, ok := ret.Get(0).(func(context.Context, Config) ([]*telemetryv1.GenericReport_Metric, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, Config) ([]*genericv1.GenericReport_Metric, error)); ok { return rf(ctx, config) } - if rf, ok := ret.Get(0).(func(context.Context, Config) []*telemetryv1.GenericReport_Metric); ok { + if rf, ok := ret.Get(0).(func(context.Context, Config) []*genericv1.GenericReport_Metric); ok { r0 = rf(ctx, config) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*telemetryv1.GenericReport_Metric) + r0 = ret.Get(0).([]*genericv1.GenericReport_Metric) } } diff --git a/managed/services/telemetry/mock_sender_test.go b/managed/services/telemetry/mock_sender_test.go index 8230bff6ed..3c943e8de4 100644 --- a/managed/services/telemetry/mock_sender_test.go +++ b/managed/services/telemetry/mock_sender_test.go @@ -5,7 +5,7 @@ package telemetry import ( context "context" - telemetryv1 "github.com/percona/saas/gen/telemetry/generic" + genericv1 "github.com/percona/saas/gen/telemetry/generic" mock "github.com/stretchr/testify/mock" ) @@ -15,7 +15,7 @@ type mockSender struct { } // SendTelemetry provides a mock function with given fields: ctx, report -func (_m *mockSender) SendTelemetry(ctx context.Context, report *telemetryv1.ReportRequest) error { +func (_m *mockSender) SendTelemetry(ctx context.Context, report *genericv1.ReportRequest) error { ret := _m.Called(ctx, report) if len(ret) == 0 { @@ -23,7 +23,7 @@ func (_m *mockSender) SendTelemetry(ctx context.Context, report *telemetryv1.Rep } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *telemetryv1.ReportRequest) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *genericv1.ReportRequest) error); ok { r0 = rf(ctx, report) } else { r0 = ret.Error(0) diff --git a/managed/services/telemetry/telemetry.go b/managed/services/telemetry/telemetry.go index 4e49bb20a3..073b821080 100644 --- a/managed/services/telemetry/telemetry.go +++ b/managed/services/telemetry/telemetry.go @@ -24,6 +24,7 @@ import ( "github.com/google/uuid" pmmv1 "github.com/percona/saas/gen/telemetry/events/pmm" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/protobuf/types/known/durationpb" diff --git a/managed/utils/platform/client.go b/managed/utils/platform/client.go index c045ee8f3b..216365019a 100644 --- a/managed/utils/platform/client.go +++ b/managed/utils/platform/client.go @@ -25,6 +25,7 @@ import ( "net/http" api "github.com/percona/saas/gen/check/retrieval" + telemetryv1 "github.com/percona/saas/gen/telemetry/generic" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/grpc/codes"