-
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
Replace internal metrics.Factory usage with direct calls to expvar #5496
Replace internal metrics.Factory usage with direct calls to expvar #5496
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5496 +/- ##
==========================================
+ Coverage 96.00% 96.20% +0.20%
==========================================
Files 330 327 -3
Lines 16151 16009 -142
==========================================
- Hits 15506 15402 -104
+ Misses 469 434 -35
+ Partials 176 173 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
cmd/agent/app/builder.go
Outdated
func (b *Builder) publishOpts(mFactory metrics.Factory) { | ||
internalFactory := mFactory.Namespace(metrics.NSOptions{Name: "internal"}) | ||
func (b *Builder) publishOpts() { | ||
v := expvar.NewInt("jaeger_agent_max_traces") |
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.
there are three independent variables, for each processor
cmd/agent/app/builder_test.go
Outdated
forkFactory := metricstest.NewFactory(time.Second) | ||
defer forkFactory.Stop() |
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.
this is not needed
cmd/agent/main.go
Outdated
@@ -61,10 +59,7 @@ func main() { | |||
baseFactory := svc.MetricsFactory. |
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.
baseFactory := svc.MetricsFactory. | |
mFactory := svc.MetricsFactory. |
this way you don't have to change sites where it's used
plugin/storage/factory.go
Outdated
Update(int64(f.FactoryConfig.DownsamplingRatio)) | ||
internalFactory.Gauge(metrics.Options{Name: spanStorageType + "-" + f.SpanReaderType}). | ||
Update(1) | ||
v := expvar.NewInt("jaeger_storage_max_traces") |
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.
why are you calling everything jaeger_storage_max_traces
? The names are in the code you're deleting
@@ -80,8 +79,7 @@ func TestPublishOpts(t *testing.T) { | |||
defer baseMetrics.Stop() | |||
forkFactory := metricstest.NewFactory(time.Second) | |||
defer forkFactory.Stop() | |||
metricsFactory := fork.New("internal", forkFactory, baseMetrics) | |||
require.NoError(t, f.Initialize(metricsFactory, zap.NewNop())) | |||
require.NoError(t, f.Initialize(forkFactory, zap.NewNop())) | |||
|
|||
forkFactory.AssertGaugeMetrics(t, metricstest.ExpectedMetric{ |
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.
you changed PublishOpt to use expvar, metric factories are no longer relevant. You need to validate that the correct expvar is set (you can see how to do that in expvar/factory_test.go)
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.
thanks for the help
its producing |
cmd/agent/app/builder_test.go
Outdated
if got := expvar.Get(prefix + suffixServerMaxPacketSize).(*expvar.Int).Value(); got != 4242 { | ||
t.Errorf(`expected %d, but got %d for %s`, 4242, got, fmt.Sprintf(prefix+suffixServerMaxPacketSize)) | ||
} |
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.
if got := expvar.Get(prefix + suffixServerMaxPacketSize).(*expvar.Int).Value(); got != 4242 { | |
t.Errorf(`expected %d, but got %d for %s`, 4242, got, fmt.Sprintf(prefix+suffixServerMaxPacketSize)) | |
} | |
assert.EqualValue(t, 4242, expvar.Get(prefix + suffixServerMaxPacketSize).(*expvar.Int).Value()) |
plugin/storage/factory_test.go
Outdated
if got := expvar.Get(downsamplingRatio).(*expvar.Int).Value(); got != 1 { | ||
t.Errorf("expected %d, but got %d for %s", 1, got, downsamplingRatio) | ||
} |
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.
use assert
if got := expvar.Get("jaeger_storage_memory_max_traces").(*expvar.Int).Value(); got != 100 { | ||
t.Errorf("expected %d, but got %d for jaeger_storage_memory_max_traces", 100, got) | ||
} |
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.
use assert
Yeah, I can see why, since tests are running from a single binary and the expvars are global. In the package you deleted we had a cache that was remembering already created expvars by name and on subsequent calls returning the same instance as before. You may need to restore and refactor that cache. It doesn't need to work with metrics API anymore, just with the types of expvars we actually use (mostly int, but maybe others). I would put it under internal/safeexpvar. |
Signed-off-by: Griffin <prakritimandal611@gmail.com>
2465cdb
to
dfb4a79
Compare
Signed-off-by: Griffin <prakritimandal611@gmail.com>
cmd/agent/app/builder.go
Outdated
Update(int64(p.Server.QueueSize)) | ||
internalFactory.Gauge(metrics.Options{Name: prefix + suffixWorkers}). | ||
Update(int64(p.Workers)) | ||
safeexpvar.SetExpvarInt(prefix+suffixServerMaxPacketSize, int64(p.Server.MaxPacketSize)) |
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.
safeexpvar.SetExpvarInt(prefix+suffixServerMaxPacketSize, int64(p.Server.MaxPacketSize)) | |
safeexpvar.SetInt(prefix+suffixServerMaxPacketSize, int64(p.Server.MaxPacketSize)) |
it is already explicit from package name that this is expvar
cmd/agent/app/builder.go
Outdated
Update(int64(p.Workers)) | ||
safeexpvar.SetExpvarInt(prefix+suffixServerMaxPacketSize, int64(p.Server.MaxPacketSize)) | ||
// v := expvar.NewInt(prefix + suffixServerMaxPacketSize) | ||
// v.Set(int64(p.Server.MaxPacketSize)) |
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.
please remove commented code
cmd/collector/app/collector_test.go
Outdated
Name: "internal.collector.num-workers", | ||
Value: 24, | ||
}) | ||
forkFactory.AssertGaugeMetrics(t, metricstest.ExpectedMetric{ | ||
metricsFactory.AssertGaugeMetrics(t, metricstest.ExpectedMetric{ | ||
Name: "internal.collector.queue-size", |
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.
Where in the code are these emitted? If this test is passing we may have missed a place where these were emitted via "internal" namespace instead of writing directly to expvar
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.
yes, there is a metrics emitted from an internal ns
internal/safeexpvar/checkexpvar.go
Outdated
@@ -1,4 +1,5 @@ | |||
// Copyright (c) 2023 The Jaeger Authors. | |||
// Copyright (c) 2022 The Jaeger Authors. |
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.
// Copyright (c) 2022 The Jaeger Authors. | |
// Copyright (c) 2024 The Jaeger Authors. |
internal/safeexpvar/checkexpvar.go
Outdated
@@ -12,14 +13,16 @@ | |||
// See the License for the specific language governing permissions and | |||
// limitations under the License. | |||
|
|||
package expvar | |||
package safeexpvar |
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.
internal/safeexpvar/checkexpvar.go -> internal/safeexpvar/safeexpvar.go
) | ||
|
||
func TestSetExpvarInt(t *testing.T) { | ||
initialGoroutines := runtime.NumGoroutine() |
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.
just add a TestMain like this:
forkFactory := metricstest.NewFactory(time.Second) | ||
defer forkFactory.Stop() | ||
metricsFactory := fork.New("internal", forkFactory, baseMetrics) | ||
metricsFactory := metricstest.NewFactory(time.Second) |
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.
you can just use metrics.NullFactory, since you're not validating anything with it
go.mod
Outdated
require ( | ||
golang.org/x/mod v0.17.0 // indirect | ||
golang.org/x/tools v0.21.0 // indirect | ||
) | ||
|
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.
please remove, there are no dependency changes in this PR
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.
and run go mod tidy
after removing
// Copyright (c) 2024 The Jaeger Authors. | ||
// Copyright (c) 2018 Uber Technologies, Inc. | ||
// | ||
// 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. |
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.
// Copyright (c) 2024 The Jaeger Authors. | |
// Copyright (c) 2018 Uber Technologies, Inc. | |
// | |
// 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. | |
// Copyright (c) 2024 The Jaeger Authors. | |
// SPDX-License-Identifier: Apache-2.0 |
internal/safeexpvar/safeexpvar.go
Outdated
@@ -1,4 +1,5 @@ | |||
// Copyright (c) 2023 The Jaeger Authors. | |||
// Copyright (c) 2024 The Jaeger Authors. | |||
// Copyright (c) 2018 Uber Technologies, Inc. |
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.
// Copyright (c) 2018 Uber Technologies, Inc. |
expInt, ok := v.(*expvar.Int) | ||
assert.True(t, ok, "expected variable %s to be of type *expvar.Int", name) |
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.
assert has type checks functions
also this should be require.
not assert.
since you cannot continue if condition is not met
assert.NotNil(t, v, "expected variable %s to be created", name) | ||
expInt, ok := v.(*expvar.Int) | ||
assert.True(t, ok, "expected variable %s to be of type *expvar.Int", name) | ||
assert.Equal(t, value, expInt.Value(), "expected variable %s value to be %d", name, value) |
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.
assert.Equal(t, value, expInt.Value(), "expected variable %s value to be %d", name, value) | |
assert.Equal(t, value, expInt.Value()) |
assert produces descriptive enough message
metricsFactory := metrics.NullFactory | ||
require.NoError(t, f.Initialize(metricsFactory, zap.NewNop())) |
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.
metricsFactory := metrics.NullFactory | |
require.NoError(t, f.Initialize(metricsFactory, zap.NewNop())) | |
require.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop())) |
Signed-off-by: Griffin <prakritimandal611@gmail.com>
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.
Thanks!
…aegertracing#5496) ## Which problem is this PR solving? - fixes: jaegertracing#5495 ## Description of the changes * removed fork.New factory usage * identify which internal components use "internal" namespace to report settings and replace with expvar directly * removed internal/metrics/fork/* * removed internal/metrics/expvar/* * fixed tests ## How was this change tested? - ## Checklist - [ ] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [ ] I have signed all commits - [ ] I have added unit tests for the new functionality - [ ] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Griffin <prakritimandal611@gmail.com> Signed-off-by: Vamshi Maskuri <gwcchintu@gmail.com>
Which problem is this PR solving?
expvar
#5495Description of the changes
How was this change tested?
Checklist
jaeger
:make lint test
jaeger-ui
:yarn lint
andyarn test