Skip to content

Commit

Permalink
Add metrics storage to storage capabilities
Browse files Browse the repository at this point in the history
Signed-off-by: FlamingSaint <[email protected]>
  • Loading branch information
FlamingSaint committed Jul 25, 2024
1 parent e437971 commit 0ce192f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
5 changes: 3 additions & 2 deletions cmd/jaeger/internal/extension/jaegerquery/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *server) Start(_ context.Context, host component.Host) error {
}
qs := querysvc.NewQueryService(spanReader, depReader, opts)

mqs, err := s.createMetricReader(host)
mqs, err := s.createMetricReader(&opts, host)
if err != nil {
return err
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func (s *server) addArchiveStorage(opts *querysvc.QueryServiceOptions, host comp
return nil
}

func (s *server) createMetricReader(host component.Host) (metricsstore.Reader, error) {
func (s *server) createMetricReader(opts *querysvc.QueryServiceOptions, host component.Host) (metricsstore.Reader, error) {
if s.config.MetricStorage == "" {
s.telset.Logger.Info("Metric storage not configured")
return disabled.NewMetricsReader()
Expand All @@ -143,6 +143,7 @@ func (s *server) createMetricReader(host component.Host) (metricsstore.Reader, e
if err != nil {
return nil, fmt.Errorf("cannot create metrics reader %w", err)
}
opts.MetricsReader = metricsReader
return metricsReader, err
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/jaeger/internal/extension/jaegerquery/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func TestServerAddMetricsStorage(t *testing.T) {

tests := []struct {
name string
qSvcOpts *querysvc.QueryServiceOptions
config *Config
extension component.Component
expectedOutput string
Expand All @@ -301,6 +302,7 @@ func TestServerAddMetricsStorage(t *testing.T) {
{
name: "Metrics storage unset",
config: &Config{},
qSvcOpts: &querysvc.QueryServiceOptions{},
expectedOutput: `{"level":"info","msg":"Metric storage not configured"}` + "\n",
expectedErr: "",
},
Expand All @@ -309,6 +311,7 @@ func TestServerAddMetricsStorage(t *testing.T) {
config: &Config{
MetricStorage: "random-value",
},
qSvcOpts: &querysvc.QueryServiceOptions{},
expectedOutput: "",
expectedErr: "cannot find metrics storage factory: cannot find extension",
},
Expand All @@ -324,7 +327,7 @@ func TestServerAddMetricsStorage(t *testing.T) {
if tt.extension != nil {
host = storagetest.NewStorageHost().WithExtension(jaegerstorage.ID, tt.extension)
}
_, err := server.createMetricReader(host)
_, err := server.createMetricReader(tt.qSvcOpts, host)
if tt.expectedErr == "" {
require.NoError(t, err)
} else {
Expand Down
11 changes: 10 additions & 1 deletion cmd/query/app/querysvc/query_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/jaegertracing/jaeger/model/adjuster"
"github.com/jaegertracing/jaeger/storage"
"github.com/jaegertracing/jaeger/storage/dependencystore"
"github.com/jaegertracing/jaeger/storage/metricsstore"
"github.com/jaegertracing/jaeger/storage/spanstore"
)

Expand All @@ -38,13 +39,14 @@ const (
type QueryServiceOptions struct {
ArchiveSpanReader spanstore.Reader
ArchiveSpanWriter spanstore.Writer
MetricsReader metricsstore.Reader
Adjuster adjuster.Adjuster
}

// StorageCapabilities is a feature flag for query service
type StorageCapabilities struct {
ArchiveStorage bool `json:"archiveStorage"`
// TODO: Maybe add metrics Storage here
MetricStorage bool `json:"metricsStorage"`
// SupportRegex bool
// SupportTagFilter bool
}
Expand Down Expand Up @@ -134,6 +136,7 @@ func (qs QueryService) GetDependencies(ctx context.Context, endTs time.Time, loo
func (qs QueryService) GetCapabilities() StorageCapabilities {
return StorageCapabilities{
ArchiveStorage: qs.options.hasArchiveStorage(),
MetricStorage: qs.options.hasMetricStorage(),
}
}

Expand Down Expand Up @@ -171,3 +174,9 @@ func (opts *QueryServiceOptions) InitArchiveStorage(storageFactory storage.Facto
func (opts *QueryServiceOptions) hasArchiveStorage() bool {
return opts.ArchiveSpanReader != nil && opts.ArchiveSpanWriter != nil
}

// hasMetricsStorage returns true if metric storage reader is initialized.
func (opts *QueryServiceOptions) hasMetricStorage() bool {
// TODO: NEED to pass the reader when the metricsreader is created
return opts.MetricsReader != nil
}
6 changes: 3 additions & 3 deletions cmd/query/app/static_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestRegisterStaticHandler(t *testing.T) {
logAccess: true,
UIConfigPath: "",
expectedUIConfig: "JAEGER_CONFIG=DEFAULT_CONFIG;",
expectedStorageCapabilities: `JAEGER_STORAGE_CAPABILITIES = {"archiveStorage":false};`,
expectedStorageCapabilities: `JAEGER_STORAGE_CAPABILITIES = {"archiveStorage":false,"metricsStorage":false};`,
},
{
basePath: "/",
Expand All @@ -96,7 +96,7 @@ func TestRegisterStaticHandler(t *testing.T) {
expectedBaseHTML: `<base href="/"`,
UIConfigPath: "fixture/ui-config.json",
expectedUIConfig: `JAEGER_CONFIG = {"x":"y"};`,
expectedStorageCapabilities: `JAEGER_STORAGE_CAPABILITIES = {"archiveStorage":false};`,
expectedStorageCapabilities: `JAEGER_STORAGE_CAPABILITIES = {"archiveStorage":false,"metricsStorage":false};`,
},
{
basePath: "/jaeger",
Expand All @@ -106,7 +106,7 @@ func TestRegisterStaticHandler(t *testing.T) {
archiveStorage: true,
UIConfigPath: "fixture/ui-config.js",
expectedUIConfig: "function UIConfig(){",
expectedStorageCapabilities: `JAEGER_STORAGE_CAPABILITIES = {"archiveStorage":true};`,
expectedStorageCapabilities: `JAEGER_STORAGE_CAPABILITIES = {"archiveStorage":true,"metricsStorage":false};`,
},
}
httpClient = &http.Client{
Expand Down

0 comments on commit 0ce192f

Please sign in to comment.