-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 gRPC metrics to agent #1180
Merged
yurishkuro
merged 4 commits into
jaegertracing:master
from
pavolloffay:grpc-metrics-agent
Nov 16, 2018
Merged
Changes from all commits
Commits
Show all changes
4 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
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,72 @@ | ||
// Copyright (c) 2018 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 httpserver | ||
|
||
import ( | ||
"github.com/uber/jaeger-lib/metrics" | ||
|
||
"github.com/jaegertracing/jaeger/thrift-gen/baggage" | ||
"github.com/jaegertracing/jaeger/thrift-gen/sampling" | ||
) | ||
|
||
// configManagerMetrics holds metrics related to ClientConfigManager | ||
type configManagerMetrics struct { | ||
// Number of successful sampling rate responses from collector | ||
SamplingSuccess metrics.Counter `metric:"collector-proxy" tags:"result=ok,endpoint=sampling"` | ||
|
||
// Number of failed sampling rate responses from collector | ||
SamplingFailures metrics.Counter `metric:"collector-proxy" tags:"result=err,endpoint=sampling"` | ||
|
||
// Number of successful baggage restriction responses from collector | ||
BaggageSuccess metrics.Counter `metric:"collector-proxy" tags:"result=ok,endpoint=baggage"` | ||
|
||
// Number of failed baggage restriction responses from collector | ||
BaggageFailures metrics.Counter `metric:"collector-proxy" tags:"result=err,endpoint=baggage"` | ||
} | ||
|
||
// ManagerWithMetrics is manager with metrics integration. | ||
type ManagerWithMetrics struct { | ||
wrapped ClientConfigManager | ||
metrics configManagerMetrics | ||
} | ||
|
||
// WrapWithMetrics wraps ClientConfigManager and creates metrics for its invocations. | ||
func WrapWithMetrics(manager ClientConfigManager, mFactory metrics.Factory) *ManagerWithMetrics { | ||
m := configManagerMetrics{} | ||
metrics.Init(&m, mFactory, nil) | ||
return &ManagerWithMetrics{wrapped: manager, metrics: m} | ||
} | ||
|
||
// GetSamplingStrategy returns sampling strategy from server. | ||
func (m *ManagerWithMetrics) GetSamplingStrategy(serviceName string) (*sampling.SamplingStrategyResponse, error) { | ||
r, err := m.wrapped.GetSamplingStrategy(serviceName) | ||
if err != nil { | ||
m.metrics.SamplingFailures.Inc(1) | ||
} else { | ||
m.metrics.SamplingSuccess.Inc(1) | ||
} | ||
return r, err | ||
} | ||
|
||
// GetBaggageRestrictions returns baggage restrictions from server. | ||
func (m *ManagerWithMetrics) GetBaggageRestrictions(serviceName string) ([]*baggage.BaggageRestriction, error) { | ||
r, err := m.wrapped.GetBaggageRestrictions(serviceName) | ||
if err != nil { | ||
m.metrics.BaggageFailures.Inc(1) | ||
} else { | ||
m.metrics.BaggageSuccess.Inc(1) | ||
} | ||
return r, err | ||
} |
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,87 @@ | ||
// Copyright (c) 2018 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 httpserver | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/uber/jaeger-lib/metrics" | ||
mTestutils "github.com/uber/jaeger-lib/metrics/testutils" | ||
|
||
"github.com/jaegertracing/jaeger/thrift-gen/baggage" | ||
"github.com/jaegertracing/jaeger/thrift-gen/sampling" | ||
) | ||
|
||
type noopManager struct { | ||
} | ||
|
||
func (noopManager) GetSamplingStrategy(s string) (*sampling.SamplingStrategyResponse, error) { | ||
if s == "failed" { | ||
return nil, errors.New("failed") | ||
} | ||
return &sampling.SamplingStrategyResponse{StrategyType: sampling.SamplingStrategyType_PROBABILISTIC}, nil | ||
} | ||
func (noopManager) GetBaggageRestrictions(s string) ([]*baggage.BaggageRestriction, error) { | ||
if s == "failed" { | ||
return nil, errors.New("failed") | ||
} | ||
return []*baggage.BaggageRestriction{{BaggageKey: "foo"}}, nil | ||
} | ||
|
||
func TestMetrics(t *testing.T) { | ||
tests := []struct { | ||
expected []mTestutils.ExpectedMetric | ||
err error | ||
}{ | ||
{expected: []mTestutils.ExpectedMetric{ | ||
{Name: "collector-proxy", Tags: map[string]string{"result": "ok", "endpoint": "sampling"}, Value: 1}, | ||
{Name: "collector-proxy", Tags: map[string]string{"result": "err", "endpoint": "sampling"}, Value: 0}, | ||
{Name: "collector-proxy", Tags: map[string]string{"result": "ok", "endpoint": "baggage"}, Value: 1}, | ||
{Name: "collector-proxy", Tags: map[string]string{"result": "err", "endpoint": "baggage"}, Value: 0}, | ||
}}, | ||
{expected: []mTestutils.ExpectedMetric{ | ||
{Name: "collector-proxy", Tags: map[string]string{"result": "ok", "endpoint": "sampling"}, Value: 0}, | ||
{Name: "collector-proxy", Tags: map[string]string{"result": "err", "endpoint": "sampling"}, Value: 1}, | ||
{Name: "collector-proxy", Tags: map[string]string{"result": "ok", "endpoint": "baggage"}, Value: 0}, | ||
{Name: "collector-proxy", Tags: map[string]string{"result": "err", "endpoint": "baggage"}, Value: 1}, | ||
}, err: errors.New("failed")}, | ||
} | ||
|
||
for _, test := range tests { | ||
metricsFactory := metrics.NewLocalFactory(time.Microsecond) | ||
mgr := WrapWithMetrics(&noopManager{}, metricsFactory) | ||
|
||
if test.err != nil { | ||
s, err := mgr.GetSamplingStrategy(test.err.Error()) | ||
require.Nil(t, s) | ||
assert.EqualError(t, err, test.err.Error()) | ||
b, err := mgr.GetBaggageRestrictions(test.err.Error()) | ||
require.Nil(t, b) | ||
assert.EqualError(t, err, test.err.Error()) | ||
} else { | ||
s, err := mgr.GetSamplingStrategy("") | ||
require.NoError(t, err) | ||
require.NotNil(t, s) | ||
b, err := mgr.GetBaggageRestrictions("") | ||
require.NoError(t, err) | ||
require.NotNil(t, b) | ||
} | ||
mTestutils.AssertCounterMetrics(t, metricsFactory, test.expected...) | ||
} | ||
} |
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.
nit: if we remove "EmitZipkinBatch" in #1193, we need to change the changelog since the new metrics won't be partitioned by the "format".