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

Replace internal metrics.Factory usage with direct calls to expvar #5496

Merged

Conversation

prakrit55
Copy link
Contributor

Which problem is this PR solving?

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

@prakrit55 prakrit55 requested a review from a team as a code owner May 28, 2024 07:55
@prakrit55 prakrit55 requested a review from albertteoh May 28, 2024 07:55
@prakrit55 prakrit55 marked this pull request as draft May 28, 2024 07:56
Copy link

codecov bot commented May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.20%. Comparing base (5900360) to head (916ce93).
Report is 1 commits behind head on main.

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     
Flag Coverage Δ
badger_v1 8.05% <0.00%> (ø)
badger_v2 1.93% <0.00%> (ø)
cassandra-3.x-v1 16.43% <0.00%> (ø)
cassandra-3.x-v2 1.85% <0.00%> (ø)
cassandra-4.x-v1 16.43% <0.00%> (ø)
cassandra-4.x-v2 1.85% <0.00%> (ø)
elasticsearch-7.x-v1 18.88% <0.00%> (-0.02%) ⬇️
elasticsearch-8.x-v1 19.07% <0.00%> (-0.02%) ⬇️
elasticsearch-8.x-v2 19.08% <0.00%> (?)
grpc_v1 9.48% <100.00%> (?)
grpc_v2 7.53% <100.00%> (-0.06%) ⬇️
kafka 9.78% <0.00%> (ø)
opensearch-1.x-v1 18.94% <0.00%> (?)
opensearch-2.x-v1 18.92% <0.00%> (?)
opensearch-2.x-v2 18.92% <0.00%> (ø)
unittests 93.90% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

cmd/agent/app/builder.go Show resolved Hide resolved
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")
Copy link
Member

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.go Outdated Show resolved Hide resolved
Comment on lines 310 to 311
forkFactory := metricstest.NewFactory(time.Second)
defer forkFactory.Stop()
Copy link
Member

Choose a reason for hiding this comment

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

this is not needed

@@ -61,10 +59,7 @@ func main() {
baseFactory := svc.MetricsFactory.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
baseFactory := svc.MetricsFactory.
mFactory := svc.MetricsFactory.

this way you don't have to change sites where it's used

cmd/collector/main.go Show resolved Hide resolved
Update(int64(f.FactoryConfig.DownsamplingRatio))
internalFactory.Gauge(metrics.Options{Name: spanStorageType + "-" + f.SpanReaderType}).
Update(1)
v := expvar.NewInt("jaeger_storage_max_traces")
Copy link
Member

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

plugin/storage/factory_test.go Show resolved Hide resolved
plugin/storage/memory/factory.go Outdated Show resolved Hide resolved
@@ -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{
Copy link
Member

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)

Copy link
Contributor Author

@prakrit55 prakrit55 May 29, 2024

Choose a reason for hiding this comment

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

thanks for the help

@prakrit55
Copy link
Contributor Author

its producing panic: Reuse of exported var name: type errors when all file tests are ran at a time

Comment on lines 320 to 322
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))
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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())

cmd/collector/app/collector_test.go Show resolved Hide resolved
cmd/collector/main.go Show resolved Hide resolved
Comment on lines 412 to 414
if got := expvar.Get(downsamplingRatio).(*expvar.Int).Value(); got != 1 {
t.Errorf("expected %d, but got %d for %s", 1, got, downsamplingRatio)
}
Copy link
Member

Choose a reason for hiding this comment

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

use assert

Comment on lines 83 to 85
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)
}
Copy link
Member

Choose a reason for hiding this comment

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

use assert

@yurishkuro
Copy link
Member

its producing panic: Reuse of exported var name: type errors when all file tests are ran at a time

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>
Signed-off-by: Griffin <prakritimandal611@gmail.com>
Signed-off-by: Griffin <prakritimandal611@gmail.com>
Signed-off-by: Griffin <prakritimandal611@gmail.com>
Signed-off-by: Griffin <prakritimandal611@gmail.com>
Signed-off-by: Griffin <prakritimandal611@gmail.com>
@prakrit55 prakrit55 force-pushed the replace-internal-metrics.Factory-expvar branch from 2465cdb to dfb4a79 Compare May 30, 2024 09:07
@prakrit55 prakrit55 marked this pull request as ready for review May 30, 2024 09:22
Signed-off-by: Griffin <prakritimandal611@gmail.com>
Update(int64(p.Server.QueueSize))
internalFactory.Gauge(metrics.Options{Name: prefix + suffixWorkers}).
Update(int64(p.Workers))
safeexpvar.SetExpvarInt(prefix+suffixServerMaxPacketSize, int64(p.Server.MaxPacketSize))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Update(int64(p.Workers))
safeexpvar.SetExpvarInt(prefix+suffixServerMaxPacketSize, int64(p.Server.MaxPacketSize))
// v := expvar.NewInt(prefix + suffixServerMaxPacketSize)
// v.Set(int64(p.Server.MaxPacketSize))
Copy link
Member

Choose a reason for hiding this comment

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

please remove commented code

Name: "internal.collector.num-workers",
Value: 24,
})
forkFactory.AssertGaugeMetrics(t, metricstest.ExpectedMetric{
metricsFactory.AssertGaugeMetrics(t, metricstest.ExpectedMetric{
Name: "internal.collector.queue-size",
Copy link
Member

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

Copy link
Contributor Author

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

@@ -1,4 +1,5 @@
// Copyright (c) 2023 The Jaeger Authors.
// Copyright (c) 2022 The Jaeger Authors.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright (c) 2022 The Jaeger Authors.
// Copyright (c) 2024 The Jaeger Authors.

@@ -12,14 +13,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package expvar
package safeexpvar
Copy link
Member

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

Choose a reason for hiding this comment

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

forkFactory := metricstest.NewFactory(time.Second)
defer forkFactory.Stop()
metricsFactory := fork.New("internal", forkFactory, baseMetrics)
metricsFactory := metricstest.NewFactory(time.Second)
Copy link
Member

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

Signed-off-by: Griffin <prakritimandal611@gmail.com>
Signed-off-by: Griffin <prakritimandal611@gmail.com>
Signed-off-by: Griffin <prakritimandal611@gmail.com>
go.mod Outdated
Comment on lines 84 to 88
require (
golang.org/x/mod v0.17.0 // indirect
golang.org/x/tools v0.21.0 // indirect
)

Copy link
Member

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

Copy link
Member

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

Comment on lines 1 to 14
// 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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 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

@@ -1,4 +1,5 @@
// Copyright (c) 2023 The Jaeger Authors.
// Copyright (c) 2024 The Jaeger Authors.
// Copyright (c) 2018 Uber Technologies, Inc.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright (c) 2018 Uber Technologies, Inc.

Comment on lines 37 to 38
expInt, ok := v.(*expvar.Int)
assert.True(t, ok, "expected variable %s to be of type *expvar.Int", name)
Copy link
Member

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

Choose a reason for hiding this comment

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

Suggested change
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

Comment on lines 77 to 78
metricsFactory := metrics.NullFactory
require.NoError(t, f.Initialize(metricsFactory, zap.NewNop()))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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>
Signed-off-by: Griffin <prakritimandal611@gmail.com>
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

Thanks!

@yurishkuro yurishkuro merged commit ac7744e into jaegertracing:main May 31, 2024
40 checks passed
varshith257 pushed a commit to varshith257/jaeger that referenced this pull request Jun 2, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace "internal" metrics.Factory usage with direct calls to expvar
2 participants