From c17b575761c770d42cb6e030c739ee79b8c4d7b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20Antonin?= Date: Wed, 8 Nov 2023 00:26:30 +0100 Subject: [PATCH] Make ArchiveTrace button auto-configurable (#4913) ## Which problem is this PR solving? - backend part of #4874 ## Description of the changes 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. Related UI change https://github.com/jaegertracing/jaeger-ui/pull/1944 ## How was this change tested? All corresponding tests have been updated. ## Checklist - [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: Antonin Barthelemy --------- Signed-off-by: Barthelemy Antonin Signed-off-by: Yuri Shkuro Co-authored-by: Yuri Shkuro Co-authored-by: Yuri Shkuro --- 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 | 62 ++++++++++--------- cmd/query/app/static_handler_test.go | 63 ++++++++++++-------- 6 files changed, 117 insertions(+), 57 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..4a8b0031b5b 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.GetCapacities() +func TestGetCapabilities(t *testing.T) { + tqs := initializeTestService() + expectedStorageCapabilities := StorageCapabilities{ + ArchiveStorage: false, + } + assert.Equal(t, expectedStorageCapabilities, tqs.queryService.GetCapabilities()) +} + +func TestGetCapabilitiesWithSupportsArchive(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..f4f723f6ef1 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(`