Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics storage to storage capabilities #5774

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
FlamingSaint marked this conversation as resolved.
Show resolved Hide resolved
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{},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of defining these as test case parameter if they don't change across tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modelled this based on the archive storage test.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query service constructor accepts metric reader as argument. Having it also as a field in these options is redundant and confusing to the callers of the constructor

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the query service constructor accepts metric reader as an argument . It only accepts span reader, dependency reader and options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it's even worse, if QueryService struct is only designed to serve trace queries, there's absolutely no reason to introduce metrics reader into it. Metrics reader is actually a counterpart for QueryService. It's a poor design to couple them in any way.

Notice that QueryService itself does not serve any remote endpoints, it's purely an internal API. The capabilities struct is served via remote endpoint by app.Server (which does have access to move qs and mqs), and this is where the logic should be, ideally.

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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it need to interrogate Options if you have access to qs which likely already stores the reference to metric reader?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No qs doesn't store the reference to the metrics reader. The options does.

}
}

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
Loading