From 41db807ee41daee1c65535884cd8287060897b73 Mon Sep 17 00:00:00 2001 From: Nurlan Moldomurov Date: Sat, 20 Apr 2024 11:40:31 +0300 Subject: [PATCH] PMM-7 Fix imports protobuf (#2964) --- go.mod | 2 +- managed/services/agents/channel/channel.go | 7 +- managed/services/agents/state.go | 4 +- managed/services/management/rds_test.go | 6 +- qan-api2/services/analytics/filters_test.go | 27 ++- .../services/analytics/object_details_test.go | 113 ++++++----- qan-api2/services/analytics/profile_test.go | 178 +++++++++--------- 7 files changed, 167 insertions(+), 170 deletions(-) diff --git a/go.mod b/go.mod index be04ff72d2..39fdee8865 100644 --- a/go.mod +++ b/go.mod @@ -41,7 +41,6 @@ require ( github.com/go-openapi/validate v0.24.0 github.com/go-sql-driver/mysql v1.7.1 github.com/golang-migrate/migrate/v4 v4.17.0 - github.com/golang/protobuf v1.5.4 github.com/google/uuid v1.6.0 github.com/grafana/grafana-api-golang-client v0.27.0 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 @@ -116,6 +115,7 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/golang-jwt/jwt/v5 v5.2.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 // indirect diff --git a/managed/services/agents/channel/channel.go b/managed/services/agents/channel/channel.go index 448010495e..12de14e636 100644 --- a/managed/services/agents/channel/channel.go +++ b/managed/services/agents/channel/channel.go @@ -21,12 +21,13 @@ import ( "sync" "sync/atomic" - "github.com/golang/protobuf/proto" //nolint:staticcheck "github.com/pkg/errors" "github.com/sirupsen/logrus" protostatus "google.golang.org/genproto/googleapis/rpc/status" "google.golang.org/grpc/codes" grpcstatus "google.golang.org/grpc/status" + "google.golang.org/protobuf/encoding/prototext" + "google.golang.org/protobuf/proto" "github.com/percona/pmm/api/agentpb" "github.com/percona/pmm/utils/logger" @@ -194,7 +195,7 @@ func (c *Channel) send(msg *agentpb.ServerMessage) { if size := proto.Size(msg); size < 100 { c.l.Debugf("Sending message (%d bytes): %s.", size, msg) } else { - c.l.Debugf("Sending message (%d bytes):\n%s\n", size, proto.MarshalTextString(msg)) + c.l.Debugf("Sending message (%d bytes):\n%s\n", size, prototext.Format(msg)) } } @@ -229,7 +230,7 @@ func (c *Channel) runReceiver() { if size := proto.Size(msg); size < 100 { c.l.Debugf("Received message (%d bytes): %s.", size, msg) } else { - c.l.Debugf("Received message (%d bytes):\n%s\n", size, proto.MarshalTextString(msg)) + c.l.Debugf("Received message (%d bytes):\n%s\n", size, prototext.Format(msg)) } } diff --git a/managed/services/agents/state.go b/managed/services/agents/state.go index d7ad55ea4c..ed0c4e0ecd 100644 --- a/managed/services/agents/state.go +++ b/managed/services/agents/state.go @@ -21,9 +21,9 @@ import ( "time" "github.com/AlekSi/pointer" - "github.com/golang/protobuf/proto" //nolint:staticcheck "github.com/pkg/errors" "github.com/sirupsen/logrus" + "google.golang.org/protobuf/encoding/prototext" "gopkg.in/reform.v1" "github.com/percona/pmm/api/agentpb" @@ -274,7 +274,7 @@ func (u *StateUpdater) sendSetStateRequest(ctx context.Context, agent *pmmAgentI AgentProcesses: agentProcesses, BuiltinAgents: builtinAgents, } - l.Debugf("sendSetStateRequest:\n%s", proto.MarshalTextString(state)) + l.Debugf("sendSetStateRequest:\n%s", prototext.Format(state)) resp, err := agent.channel.SendAndWaitResponse(state) if err != nil { diff --git a/managed/services/management/rds_test.go b/managed/services/management/rds_test.go index c339ffa17a..c103825de1 100644 --- a/managed/services/management/rds_test.go +++ b/managed/services/management/rds_test.go @@ -26,12 +26,12 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" - "github.com/golang/protobuf/proto" //nolint:staticcheck "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/encoding/prototext" "gopkg.in/reform.v1" "gopkg.in/reform.v1/dialects/postgresql" @@ -318,7 +318,7 @@ func TestRDSService(t *testing.T) { Status: inventorypb.AgentStatus_UNKNOWN, }, } - assert.Equal(t, proto.MarshalTextString(expected), proto.MarshalTextString(resp)) // for better diffs + assert.Equal(t, prototext.Format(expected), prototext.Format(resp)) // for better diffs }) t.Run("AddRDSPostgreSQL", func(t *testing.T) { @@ -408,6 +408,6 @@ func TestRDSService(t *testing.T) { Status: inventorypb.AgentStatus_UNKNOWN, }, } - assert.Equal(t, proto.MarshalTextString(expected), proto.MarshalTextString(resp)) // for better diffs + assert.Equal(t, prototext.Format(expected), prototext.Format(resp)) // for better diffs }) } diff --git a/qan-api2/services/analytics/filters_test.go b/qan-api2/services/analytics/filters_test.go index 31b4fb81f4..a627add915 100644 --- a/qan-api2/services/analytics/filters_test.go +++ b/qan-api2/services/analytics/filters_test.go @@ -24,10 +24,9 @@ import ( "time" _ "github.com/ClickHouse/clickhouse-go/151" // register database/sql driver - // TODO replace with 'google.golang.org/protobuf/encoding/protojson' since this one is deprecated. - "github.com/golang/protobuf/ptypes/timestamp" "github.com/jmoiron/sqlx" "github.com/stretchr/testify/assert" + "google.golang.org/protobuf/types/known/timestamppb" qanpb "github.com/percona/pmm/api/qanpb" "github.com/percona/pmm/qan-api2/models" @@ -82,8 +81,8 @@ func TestService_GetFilters(t *testing.T) { "success", fields{rm: rm, mm: mm}, &qanpb.FiltersRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, }, &want, false, @@ -92,8 +91,8 @@ func TestService_GetFilters(t *testing.T) { "success_with_dimensions_username", fields{rm: rm, mm: mm}, &qanpb.FiltersRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, Labels: []*qanpb.MapFieldEntry{ {Key: "username", Value: []string{"user1", "user2"}}, }, @@ -105,8 +104,8 @@ func TestService_GetFilters(t *testing.T) { "success_with_dimensions_client_host_schema_service_name", fields{rm: rm, mm: mm}, &qanpb.FiltersRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, Labels: []*qanpb.MapFieldEntry{ {Key: "client_host", Value: []string{"10.11.12.1", "10.11.12.2", "10.11.12.3", "10.11.12.4", "10.11.12.5", "10.11.12.6", "10.11.12.7", "10.11.12.8", "10.11.12.9", "10.11.12.10", "10.11.12.11", "10.11.12.12", "10.11.12.13"}}, {Key: "schema", Value: []string{"schema65", "schema6", "schema42", "schema76", "schema90", "schema39", "schema1", "schema17", "schema79", "schema10"}}, @@ -120,8 +119,8 @@ func TestService_GetFilters(t *testing.T) { "success_with_dimensions_multiple", fields{rm: rm, mm: mm}, &qanpb.FiltersRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, Labels: []*qanpb.MapFieldEntry{ {Key: "container_id", Value: []string{"container_id"}}, {Key: "container_name", Value: []string{"container_name1"}}, @@ -148,8 +147,8 @@ func TestService_GetFilters(t *testing.T) { "success_with_labels", fields{rm: rm, mm: mm}, &qanpb.FiltersRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, Labels: []*qanpb.MapFieldEntry{ {Key: "label0", Value: []string{"value1"}}, }, @@ -161,8 +160,8 @@ func TestService_GetFilters(t *testing.T) { "fail", fields{rm: rm, mm: mm}, &qanpb.FiltersRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t2.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t1.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t2.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t1.Unix()}, }, nil, true, diff --git a/qan-api2/services/analytics/object_details_test.go b/qan-api2/services/analytics/object_details_test.go index 05793dd581..27b93ee4c6 100644 --- a/qan-api2/services/analytics/object_details_test.go +++ b/qan-api2/services/analytics/object_details_test.go @@ -21,11 +21,10 @@ import ( "testing" "time" - // TODO replace with 'google.golang.org/protobuf/encoding/protojson' since this one is deprecated. - "github.com/golang/protobuf/jsonpb" //nolint:staticcheck - "github.com/golang/protobuf/ptypes/timestamp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/types/known/timestamppb" qanpb "github.com/percona/pmm/api/qanpb" "github.com/percona/pmm/qan-api2/models" @@ -53,7 +52,7 @@ func TestService_GetQueryExample(t *testing.T) { "no_period_start_from", fields{rm: rm, mm: mm}, &qanpb.QueryExampleRequest{ - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", FilterBy: "B305F6354FA21F2A", Limit: 5, @@ -65,7 +64,7 @@ func TestService_GetQueryExample(t *testing.T) { "no_period_start_to", fields{rm: rm, mm: mm}, &qanpb.QueryExampleRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, GroupBy: "queryid", FilterBy: "B305F6354FA21F2A", Limit: 5, @@ -77,8 +76,8 @@ func TestService_GetQueryExample(t *testing.T) { "no_group", fields{rm: rm, mm: mm}, &qanpb.QueryExampleRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, FilterBy: "B305F6354FA21F2A", Limit: 5, }, @@ -89,8 +88,8 @@ func TestService_GetQueryExample(t *testing.T) { "no_limit", fields{rm: rm, mm: mm}, &qanpb.QueryExampleRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", FilterBy: "B305F6354FA21F2A", }, @@ -101,8 +100,8 @@ func TestService_GetQueryExample(t *testing.T) { "invalid_group_name", fields{rm: rm, mm: mm}, &qanpb.QueryExampleRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "invalid_group_name", FilterBy: "B305F6354FA21F2A", }, @@ -113,8 +112,8 @@ func TestService_GetQueryExample(t *testing.T) { "not_found", fields{rm: rm, mm: mm}, &qanpb.QueryExampleRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", FilterBy: "unexist", }, @@ -138,12 +137,12 @@ func TestService_GetQueryExample(t *testing.T) { } expectedJSON := getExpectedJSON(t, got, "../../test_data/GetQueryExample_"+tt.name+".json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := protojson.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + require.JSONEq(t, string(expectedJSON), string(gotJSON)) }) } } @@ -170,8 +169,8 @@ func TestService_GetMetricsError(t *testing.T) { "not_found", fields{rm: rm, mm: mm}, &qanpb.MetricsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", FilterBy: "unexist", }, @@ -182,7 +181,7 @@ func TestService_GetMetricsError(t *testing.T) { "no_period_start_from", fields{rm: rm, mm: mm}, &qanpb.MetricsRequest{ - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", FilterBy: "B305F6354FA21F2A", }, @@ -193,7 +192,7 @@ func TestService_GetMetricsError(t *testing.T) { "no_period_start_to", fields{rm: rm, mm: mm}, &qanpb.MetricsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, GroupBy: "queryid", FilterBy: "B305F6354FA21F2A", }, @@ -204,8 +203,8 @@ func TestService_GetMetricsError(t *testing.T) { "invalid_group_name", fields{rm: rm, mm: mm}, &qanpb.MetricsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "no_group_name", FilterBy: "B305F6354FA21F2A", }, @@ -216,8 +215,8 @@ func TestService_GetMetricsError(t *testing.T) { "not_found_labels", fields{rm: rm, mm: mm}, &qanpb.MetricsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "no_group_name", FilterBy: "B305F6354FA21F2A", Labels: []*qanpb.MapFieldEntry{ @@ -283,8 +282,8 @@ func TestService_GetMetrics(t *testing.T) { mm: mm, } in := &qanpb.MetricsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", FilterBy: "B305F6354FA21F2A", } @@ -292,12 +291,12 @@ func TestService_GetMetrics(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetMetrics()") expectedJSON := getExpectedJSON(t, got, "../../test_data/GetMetrics_group_by_queryid.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := protojson.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - require.JSONEq(t, string(expectedJSON), gotJSON) + require.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t3, _ := time.Parse(time.RFC3339, "2019-01-01T01:30:00Z") @@ -307,8 +306,8 @@ func TestService_GetMetrics(t *testing.T) { mm: mm, } in := &qanpb.MetricsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t3.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t3.Unix()}, GroupBy: "queryid", FilterBy: "B305F6354FA21F2A", } @@ -316,12 +315,12 @@ func TestService_GetMetrics(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetMetrics()") expectedJSON := getExpectedJSON(t, got, "../../test_data/GetMetrics_sparklines_90_points.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := protojson.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - require.JSONEq(t, string(expectedJSON), gotJSON) + require.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t.Run("total", func(t *testing.T) { @@ -330,8 +329,8 @@ func TestService_GetMetrics(t *testing.T) { mm: mm, } in := &qanpb.MetricsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", FilterBy: "", // Empty filter get all queries. Totals: true, @@ -340,12 +339,12 @@ func TestService_GetMetrics(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetMetrics()") expectedJSON := getExpectedJSON(t, got, "../../test_data/GetMetrics_total.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := protojson.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) } @@ -373,8 +372,8 @@ func TestService_GetLabels(t *testing.T) { "success", fields{rm: rm, mm: mm}, &qanpb.ObjectDetailsLabelsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", FilterBy: "1D410B4BE5060972", }, @@ -391,12 +390,12 @@ func TestService_GetLabels(t *testing.T) { require.Equal(t, tt.wantErr, err) expectedJSON := getExpectedJSON(t, got, "../../test_data/GetLabels"+tt.name+".json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := protojson.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) tt = testCase{ @@ -404,7 +403,7 @@ func TestService_GetLabels(t *testing.T) { fields{rm: rm, mm: mm}, &qanpb.ObjectDetailsLabelsRequest{ PeriodStartFrom: nil, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", FilterBy: "1D410B4BE5060972", }, @@ -425,7 +424,7 @@ func TestService_GetLabels(t *testing.T) { "required to", fields{rm: rm, mm: mm}, &qanpb.ObjectDetailsLabelsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, PeriodStartTo: nil, GroupBy: "queryid", FilterBy: "1D410B4BE5060972", @@ -444,8 +443,8 @@ func TestService_GetLabels(t *testing.T) { }) request := &qanpb.ObjectDetailsLabelsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "", FilterBy: "1D410B4BE5060972", } @@ -467,8 +466,8 @@ func TestService_GetLabels(t *testing.T) { }) request = &qanpb.ObjectDetailsLabelsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", FilterBy: "", } @@ -489,17 +488,17 @@ func TestService_GetLabels(t *testing.T) { require.Equal(t, tt.wantErr, err) expectedJSON := getExpectedJSON(t, got, "../../test_data/GetLabels_"+tt.name+".json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := protojson.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) request = &qanpb.ObjectDetailsLabelsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t2.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t1.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t2.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t1.Unix()}, GroupBy: "queryid", FilterBy: "1D410B4BE5060972", } @@ -521,8 +520,8 @@ func TestService_GetLabels(t *testing.T) { }) request = &qanpb.ObjectDetailsLabelsRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "invalid group", FilterBy: "1D410B4BE5060972", } diff --git a/qan-api2/services/analytics/profile_test.go b/qan-api2/services/analytics/profile_test.go index 95e22f1f81..4d4d466516 100644 --- a/qan-api2/services/analytics/profile_test.go +++ b/qan-api2/services/analytics/profile_test.go @@ -23,13 +23,11 @@ import ( "testing" "time" - // TODO replace with 'google.golang.org/protobuf/encoding/protojson' since this one is deprecated. - "github.com/golang/protobuf/jsonpb" //nolint:staticcheck - // TODO replace with 'google.golang.org/protobuf/proto' since this one is deprecated. - "github.com/golang/protobuf/proto" //nolint:staticcheck - "github.com/golang/protobuf/ptypes/timestamp" "github.com/jmoiron/sqlx" "github.com/stretchr/testify/assert" + jsonpb "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/timestamppb" qanpb "github.com/percona/pmm/api/qanpb" "github.com/percona/pmm/qan-api2/models" @@ -51,14 +49,14 @@ func setup() *sqlx.DB { func getExpectedJSON(t *testing.T, got proto.Message, filename string) []byte { t.Helper() if os.Getenv("REFRESH_TEST_DATA") != "" { - marshaler := jsonpb.Marshaler{ + marshaler := jsonpb.MarshalOptions{ Indent: "\t", } - json, err := marshaler.MarshalToString(got) + json, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - err = os.WriteFile(filename, []byte(json), 0o644) //nolint:gosec + err = os.WriteFile(filename, json, 0o644) //nolint:gosec if err != nil { t.Errorf("cannot write:%v", err) } @@ -92,8 +90,8 @@ func TestService_GetReport(t *testing.T) { "success", fields{rm: rm, mm: mm}, &qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", Columns: []string{"query_time", "lock_time", "sort_scan"}, OrderBy: "query_time", @@ -107,8 +105,8 @@ func TestService_GetReport(t *testing.T) { "load without query_time", fields{rm: rm, mm: mm}, &qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", Columns: []string{"load", "lock_time", "sort_scan"}, OrderBy: "-load", @@ -122,8 +120,8 @@ func TestService_GetReport(t *testing.T) { "wrong_time_range", fields{rm: rm, mm: mm}, &qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t2.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t1.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t2.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t1.Unix()}, }, nil, true, @@ -153,12 +151,12 @@ func TestService_GetReport(t *testing.T) { return } expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_"+tt.name+".json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) } } @@ -182,8 +180,8 @@ func TestService_GetReport_Mix(t *testing.T) { }{ fields{rm: rm, mm: mm}, &qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", Columns: []string{"query_time", "lock_time", "sort_scan"}, OrderBy: "-query_time", @@ -215,12 +213,12 @@ func TestService_GetReport_Mix(t *testing.T) { return } expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Mix_reverce_order.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t.Run("correct_load", func(t *testing.T) { @@ -234,12 +232,12 @@ func TestService_GetReport_Mix(t *testing.T) { return } expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Mix_correct_load.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), string(gotJSON)) //nolint:unconvert //keeps converting automatically + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t.Run("correct_latency", func(t *testing.T) { @@ -254,12 +252,12 @@ func TestService_GetReport_Mix(t *testing.T) { return } expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Mix_correct_latency.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), string(gotJSON)) //nolint:unconvert //keeps converting automatically + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t.Run("no error on limit is 0", func(t *testing.T) { @@ -306,8 +304,8 @@ func TestService_GetReport_Groups(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", Columns: []string{ "query_time", "lock_time", "sort_scan", "rows_sent", "rows_examined", "rows_affected", @@ -329,12 +327,12 @@ func TestService_GetReport_Groups(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Groups_group_by_queryid.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t.Run("group_by_service_name", func(t *testing.T) { @@ -344,8 +342,8 @@ func TestService_GetReport_Groups(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "service_name", Columns: []string{ "query_time", "lock_time", "sort_scan", "rows_sent", "rows_examined", "rows_affected", @@ -367,12 +365,12 @@ func TestService_GetReport_Groups(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Groups_group_by_service_name.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t.Run("group_by_database", func(t *testing.T) { @@ -382,8 +380,8 @@ func TestService_GetReport_Groups(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "database", Columns: []string{ "query_time", "lock_time", "sort_scan", "rows_sent", "rows_examined", "rows_affected", @@ -405,12 +403,12 @@ func TestService_GetReport_Groups(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Groups_group_by_database.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t.Run("group_by_schema", func(t *testing.T) { @@ -420,8 +418,8 @@ func TestService_GetReport_Groups(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "schema", Columns: []string{ "query_time", "lock_time", "sort_scan", "rows_sent", "rows_examined", "rows_affected", @@ -443,12 +441,12 @@ func TestService_GetReport_Groups(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Groups_group_by_schema.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t.Run("group_by_username", func(t *testing.T) { @@ -458,8 +456,8 @@ func TestService_GetReport_Groups(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "username", Columns: []string{ "query_time", "lock_time", "sort_scan", "rows_sent", "rows_examined", "rows_affected", @@ -481,12 +479,12 @@ func TestService_GetReport_Groups(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Groups_group_by_username.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t.Run("group_by_client_host", func(t *testing.T) { @@ -496,8 +494,8 @@ func TestService_GetReport_Groups(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "client_host", Columns: []string{ "query_time", "lock_time", "sort_scan", "rows_sent", "rows_examined", "rows_affected", @@ -519,12 +517,12 @@ func TestService_GetReport_Groups(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Groups_group_by_client_host.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), string(gotJSON)) //nolint:unconvert //keeps converting automatically + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) } @@ -555,8 +553,8 @@ func TestService_GetReport_AllLabels(t *testing.T) { "", fields{rm: rm, mm: mm}, &qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", Columns: []string{"query_time", "lock_time", "sort_scan"}, OrderBy: "-query_time", @@ -656,8 +654,8 @@ func TestService_GetReport_Sparklines(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", Columns: []string{ "query_time", "lock_time", "sort_scan", "rows_sent", "rows_examined", "rows_affected", @@ -679,12 +677,12 @@ func TestService_GetReport_Sparklines(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_sparklines_60_points.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), string(gotJSON)) //nolint:unconvert //keeps converting automatically + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t3, _ := time.Parse(time.RFC3339, "2019-01-01T01:30:00Z") @@ -695,8 +693,8 @@ func TestService_GetReport_Sparklines(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t3.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t3.Unix()}, GroupBy: "queryid", Columns: []string{ "query_time", "lock_time", "sort_scan", "rows_sent", "rows_examined", "rows_affected", @@ -718,12 +716,12 @@ func TestService_GetReport_Sparklines(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_sparklines_90_points.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) } @@ -741,8 +739,8 @@ func TestService_GetReport_Search(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", Columns: []string{ "query_time", @@ -757,12 +755,12 @@ func TestService_GetReport_Search(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Search_search_queryid.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t.Run("search_fingerprint", func(t *testing.T) { @@ -772,8 +770,8 @@ func TestService_GetReport_Search(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", Columns: []string{ "query_time", @@ -788,12 +786,12 @@ func TestService_GetReport_Search(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Search_search_fingerprint.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) t.Run("search_service_name", func(t *testing.T) { @@ -803,8 +801,8 @@ func TestService_GetReport_Search(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "service_name", Columns: []string{ "query_time", @@ -819,12 +817,12 @@ func TestService_GetReport_Search(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestService_GetReport_Search_search_service_name.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), gotJSON) + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) } @@ -842,8 +840,8 @@ func TestServiceGetReportSpecialMetrics(t *testing.T) { } in := qanpb.ReportRequest{ - PeriodStartFrom: ×tamp.Timestamp{Seconds: t1.Unix()}, - PeriodStartTo: ×tamp.Timestamp{Seconds: t2.Unix()}, + PeriodStartFrom: ×tamppb.Timestamp{Seconds: t1.Unix()}, + PeriodStartTo: ×tamppb.Timestamp{Seconds: t2.Unix()}, GroupBy: "queryid", Columns: []string{ "num_queries_with_errors", "num_queries_with_warnings", "num_queries", "load", @@ -857,11 +855,11 @@ func TestServiceGetReportSpecialMetrics(t *testing.T) { assert.NoError(t, err, "Unexpected error in Service.GetReport()") expectedJSON := getExpectedJSON(t, got, "../../test_data/TestServiceGetReportSpecialMetrics_num_queries_with_errors.json") - marshaler := jsonpb.Marshaler{Indent: "\t"} - gotJSON, err := marshaler.MarshalToString(got) + marshaler := jsonpb.MarshalOptions{Indent: "\t"} + gotJSON, err := marshaler.Marshal(got) if err != nil { t.Errorf("cannot marshal:%v", err) } - assert.JSONEq(t, string(expectedJSON), string(gotJSON)) //nolint:unconvert //keeps converting automatically + assert.JSONEq(t, string(expectedJSON), string(gotJSON)) }) }