Skip to content

Commit 0b71b4a

Browse files
Copilotyurishkuro
andauthored
Remove unused factory pattern code from sampling strategy packages (#7705)
- [x] Verify that flagged functions are unused outside tests - [x] Remove unused functions from adaptive/factory.go (entire file deleted) - [x] Remove unused functions from adaptive/options.go (AddFlags, InitFromViper) - [x] Remove unused functions from adaptive/calculationstrategy/interface.go (CalculateFunc type) - [x] Remove unused functions from file/factory.go (entire file deleted) - [x] Remove unused functions from file/options.go (AddFlags, InitFromViper) - [x] Remove unused functions from file/provider.go (deepCopy) - [x] Remove unused functions from metafactory/factory.go (entire directory deleted) - [x] Remove unused functions from metafactory/factory_config.go (entire directory deleted) - [x] Clean up unused imports after deletions - [x] Remove metafactory references from cmd/internal/env/command.go - [x] Remove test files that only tested deleted functions - [x] Update remaining tests to not use deleted functions - [x] Fix formatting issues - [x] Remove unused defaultResourceName constant - [x] Remove viper imports and constants no longer needed - [x] Inline default constants into DefaultOptions() - [x] Add unit test for DefaultOptions() - [x] Build all binaries successfully (jaeger, remote-storage, and others) - [x] Run all tests successfully (sampling strategy, extension, processor tests pass) - [x] Lint passes with 0 issues ## Summary Successfully removed all 25 unused functions flagged by the deadcode detector plus additional cleanup: - Deleted entire factory.go files from adaptive, file, and metafactory packages - Removed AddFlags and InitFromViper functions from options.go files - Removed deepCopy function from file/provider.go - Removed CalculateFunc type from interface.go - Updated tests to use documented mock implementations - Removed metafactory references from cmd/internal/env/command.go - Removed viper imports and viper key constants that were only used by deleted functions - Inlined default constants directly into DefaultOptions() to reduce mental overhead - Added unit test for DefaultOptions() to provide test coverage - All binaries build successfully - All tests pass - Linter passes with 0 issues <!-- START COPILOT CODING AGENT SUFFIX --> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > Deadcode detector tool flags the following functions as unused. Verify that they are indeed not used outside of their internal unit tests and delete them. Make sure all binaries build via `make build-binaries` and all tests pass via `make tests`. > > ``` > internal/sampling/samplingstrategy/adaptive/factory.go:37:6: unreachable func: NewFactory > internal/sampling/samplingstrategy/adaptive/factory.go:47:17: unreachable func: Factory.AddFlags > internal/sampling/samplingstrategy/adaptive/factory.go:52:19: unreachable func: Factory.InitFromViper > internal/sampling/samplingstrategy/adaptive/factory.go:57:19: unreachable func: Factory.Initialize > internal/sampling/samplingstrategy/adaptive/factory.go:83:19: unreachable func: Factory.CreateStrategyProvider > internal/sampling/samplingstrategy/adaptive/factory.go:97:19: unreachable func: Factory.Close > internal/sampling/samplingstrategy/adaptive/options.go:122:6: unreachable func: AddFlags > internal/sampling/samplingstrategy/adaptive/calculationstrategy/interface.go:15:24: unreachable func: CalculateFunc.Calculate > internal/sampling/samplingstrategy/file/factory.go:26:6: unreachable func: NewFactory > internal/sampling/samplingstrategy/file/factory.go:34:17: unreachable func: Factory.AddFlags > internal/sampling/samplingstrategy/file/factory.go:39:19: unreachable func: Factory.InitFromViper > internal/sampling/samplingstrategy/file/factory.go:44:19: unreachable func: Factory.Initialize > internal/sampling/samplingstrategy/file/factory.go:50:19: unreachable func: Factory.CreateStrategyProvider > internal/sampling/samplingstrategy/file/factory.go:60:17: unreachable func: Factory.Close > internal/sampling/samplingstrategy/file/options.go:31:6: unreachable func: AddFlags > internal/sampling/samplingstrategy/file/provider.go:324:6: unreachable func: deepCopy > internal/sampling/samplingstrategy/metafactory/factory.go:45:6: unreachable func: NewFactory > internal/sampling/samplingstrategy/metafactory/factory.go:61:17: unreachable func: Factory.getFactoryOfType > internal/sampling/samplingstrategy/metafactory/factory.go:73:19: unreachable func: Factory.AddFlags > internal/sampling/samplingstrategy/metafactory/factory.go:82:19: unreachable func: Factory.InitFromViper > internal/sampling/samplingstrategy/metafactory/factory.go:91:19: unreachable func: Factory.Initialize > internal/sampling/samplingstrategy/metafactory/factory.go:101:19: unreachable func: Factory.CreateStrategyProvider > internal/sampling/samplingstrategy/metafactory/factory.go:110:19: unreachable func: Factory.Close > internal/sampling/samplingstrategy/metafactory/factory_config.go:24:6: unreachable func: FactoryConfigFromEnv > internal/sampling/samplingstrategy/metafactory/factory_config.go:36:6: unreachable func: getStrategyStoreTypeFromEnv > ``` </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: yurishkuro <[email protected]> Co-authored-by: Yuri Shkuro <[email protected]>
1 parent cb37388 commit 0b71b4a

File tree

20 files changed

+36
-997
lines changed

20 files changed

+36
-997
lines changed

cmd/internal/env/command.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/spf13/cobra"
1111
"github.com/spf13/pflag"
1212

13-
ss "github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/metafactory"
1413
"github.com/jaegertracing/jaeger/internal/storage/metricstore"
1514
storage "github.com/jaegertracing/jaeger/internal/storage/v1/factory"
1615
)
@@ -33,15 +32,6 @@ Multiple backends can be specified as comma-separated list, e.g. "cassandra,elas
3332
(currently only for writing spans). Note that "kafka" is only valid in jaeger-collector;
3433
it is not a replacement for a proper storage backend, and only used as a buffer for spans
3534
when Jaeger is deployed in the collector+ingester configuration.
36-
`
37-
38-
samplingTypeDescription = `The method [%s] used for determining the sampling rates served
39-
to clients configured with remote sampling enabled. "file" uses a periodically reloaded file and
40-
"adaptive" dynamically adjusts sampling rates based on current traffic.
41-
`
42-
43-
samplingStorageTypeDescription = `The type of backend [%s] used for adaptive sampling storage
44-
when adaptive sampling is enabled via %s.
4535
`
4636

4737
metricsStorageTypeDescription = `The type of backend [%s] used as a metrics store with
@@ -65,23 +55,6 @@ func Command() *cobra.Command {
6555
"${SPAN_STORAGE_TYPE}",
6656
"The type of backend used for service dependencies storage.",
6757
)
68-
fs.String(
69-
ss.SamplingTypeEnvVar,
70-
"file",
71-
fmt.Sprintf(
72-
strings.ReplaceAll(samplingTypeDescription, "\n", " "),
73-
strings.Join(ss.AllSamplingTypes, ", "),
74-
),
75-
)
76-
fs.String(
77-
storage.SamplingStorageTypeEnvVar,
78-
"",
79-
fmt.Sprintf(
80-
strings.ReplaceAll(samplingStorageTypeDescription, "\n", " "),
81-
strings.Join(storage.AllSamplingStorageTypes(), ", "),
82-
ss.SamplingTypeEnvVar,
83-
),
84-
)
8558
fs.String(
8659
metricstore.StorageTypeEnvVar,
8760
"",

go.mod

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ require (
157157
require (
158158
github.com/IBM/sarama v1.46.3 // indirect
159159
github.com/alecthomas/participle/v2 v2.1.4 // indirect
160-
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect
161-
github.com/andybalholm/brotli v1.2.0 // indirect
162160
github.com/antchfx/xmlquery v1.5.0 // indirect
163161
github.com/antchfx/xpath v1.3.5 // indirect
164162
github.com/aws/aws-msk-iam-sasl-signer-go v1.0.4 // indirect
@@ -171,7 +169,6 @@ require (
171169
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
172170
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3 // indirect
173171
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.14 // indirect
174-
github.com/aws/aws-sdk-go-v2/service/signin v1.0.1 // indirect
175172
github.com/aws/aws-sdk-go-v2/service/sso v1.30.4 // indirect
176173
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.9 // indirect
177174
github.com/aws/aws-sdk-go-v2/service/sts v1.41.1 // indirect
@@ -182,7 +179,6 @@ require (
182179
github.com/cespare/xxhash/v2 v2.3.0 // indirect
183180
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
184181
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
185-
github.com/dennwc/varint v1.0.0 // indirect
186182
github.com/dgraph-io/ristretto/v2 v2.2.0 // indirect
187183
github.com/dustin/go-humanize v1.0.1 // indirect
188184
github.com/eapache/go-resiliency v1.7.0 // indirect
@@ -204,16 +200,11 @@ require (
204200
github.com/gobwas/glob v0.2.3 // indirect
205201
github.com/goccy/go-json v0.10.5 // indirect
206202
github.com/gogo/googleapis v1.4.1 // indirect
207-
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
208203
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
209204
github.com/golang/snappy v1.0.0 // indirect
210205
github.com/google/flatbuffers v25.2.10+incompatible // indirect
211206
github.com/google/go-tpm v0.9.7 // indirect
212-
github.com/google/s2a-go v0.1.9 // indirect
213207
github.com/google/uuid v1.6.0 // indirect
214-
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
215-
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
216-
github.com/grafana/regexp v0.0.0-20250905093917-f7b3be9d1853 // indirect
217208
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
218209
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
219210
github.com/hashicorp/go-uuid v1.0.3 // indirect
@@ -229,15 +220,12 @@ require (
229220
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
230221
github.com/jonboulle/clockwork v0.5.0 // indirect
231222
github.com/josharian/intern v1.0.0 // indirect
232-
github.com/jpillora/backoff v1.0.0 // indirect
233223
github.com/json-iterator/go v1.1.12 // indirect
234224
github.com/klauspost/compress v1.18.1 // indirect
235-
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
236225
github.com/knadh/koanf/maps v0.1.2 // indirect
237226
github.com/knadh/koanf/providers/confmap v1.0.0 // indirect
238227
github.com/knadh/koanf/v2 v2.3.0 // indirect
239228
github.com/kr/text v0.2.0 // indirect
240-
github.com/kylelemons/godebug v1.1.0 // indirect
241229
github.com/lightstep/go-expohisto v1.0.0 // indirect
242230
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect
243231
github.com/magefile/mage v1.15.0 // indirect
@@ -251,7 +239,6 @@ require (
251239
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.141.0 // indirect
252240
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.141.0 // indirect
253241
github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter v0.141.0 // indirect
254-
github.com/open-telemetry/opentelemetry-collector-contrib/internal/healthcheck v0.141.0 // indirect
255242
github.com/open-telemetry/opentelemetry-collector-contrib/internal/kafka v0.141.0 // indirect
256243
github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil v0.141.0 // indirect
257244
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchpersignal v0.141.0 // indirect
@@ -270,14 +257,10 @@ require (
270257
github.com/paulmach/orb v0.11.1 // indirect
271258
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
272259
github.com/pierrec/lz4/v4 v4.1.22 // indirect
273-
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
274260
github.com/pkg/errors v0.9.1 // indirect
275261
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
276262
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
277-
github.com/prometheus/otlptranslator v1.0.0 // indirect
278263
github.com/prometheus/procfs v0.17.0 // indirect
279-
github.com/prometheus/prometheus v0.307.3 // indirect
280-
github.com/prometheus/sigv4 v0.2.1 // indirect
281264
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 // indirect
282265
github.com/relvacode/iso8601 v1.7.0 // indirect
283266
github.com/rogpeppe/go-internal v1.14.1 // indirect
@@ -292,22 +275,18 @@ require (
292275
github.com/spf13/cast v1.10.0 // indirect
293276
github.com/stretchr/objx v0.5.2 // indirect
294277
github.com/subosito/gotenv v1.6.0 // indirect
295-
github.com/tg123/go-htpasswd v1.2.4 // indirect
296278
github.com/tklauser/go-sysconf v0.3.15 // indirect
297279
github.com/tklauser/numcpus v0.10.0 // indirect
298280
github.com/twmb/franz-go v1.20.5 // indirect
299-
github.com/twmb/franz-go/pkg/kadm v1.17.1 // indirect
300281
github.com/twmb/franz-go/pkg/kmsg v1.12.0 // indirect
301282
github.com/twmb/franz-go/pkg/sasl/kerberos v1.1.0 // indirect
302283
github.com/twmb/franz-go/plugin/kzap v1.1.2 // indirect
303284
github.com/twmb/murmur3 v1.1.8 // indirect
304285
github.com/ua-parser/uap-go v0.0.0-20240611065828-3a4781585db6 // indirect
305286
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
306287
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
307-
github.com/xdg-go/scram v1.2.0 // indirect
308288
github.com/xdg-go/stringprep v1.0.4 // indirect
309289
github.com/yusufpapurcu/wmi v1.2.4 // indirect
310-
github.com/zeebo/xxh3 v1.0.2 // indirect
311290
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
312291
go.opentelemetry.io/collector v0.141.0 // indirect
313292
go.opentelemetry.io/collector/config/configcompression v1.47.0 // indirect
@@ -339,7 +318,6 @@ require (
339318
go.opentelemetry.io/collector/receiver/receiverhelper v0.141.0 // indirect
340319
go.opentelemetry.io/collector/receiver/receivertest v0.141.0 // indirect
341320
go.opentelemetry.io/collector/receiver/xreceiver v0.141.0 // indirect
342-
go.opentelemetry.io/collector/semconv v0.128.1-0.20250610090210-188191247685 // indirect
343321
go.opentelemetry.io/collector/service v0.141.0
344322
go.opentelemetry.io/collector/service/hostcapabilities v0.141.0 // indirect
345323
go.opentelemetry.io/contrib/bridges/otelzap v0.13.0 // indirect
@@ -357,22 +335,13 @@ require (
357335
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
358336
go.uber.org/atomic v1.11.0 // indirect
359337
go.uber.org/multierr v1.11.0 // indirect
360-
go.yaml.in/yaml/v2 v2.4.3 // indirect
361338
go.yaml.in/yaml/v3 v3.0.4
362339
golang.org/x/crypto v0.45.0 // indirect
363340
golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b
364-
golang.org/x/oauth2 v0.32.0 // indirect
365341
golang.org/x/text v0.31.0 // indirect
366-
golang.org/x/time v0.13.0 // indirect
367342
gonum.org/v1/gonum v0.16.0 // indirect
368-
google.golang.org/api v0.250.0 // indirect
369343
google.golang.org/genproto/googleapis/api v0.0.0-20251022142026-3a174f9686a8 // indirect
370344
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8 // indirect
371345
gopkg.in/inf.v0 v0.9.1 // indirect
372346
gopkg.in/yaml.v2 v2.4.0 // indirect
373-
gopkg.in/yaml.v3 v3.0.1 // indirect
374-
k8s.io/apimachinery v0.34.1 // indirect
375-
k8s.io/client-go v0.34.1 // indirect
376-
k8s.io/klog/v2 v2.130.1 // indirect
377-
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
378347
)

internal/sampling/samplingstrategy/adaptive/calculationstrategy/interface.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,3 @@ package calculationstrategy
77
type ProbabilityCalculator interface {
88
Calculate(targetQPS, curQPS, prevProbability float64) (newProbability float64)
99
}
10-
11-
// CalculateFunc wraps a function of appropriate signature and makes a ProbabilityCalculator from it.
12-
type CalculateFunc func(targetQPS, curQPS, prevProbability float64) (newProbability float64)
13-
14-
// Calculate implements Calculator interface.
15-
func (c CalculateFunc) Calculate(targetQPS, curQPS, prevProbability float64) float64 {
16-
return c(targetQPS, curQPS, prevProbability)
17-
}

internal/sampling/samplingstrategy/adaptive/calculationstrategy/interface_test.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

internal/sampling/samplingstrategy/adaptive/factory.go

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)