diff --git a/managed/models/template_helpers_test.go b/managed/models/template_helpers_test.go index 6393592d44a..35d6b8b7a1c 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 0b7a4fd7648..0fe0448d7eb 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" + reporter "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) ([]*reporter.GenericReport_Metric, error) { + var metrics []*reporter.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, &reporter.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 61e94e2a2c4..b31922a7d57 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" + reporter "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) ([]*reporter.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 9ac78cf0508..4091b97e80e 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" + reporter "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) ([]*reporter.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 e6517f140c8..bdbb5868181 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" + reporter "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) ([]*reporter.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 fad001937f4..c2b15ff014d 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" + reporter "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) ([]*reporter.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 []*reporter.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, &reporter.GenericReport_Metric{ Key: configItem.MetricName, Value: string(value), }) } if configItem.Value != "" { - metrics = append(metrics, &pmmv1.ServerMetric_Metric{ + metrics = append(metrics, &reporter.GenericReport_Metric{ Key: configItem.MetricName, Value: v.Value.String(), }) diff --git a/managed/services/telemetry/datasources.go b/managed/services/telemetry/datasources.go index 4cbde06362a..356f54d4a4d 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" + reporter "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) ([]*reporter.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 []*reporter.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, &reporter.GenericReport_Metric{ Key: col.MetricName, Value: value, }) diff --git a/managed/services/telemetry/deps.go b/managed/services/telemetry/deps.go index fd92d81d73b..dca26ee7b1c 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 af5e60f71b6..5b3e5bb165a 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" + reporter "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) ([]*reporter.GenericReport_Metric, error) } diff --git a/managed/services/telemetry/mock_data_source_test.go b/managed/services/telemetry/mock_data_source_test.go index 35925c66b5f..e6b004ebb52 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 a813e0a27d2..3c943e8de4f 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 53393d29f03..e9842a1efe1 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" - 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/protobuf/types/known/durationpb" @@ -53,7 +53,7 @@ type Service struct { os string sDistributionMethod serverv1.DistributionMethod tDistributionMethod pmmv1.DistributionMethod - sendCh chan *pmmv1.ServerMetric + 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 *pmmv1.ServerMetric, 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 []*pmmv1.ServerMetric + var reportsBuf []*reporter.GenericReport var sendCtx context.Context //nolint:contextcheck var cancel context.CancelFunc @@ -182,14 +182,19 @@ func (s *Service) processSendCh(ctx context.Context) { sendCtx, cancel = context.WithTimeout(ctx, s.config.Reporting.SendTimeout) reportsBufSync.Lock() - reportsBuf = append(reportsBuf, report) + reportsBuf = append(reportsBuf, &reporter.GenericReport{ + Id: string(report.GetId()), + CreateTime: report.GetCreateTime(), + InstanceId: string(report.GetInstanceId()), + ProductFamily: reporter.ProductFamily_PRODUCT_FAMILY_PMM, + Metrics: report.Metrics, + }) reportsToSend := reportsBuf - reportsBuf = []*pmmv1.ServerMetric{} reportsBufSync.Unlock() go func(ctx context.Context) { err := s.send(ctx, &reporter.ReportRequest{ - Metrics: reportsToSend, + Reports: []*reporter.GenericReport{}, }) if err != nil { s.l.Debugf("Telemetry info not sent, due to error: %s.", err) @@ -211,7 +216,7 @@ func (s *Service) processSendCh(ctx context.Context) { } } -func (s *Service) prepareReport(ctx context.Context) *pmmv1.ServerMetric { +func (s *Service) prepareReport(ctx context.Context) *reporter.GenericReport { initializedDataSources := make(map[DataSourceName]DataSource) telemetryMetric, _ := s.makeMetric(ctx) var totalTime time.Duration @@ -324,7 +329,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) (*reporter.GenericReport, error) { var settings *models.Settings useServerID := false err := s.db.InTransaction(func(tx *reform.TX) error { @@ -362,13 +367,15 @@ func (s *Service) makeMetric(ctx context.Context) (*pmmv1.ServerMetric, error) { _, distMethod, _ := s.dus.GetDistributionMethodAndOS() 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 &reporter.GenericReport{ + Id: string(eventID[:]), + CreateTime: timestamppb.New(time.Now()), + InstanceId: string(serverID), + Metrics: []*reporter.GenericReport_Metric{ + {Key: "PMMServerVersion", Value: s.pmmVersion}, + {Key: "UpDuration", Value: durationpb.New(time.Since(s.start)).String()}, + {Key: "DistributionMethod", Value: distMethod.String()}, + }, }, nil } @@ -412,7 +419,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 *reporter.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 ae11cfdbe1a..098e51e36b5 100644 --- a/managed/services/telemetry/telemetry_test.go +++ b/managed/services/telemetry/telemetry_test.go @@ -24,7 +24,8 @@ import ( _ "github.com/ClickHouse/clickhouse-go/v2" 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" + reporter "github.com/percona/saas/gen/telemetry/generic" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -82,7 +83,11 @@ func TestRunTelemetryService(t *testing.T) { logger.SetLevel(logrus.DebugLevel) logEntry := logrus.NewEntry(logger) - expectedServerMetrics := []*pmmv1.ServerMetric_Metric{ + expectedServerMetrics := []*reporter.GenericReport_Metric{ + { + Key: "DistributionMethod", + Value: "pmmv1.DistributionMethod_AMI", + }, { Key: "key", Value: "value", @@ -97,10 +102,9 @@ func TestRunTelemetryService(t *testing.T) { }, } expectedReport := &reporter.ReportRequest{ - Metrics: []*pmmv1.ServerMetric{ + Reports: []*reporter.GenericReport{ { - DistributionMethod: pmmv1.DistributionMethod_AMI, - Metrics: expectedServerMetrics, + Metrics: expectedServerMetrics, }, }, } @@ -176,7 +180,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) }) @@ -295,9 +299,18 @@ func initMockTelemetrySender(t *testing.T, expectedReport *reporter.ReportReques } } +func valueIsInArray(items []*genericv1.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.Metrics) == 1 && - expectedReport.Metrics[0].DistributionMethod.String() == "AMI" + return len(report.Reports) == 1 && valueIsInArray(expectedReport.Reports[0].Metrics, "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 794917b9724..6543354223e 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 e196605da20..b7ddd669166 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" + reporter "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 []*reporter.GenericReport_Metric } - noMetrics := []*pmmv1.ServerMetric_Metric{} + noMetrics := []*reporter.GenericReport_Metric{} tests := []struct { name string args args - want []*pmmv1.ServerMetric_Metric + want []*reporter.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: []*reporter.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: []*reporter.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: []*reporter.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: []*reporter.GenericReport_Metric{ {Key: configJSON().Data[0].MetricName, Value: "v1"}, {Key: configJSON().Data[0].MetricName, Value: "v2"}, }, }, - want: []*pmmv1.ServerMetric_Metric{ + want: []*reporter.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: []*reporter.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: []*reporter.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 []*reporter.GenericReport_Metric } - noMetrics := []*pmmv1.ServerMetric_Metric{} + noMetrics := []*reporter.GenericReport_Metric{} tests := []struct { name string args args - want []*pmmv1.ServerMetric_Metric + want []*reporter.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: []*reporter.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: []*reporter.GenericReport_Metric{ {Key: "metric-a", Value: "v1"}, {Key: "metric-b", Value: "v2"}, }, }, - want: []*pmmv1.ServerMetric_Metric{ + want: []*reporter.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 []*reporter.GenericReport_Metric } tests := []struct { name string args args - want []*pmmv1.ServerMetric_Metric + want []*reporter.GenericReport_Metric }{ { name: "should remove metrics with empty values", - args: args{metrics: []*pmmv1.ServerMetric_Metric{ + args: args{metrics: []*reporter.GenericReport_Metric{ { Key: "empty_value", Value: "", @@ -323,7 +323,7 @@ func TestRemoveEmpty(t *testing.T) { Value: "", }, }}, - want: []*pmmv1.ServerMetric_Metric{ + want: []*reporter.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: []*reporter.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: []*reporter.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: []*reporter.GenericReport_Metric{}, }, } diff --git a/managed/services/telemetry/uievents/uievents.go b/managed/services/telemetry/uievents/uievents.go index 1bee25ca8a7..c73bb710e61 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" + reporter "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) ([]*reporter.GenericReport_Metric, error) { //nolint:unparam s.stateM.RLock() defer s.stateM.RUnlock() - var result []*pmmv1.ServerMetric_Metric + var result []*reporter.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() *reporter.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 &reporter.GenericReport_Metric{ Key: "ui-events-dashboards", Value: string(serializedDashboardStat), } } -func (s *Service) processComponentMetrics() *pmmv1.ServerMetric_Metric { +func (s *Service) processComponentMetrics() *reporter.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 &reporter.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() []*reporter.GenericReport_Metric { + result := make([]*reporter.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, &reporter.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 dca019327a4..305d5ba0adf 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"