diff --git a/packages/grafana-data/src/types/featureToggles.gen.ts b/packages/grafana-data/src/types/featureToggles.gen.ts index be9f94d3b37..c4334575773 100644 --- a/packages/grafana-data/src/types/featureToggles.gen.ts +++ b/packages/grafana-data/src/types/featureToggles.gen.ts @@ -53,7 +53,6 @@ export interface FeatureToggles { datasourceQueryMultiStatus?: boolean; traceToMetrics?: boolean; prometheusStreamingJSONParser?: boolean; - prometheusStreamingJSONParserTest?: boolean; newDBLibrary?: boolean; validateDashboardsOnSave?: boolean; autoMigrateGraphPanels?: boolean; diff --git a/pkg/services/featuremgmt/registry.go b/pkg/services/featuremgmt/registry.go index 814089f0bbf..1ba42512802 100644 --- a/pkg/services/featuremgmt/registry.go +++ b/pkg/services/featuremgmt/registry.go @@ -212,11 +212,6 @@ var ( Description: "Enable streaming JSON parser for Prometheus datasource", State: FeatureStateBeta, }, - { - Name: "prometheusStreamingJSONParserTest", - Description: "Run both old and streaming requests and log differences", - State: FeatureStateBeta, - }, { Name: "newDBLibrary", Description: "Use jmoiron/sqlx rather than xorm for a few backend services", diff --git a/pkg/services/featuremgmt/toggles_gen.go b/pkg/services/featuremgmt/toggles_gen.go index 3ea262fdcf2..432aac5a880 100644 --- a/pkg/services/featuremgmt/toggles_gen.go +++ b/pkg/services/featuremgmt/toggles_gen.go @@ -155,10 +155,6 @@ const ( // Enable streaming JSON parser for Prometheus datasource FlagPrometheusStreamingJSONParser = "prometheusStreamingJSONParser" - // FlagPrometheusStreamingJSONParserTest - // Run both old and streaming requests and log differences - FlagPrometheusStreamingJSONParserTest = "prometheusStreamingJSONParserTest" - // FlagNewDBLibrary // Use jmoiron/sqlx rather than xorm for a few backend services FlagNewDBLibrary = "newDBLibrary" diff --git a/pkg/tsdb/prometheus/prometheus.go b/pkg/tsdb/prometheus/prometheus.go index 43b12d31ddb..4f9d592dcae 100644 --- a/pkg/tsdb/prometheus/prometheus.go +++ b/pkg/tsdb/prometheus/prometheus.go @@ -2,31 +2,25 @@ package prometheus import ( "context" - "encoding/json" "errors" "fmt" - "reflect" "strings" - "sync" "time" "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/datasource" "github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt" - "github.com/grafana/grafana/pkg/tsdb/prometheus/client" - "github.com/patrickmn/go-cache" - apiv1 "github.com/prometheus/client_golang/api/prometheus/v1" - "github.com/yudai/gojsondiff" - "github.com/yudai/gojsondiff/formatter" - "github.com/grafana/grafana/pkg/infra/httpclient" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb/prometheus/buffered" + "github.com/grafana/grafana/pkg/tsdb/prometheus/client" "github.com/grafana/grafana/pkg/tsdb/prometheus/querydata" "github.com/grafana/grafana/pkg/tsdb/prometheus/resource" + "github.com/patrickmn/go-cache" + apiv1 "github.com/prometheus/client_golang/api/prometheus/v1" ) var plog = log.New("tsdb.prometheus") @@ -103,36 +97,6 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest) return i.queryData.Execute(ctx, req) } - // To test the new client implementation this can be run and we do 2 requests and compare. - if s.features.IsEnabled(featuremgmt.FlagPrometheusStreamingJSONParserTest) { - var wg sync.WaitGroup - var streamData *backend.QueryDataResponse - var streamError error - - var data *backend.QueryDataResponse - var err error - - plog.FromContext(ctx).Debug("PrometheusStreamingJSONParserTest", "req", req) - - wg.Add(1) - go func() { - defer wg.Done() - streamData, streamError = i.queryData.Execute(ctx, req) - }() - - wg.Add(1) - go func() { - defer wg.Done() - data, err = i.buffered.ExecuteTimeSeriesQuery(ctx, req) - }() - - wg.Wait() - - // Report can take a while and we don't really need to wait for it. - go reportDiff(data, err, streamData, streamError) - return data, err - } - return i.buffered.ExecuteTimeSeriesQuery(ctx, req) } @@ -187,48 +151,3 @@ func ConvertAPIError(err error) error { } return err } - -func reportDiff(data *backend.QueryDataResponse, err error, streamData *backend.QueryDataResponse, streamError error) { - if err == nil && streamError != nil { - plog.Debug("PrometheusStreamingJSONParserTest error in streaming client", "err", streamError) - } - - if err != nil && streamError == nil { - plog.Debug("PrometheusStreamingJSONParserTest error in buffer but not streaming", "err", err) - } - - if !reflect.DeepEqual(data, streamData) { - plog.Debug("PrometheusStreamingJSONParserTest buffer and streaming data are different") - dataJson, jsonErr := json.MarshalIndent(data, "", "\t") - if jsonErr != nil { - plog.Debug("PrometheusStreamingJSONParserTest error marshaling data", "jsonErr", jsonErr) - } - streamingJson, jsonErr := json.MarshalIndent(streamData, "", "\t") - if jsonErr != nil { - plog.Debug("PrometheusStreamingJSONParserTest error marshaling streaming data", "jsonErr", jsonErr) - } - differ := gojsondiff.New() - d, diffErr := differ.Compare(dataJson, streamingJson) - if diffErr != nil { - plog.Debug("PrometheusStreamingJSONParserTest diff error", "err", diffErr) - } - config := formatter.AsciiFormatterConfig{ - ShowArrayIndex: true, - Coloring: true, - } - - var aJson map[string]interface{} - unmarshallErr := json.Unmarshal(dataJson, &aJson) - if unmarshallErr != nil { - plog.Debug("PrometheusStreamingJSONParserTest unmarshall error", "err", unmarshallErr) - } - formatter := formatter.NewAsciiFormatter(aJson, config) - diffString, diffErr := formatter.Format(d) - if diffErr != nil { - plog.Debug("PrometheusStreamingJSONParserTest diff format error", "err", diffErr) - } - fmt.Println(diffString) - } else { - plog.Debug("PrometheusStreamingJSONParserTest responses are the same") - } -}