From 6e441f0b76a226b393cc5e86b599f98f791197c3 Mon Sep 17 00:00:00 2001 From: Barthelemy Antonin Date: Tue, 31 Oct 2023 17:29:01 +0100 Subject: [PATCH] Make ArchiveTrace button auto-configurable - Resolves #4874 The button to archive a trace is now configured based on the state of the QueryService in addition to the UI configuration. It is now possible to request features from the QueryService to inject them into the UI. All corresponding tests have been updated. - [X] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [X] I have signed all commits - [X] I have added unit tests for the new functionality - [X] I have run lint and test steps successfully --------- Signed-off-by: Barthelemy Antonin --- cmd/query/app/fixture/index.html | 10 +- cmd/query/app/querysvc/query_service.go | 19 +++ cmd/query/app/querysvc/query_service_test.go | 18 +++ cmd/query/app/server.go | 2 +- cmd/query/app/static_handler.go | 158 ++++++++++--------- cmd/query/app/static_handler_test.go | 71 ++++++--- 6 files changed, 172 insertions(+), 106 deletions(-) diff --git a/cmd/query/app/fixture/index.html b/cmd/query/app/fixture/index.html index 0bce65817e0..322c925ede2 100644 --- a/cmd/query/app/fixture/index.html +++ b/cmd/query/app/fixture/index.html @@ -1,12 +1,14 @@ - - - Test Page - + diff --git a/cmd/query/app/querysvc/query_service.go b/cmd/query/app/querysvc/query_service.go index 7dde2813cae..d9b4a758de3 100644 --- a/cmd/query/app/querysvc/query_service.go +++ b/cmd/query/app/querysvc/query_service.go @@ -41,6 +41,13 @@ type QueryServiceOptions struct { Adjuster adjuster.Adjuster } +// StorageCapabilities is a feature flag for query service +type StorageCapabilities struct { + ArchiveStorage bool `json:"archiveStorage"` + // SupportRegex bool + // SupportTagFilter bool +} + // QueryService contains span utils required by the query-service. type QueryService struct { spanReader spanstore.Reader @@ -122,6 +129,13 @@ func (qs QueryService) GetDependencies(ctx context.Context, endTs time.Time, loo return qs.dependencyReader.GetDependencies(ctx, endTs, lookback) } +// GetCapabilities returns the features supported by the query service. +func (qs QueryService) GetCapabilities() StorageCapabilities { + return StorageCapabilities{ + ArchiveStorage: qs.options.hasArchiveStorage(), + } +} + // InitArchiveStorage tries to initialize archive storage reader/writer if storage factory supports them. func (opts *QueryServiceOptions) InitArchiveStorage(storageFactory storage.Factory, logger *zap.Logger) bool { archiveFactory, ok := storageFactory.(storage.ArchiveFactory) @@ -151,3 +165,8 @@ func (opts *QueryServiceOptions) InitArchiveStorage(storageFactory storage.Facto opts.ArchiveSpanWriter = writer return true } + +// hasArchiveStorage returns true if archive storage reader/writer are initialized. +func (opts *QueryServiceOptions) hasArchiveStorage() bool { + return opts.ArchiveSpanReader != nil && opts.ArchiveSpanWriter != nil +} diff --git a/cmd/query/app/querysvc/query_service_test.go b/cmd/query/app/querysvc/query_service_test.go index ee214c33ea2..08741c5de57 100644 --- a/cmd/query/app/querysvc/query_service_test.go +++ b/cmd/query/app/querysvc/query_service_test.go @@ -285,6 +285,24 @@ func TestGetDependencies(t *testing.T) { assert.Equal(t, expectedDependencies, actualDependencies) } +// Test QueryService.GetFeatures() +func TestGetFeatures(t *testing.T) { + tqs := initializeTestService() + expectedStorageCapabilities := StorageCapabilities{ + ArchiveStorage: false, + } + assert.Equal(t, expectedStorageCapabilities, tqs.queryService.GetCapabilities()) +} + +func TestGetFeaturesWithSupportsArchive(t *testing.T) { + tqs := initializeTestService(withArchiveSpanReader(), withArchiveSpanWriter()) + + expectedStorageCapabilities := StorageCapabilities{ + ArchiveStorage: true, + } + assert.Equal(t, expectedStorageCapabilities, tqs.queryService.GetCapabilities()) +} + type fakeStorageFactory1 struct{} type fakeStorageFactory2 struct { diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index 15adf5f62e3..3a7d0f548cf 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -172,7 +172,7 @@ func createHTTPServer(querySvc *querysvc.QueryService, metricsQuerySvc querysvc. } apiHandler.RegisterRoutes(r) - RegisterStaticHandler(r, logger, queryOpts) + RegisterStaticHandler(r, logger, queryOpts, querySvc.GetCapabilities()) var handler http.Handler = r handler = additionalHeadersHandler(handler, queryOpts.AdditionalHeaders) if queryOpts.BearerTokenPropagation { diff --git a/cmd/query/app/static_handler.go b/cmd/query/app/static_handler.go index 5e9ab8f9f44..bc7b873b826 100644 --- a/cmd/query/app/static_handler.go +++ b/cmd/query/app/static_handler.go @@ -30,6 +30,7 @@ import ( "github.com/gorilla/mux" "go.uber.org/zap" + "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" "github.com/jaegertracing/jaeger/cmd/query/app/ui" "github.com/jaegertracing/jaeger/pkg/fswatcher" "github.com/jaegertracing/jaeger/pkg/version" @@ -37,19 +38,21 @@ import ( var ( // The following patterns are searched and replaced in the index.html as a way of customizing the UI. - configPattern = regexp.MustCompile("JAEGER_CONFIG *= *DEFAULT_CONFIG;") - configJsPattern = regexp.MustCompile(`(?im)^\s*\/\/\s*JAEGER_CONFIG_JS.*\n.*`) - versionPattern = regexp.MustCompile("JAEGER_VERSION *= *DEFAULT_VERSION;") - basePathPattern = regexp.MustCompile(`