-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat: implement gRPC storage plugin for metrics #4414
Closed
jacobmarble
wants to merge
2
commits into
jaegertracing:main
from
jacobmarble:jgm-plugin-metrics-grpc
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
|
||
"github.com/jaegertracing/jaeger/plugin" | ||
"github.com/jaegertracing/jaeger/plugin/metrics/disabled" | ||
"github.com/jaegertracing/jaeger/plugin/metrics/grpc" | ||
"github.com/jaegertracing/jaeger/plugin/metrics/prometheus" | ||
"github.com/jaegertracing/jaeger/storage" | ||
"github.com/jaegertracing/jaeger/storage/metricsstore" | ||
|
@@ -33,6 +34,7 @@ const ( | |
disabledStorageType = "" | ||
|
||
prometheusStorageType = "prometheus" | ||
grpcStorageType = "grpc-plugin" | ||
) | ||
|
||
// AllStorageTypes defines all available storage backends. | ||
|
@@ -67,6 +69,8 @@ func (f *Factory) getFactoryOfType(factoryType string) (storage.MetricsFactory, | |
switch factoryType { | ||
case prometheusStorageType: | ||
return prometheus.NewFactory(), nil | ||
case grpcStorageType: | ||
return grpc.NewFactory(), nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we add a test? |
||
case disabledStorageType: | ||
return disabled.NewFactory(), nil | ||
} | ||
|
@@ -76,7 +80,9 @@ func (f *Factory) getFactoryOfType(factoryType string) (storage.MetricsFactory, | |
// Initialize implements storage.MetricsFactory. | ||
func (f *Factory) Initialize(logger *zap.Logger) error { | ||
for _, factory := range f.factories { | ||
factory.Initialize(logger) | ||
if err := factory.Initialize(logger); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright (c) 2023 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package grpc | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/spf13/viper" | ||
"go.uber.org/zap" | ||
|
||
"github.com/jaegertracing/jaeger/plugin" | ||
"github.com/jaegertracing/jaeger/plugin/storage/grpc/config" | ||
"github.com/jaegertracing/jaeger/plugin/storage/grpc/shared" | ||
"github.com/jaegertracing/jaeger/storage" | ||
"github.com/jaegertracing/jaeger/storage/metricsstore" | ||
) | ||
|
||
var ( | ||
_ plugin.Configurable = (*Factory)(nil) | ||
_ io.Closer = (*Factory)(nil) | ||
) | ||
|
||
// Factory implements storage.MetricsFactory | ||
type Factory struct { | ||
options Options | ||
logger *zap.Logger | ||
|
||
builder config.PluginBuilder | ||
|
||
metricsReader shared.MetricsReaderPlugin | ||
capabilities shared.PluginCapabilities | ||
} | ||
|
||
// NewFactory creates a new Factory | ||
func NewFactory() *Factory { | ||
return &Factory{} | ||
} | ||
|
||
// AddFlags implements plugin.Configurable | ||
func (f *Factory) AddFlags(flagSet *flag.FlagSet) { | ||
f.options.AddFlags(flagSet) | ||
} | ||
|
||
// InitFromViper implements plugin.Configurable | ||
func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) { | ||
if err := f.options.InitFromViper(v); err != nil { | ||
logger.Fatal("unable to initialize gRPC metrics factory", zap.Error(err)) | ||
} | ||
f.builder = &f.options.Configuration | ||
} | ||
|
||
// Initialize implements storage.MetricsFactory | ||
func (f *Factory) Initialize(logger *zap.Logger) error { | ||
f.logger = logger | ||
|
||
services, err := f.builder.Build(logger) | ||
if err != nil { | ||
return fmt.Errorf("grpc-plugin builder failed to create a store: %w", err) | ||
} | ||
|
||
f.metricsReader = services.MetricsReader | ||
f.capabilities = services.Capabilities | ||
logger.Info("External plugin storage configuration", zap.Any("configuration", f.options.Configuration)) | ||
return nil | ||
} | ||
|
||
// CreateMetricsReader implements storage.MetricsFactory | ||
func (f *Factory) CreateMetricsReader() (metricsstore.Reader, error) { | ||
if f.capabilities == nil { | ||
return nil, storage.ErrMetricsStorageNotSupported | ||
} | ||
capabilities, err := f.capabilities.Capabilities() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if capabilities == nil || !capabilities.MetricsReader { | ||
return nil, storage.ErrMetricsStorageNotSupported | ||
} | ||
return f.metricsReader.MetricsReader(), nil | ||
} | ||
|
||
// Close closes the resources held by the factory | ||
func (f *Factory) Close() error { | ||
return f.builder.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2023 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package grpc | ||
|
||
// TODO write tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2023 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package grpc | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/spf13/viper" | ||
|
||
"github.com/jaegertracing/jaeger/pkg/config/tlscfg" | ||
"github.com/jaegertracing/jaeger/pkg/tenancy" | ||
"github.com/jaegertracing/jaeger/plugin/storage/grpc/config" | ||
) | ||
|
||
const ( | ||
remotePrefix = "grpc-metrics" | ||
remoteServer = remotePrefix + ".server" | ||
remoteConnectionTimeout = remotePrefix + ".connection-timeout" | ||
defaultConnectionTimeout = time.Duration(5 * time.Second) | ||
) | ||
|
||
type Options struct { | ||
Configuration config.Configuration `mapstructure:",squash"` | ||
} | ||
|
||
func NewOptions() *Options { | ||
return &Options{} | ||
} | ||
|
||
func tlsFlagsConfig() tlscfg.ClientFlagsConfig { | ||
return tlscfg.ClientFlagsConfig{ | ||
Prefix: remotePrefix, | ||
} | ||
} | ||
|
||
// AddFlags adds flags for Options | ||
func (opt *Options) AddFlags(flagSet *flag.FlagSet) { | ||
tlsFlagsConfig().AddFlags(flagSet) | ||
|
||
flagSet.String(remoteServer, "", "The remote metrics gRPC server address as host:port") | ||
flagSet.Duration(remoteConnectionTimeout, defaultConnectionTimeout, "The remote metrics gRPC server connection timeout") | ||
} | ||
|
||
// InitFromViper initializes Options with properties from viper | ||
func (opt *Options) InitFromViper(v *viper.Viper) error { | ||
opt.Configuration.RemoteServerAddr = v.GetString(remoteServer) | ||
var err error | ||
opt.Configuration.RemoteTLS, err = tlsFlagsConfig().InitFromViper(v) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse gRPC storage TLS options: %w", err) | ||
} | ||
opt.Configuration.RemoteConnectTimeout = v.GetDuration(remoteConnectionTimeout) | ||
opt.Configuration.TenancyOpts = tenancy.InitFromViper(v) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2023 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package grpc | ||
|
||
// TODO write tests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add tests? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we have
--metrics-storage-type=grpc-plugin
but then factory flags under--grpc-metrics.*
? I can't think if a better name, but at least we should keep these in sync, so let's go withgrpc-metrics