diff --git a/.golangci.yml b/.golangci.yml index 7c4e9314df82..5427041391e6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -105,6 +105,9 @@ linters: # Checks usage of github.com/stretchr/testify. - testifylint + # Detects the possibility to use variables/constants from the Go standard library. + - usestdlibvars + # TODO consider adding more linters, cf. https://olegk.dev/go-linters-configuration-the-right-version linters-settings: diff --git a/cmd/anonymizer/app/anonymizer/anonymizer_test.go b/cmd/anonymizer/app/anonymizer/anonymizer_test.go index 431cc0162a6e..6d2f219c0620 100644 --- a/cmd/anonymizer/app/anonymizer/anonymizer_test.go +++ b/cmd/anonymizer/app/anonymizer/anonymizer_test.go @@ -4,6 +4,7 @@ package anonymizer import ( + "net/http" "os" "path/filepath" "testing" @@ -18,7 +19,7 @@ import ( var tags = []model.KeyValue{ model.Bool("error", true), - model.String("http.method", "POST"), + model.String("http.method", http.MethodPost), model.Bool("foobar", true), } @@ -127,7 +128,7 @@ func TestAnonymizer_SaveMapping(t *testing.T) { func TestAnonymizer_FilterStandardTags(t *testing.T) { expected := []model.KeyValue{ model.Bool("error", true), - model.String("http.method", "POST"), + model.String("http.method", http.MethodPost), } actual := filterStandardTags(tags) assert.Equal(t, expected, actual) diff --git a/cmd/anonymizer/app/writer/writer_test.go b/cmd/anonymizer/app/writer/writer_test.go index c6e11434cccc..dc746f16b635 100644 --- a/cmd/anonymizer/app/writer/writer_test.go +++ b/cmd/anonymizer/app/writer/writer_test.go @@ -4,6 +4,7 @@ package writer import ( + "net/http" "testing" "time" @@ -15,7 +16,7 @@ import ( var tags = []model.KeyValue{ model.Bool("error", true), - model.String("http.method", "POST"), + model.String("http.method", http.MethodPost), model.Bool("foobar", true), } diff --git a/cmd/es-rollover/app/actions.go b/cmd/es-rollover/app/actions.go index 8dbeff30e95b..3b3cf6149cf3 100644 --- a/cmd/es-rollover/app/actions.go +++ b/cmd/es-rollover/app/actions.go @@ -4,14 +4,15 @@ package app import ( + "context" "crypto/tls" + "fmt" "net/http" "time" "github.com/spf13/viper" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/pkg/config/tlscfg" "github.com/jaegertracing/jaeger/pkg/es/client" ) @@ -37,10 +38,9 @@ type Action interface { // ActionExecuteOptions are the options passed to the execute action function type ActionExecuteOptions struct { - Args []string - Viper *viper.Viper - Logger *zap.Logger - TLSFlags tlscfg.ClientFlagsConfig + Args []string + Viper *viper.Viper + Logger *zap.Logger } // ActionCreatorFunction type is the function type in charge of create the action to be executed @@ -50,15 +50,12 @@ type ActionCreatorFunction func(client.Client, Config) Action func ExecuteAction(opts ActionExecuteOptions, createAction ActionCreatorFunction) error { cfg := Config{} cfg.InitFromViper(opts.Viper) - tlsOpts, err := opts.TLSFlags.InitFromViper(opts.Viper) - if err != nil { - return err - } - tlsCfg, err := tlsOpts.Config(opts.Logger) + + ctx := context.Background() + tlsCfg, err := cfg.TLSConfig.LoadTLSConfig(ctx) if err != nil { - return err + return fmt.Errorf("TLS configuration failed: %w", err) } - defer tlsOpts.Close() esClient := newESClient(opts.Args[0], &cfg, tlsCfg) action := createAction(esClient, cfg) diff --git a/cmd/es-rollover/app/actions_test.go b/cmd/es-rollover/app/actions_test.go index e4b7a33c34f9..bc78ef118278 100644 --- a/cmd/es-rollover/app/actions_test.go +++ b/cmd/es-rollover/app/actions_test.go @@ -5,17 +5,14 @@ package app import ( "errors" - "flag" "net/http" "testing" - "github.com/spf13/cobra" - "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/pkg/config/tlscfg" + "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/es/client" ) @@ -73,22 +70,14 @@ func TestExecuteAction(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - v := viper.New() - tlsFlags := tlscfg.ClientFlagsConfig{Prefix: "es"} - command := cobra.Command{} - flags := &flag.FlagSet{} - tlsFlags.AddFlags(flags) - command.PersistentFlags().AddGoFlagSet(flags) - v.BindPFlags(command.PersistentFlags()) + v, command := config.Viperize(AddFlags) cmdLine := append([]string{"--es.tls.enabled=true"}, test.flags...) - err := command.ParseFlags(cmdLine) - require.NoError(t, err) + require.NoError(t, command.ParseFlags(cmdLine)) executedAction := false - err = ExecuteAction(ActionExecuteOptions{ - Args: args, - Viper: v, - Logger: logger, - TLSFlags: tlsFlags, + err := ExecuteAction(ActionExecuteOptions{ + Args: args, + Viper: v, + Logger: logger, }, func(c client.Client, _ Config) Action { assert.Equal(t, "https://localhost:9300", c.Endpoint) transport, ok := c.Client.Transport.(*http.Transport) @@ -101,7 +90,6 @@ func TestExecuteAction(t *testing.T) { }, } }) - assert.Equal(t, test.expectedExecuteAction, executedAction) if test.configError { require.Error(t, err) diff --git a/cmd/es-rollover/app/flags.go b/cmd/es-rollover/app/flags.go index bf7bfcac1f03..a1456546546b 100644 --- a/cmd/es-rollover/app/flags.go +++ b/cmd/es-rollover/app/flags.go @@ -7,8 +7,13 @@ import ( "flag" "github.com/spf13/viper" + "go.opentelemetry.io/collector/config/configtls" + + "github.com/jaegertracing/jaeger/pkg/config/tlscfg" ) +var tlsFlagsCfg = tlscfg.ClientFlagsConfig{Prefix: "es"} + const ( indexPrefix = "index-prefix" archive = "archive" @@ -33,6 +38,7 @@ type Config struct { Timeout int SkipDependencies bool AdaptiveSampling bool + TLSConfig configtls.ClientConfig } // AddFlags adds flags @@ -46,6 +52,7 @@ func AddFlags(flags *flag.FlagSet) { flags.Int(timeout, 120, "Number of seconds to wait for master node response") flags.Bool(skipDependencies, false, "Disable rollover for dependencies index") flags.Bool(adaptiveSampling, false, "Enable rollover for adaptive sampling index") + tlsFlagsCfg.AddFlags(flags) } // InitFromViper initializes config from viper.Viper. @@ -62,4 +69,9 @@ func (c *Config) InitFromViper(v *viper.Viper) { c.Timeout = v.GetInt(timeout) c.SkipDependencies = v.GetBool(skipDependencies) c.AdaptiveSampling = v.GetBool(adaptiveSampling) + opts, err := tlsFlagsCfg.InitFromViper(v) + if err != nil { + panic(err) + } + c.TLSConfig = opts.ToOtelClientConfig() } diff --git a/cmd/es-rollover/main.go b/cmd/es-rollover/main.go index 5fe026d6e681..411d4596d2fc 100644 --- a/cmd/es-rollover/main.go +++ b/cmd/es-rollover/main.go @@ -16,7 +16,6 @@ import ( "github.com/jaegertracing/jaeger/cmd/es-rollover/app/lookback" "github.com/jaegertracing/jaeger/cmd/es-rollover/app/rollover" "github.com/jaegertracing/jaeger/pkg/config" - "github.com/jaegertracing/jaeger/pkg/config/tlscfg" "github.com/jaegertracing/jaeger/pkg/es/client" ) @@ -30,8 +29,6 @@ func main() { Long: "Jaeger es-rollover manages Jaeger indices", } - tlsFlags := tlscfg.ClientFlagsConfig{Prefix: "es"} - // Init command initCfg := &initialize.Config{} initCommand := &cobra.Command{ @@ -42,10 +39,9 @@ func main() { SilenceUsage: true, RunE: func(_ *cobra.Command, args []string) error { return app.ExecuteAction(app.ActionExecuteOptions{ - Args: args, - Viper: v, - Logger: logger, - TLSFlags: tlsFlags, + Args: args, + Viper: v, + Logger: logger, }, func(c client.Client, cfg app.Config) app.Action { initCfg.Config = cfg initCfg.InitFromViper(v) @@ -80,10 +76,9 @@ func main() { RunE: func(_ *cobra.Command, args []string) error { rolloverCfg.InitFromViper(v) return app.ExecuteAction(app.ActionExecuteOptions{ - Args: args, - Viper: v, - Logger: logger, - TLSFlags: tlsFlags, + Args: args, + Viper: v, + Logger: logger, }, func(c client.Client, cfg app.Config) app.Action { rolloverCfg.Config = cfg rolloverCfg.InitFromViper(v) @@ -109,10 +104,9 @@ func main() { RunE: func(_ *cobra.Command, args []string) error { lookbackCfg.InitFromViper(v) return app.ExecuteAction(app.ActionExecuteOptions{ - Args: args, - Viper: v, - Logger: logger, - TLSFlags: tlsFlags, + Args: args, + Viper: v, + Logger: logger, }, func(c client.Client, cfg app.Config) app.Action { lookbackCfg.Config = cfg lookbackCfg.InitFromViper(v) @@ -129,7 +123,7 @@ func main() { }, } - addPersistentFlags(v, rootCmd, tlsFlags.AddFlags, app.AddFlags) + addPersistentFlags(v, rootCmd, app.AddFlags) addSubCommand(v, rootCmd, initCommand, initCfg.AddFlags) addSubCommand(v, rootCmd, rolloverCommand, rolloverCfg.AddFlags) addSubCommand(v, rootCmd, lookbackCommand, lookbackCfg.AddFlags) diff --git a/cmd/internal/status/command.go b/cmd/internal/status/command.go index 02f2e48683ae..355719ae4a02 100644 --- a/cmd/internal/status/command.go +++ b/cmd/internal/status/command.go @@ -30,7 +30,7 @@ func Command(v *viper.Viper, adminPort int) *cobra.Command { url := convert(v.GetString(statusHTTPHostPort)) ctx, cx := context.WithTimeout(context.Background(), time.Second) defer cx() - req, _ := http.NewRequestWithContext(ctx, "GET", url, nil) + req, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) resp, err := http.DefaultClient.Do(req) if err != nil { return err diff --git a/cmd/jaeger/docs/migration/all-in-one-metrics.md b/cmd/jaeger/docs/migration/all-in-one-metrics.md new file mode 100644 index 000000000000..28f165b2be38 --- /dev/null +++ b/cmd/jaeger/docs/migration/all-in-one-metrics.md @@ -0,0 +1,86 @@ +# ALL-IN-ONE METRICS +### Combined Metrics + +| V1 Metric | V1 Labels | V2 Metric | V2 Labels | +|-----------|---------------|-----------|---------------| +| jaeger_query_latency | operation, result | jaeger_query_latency | operation, result | +| jaeger_query_responses | operation | jaeger_query_responses | operation | +| jaeger_query_requests_total | operation, result | jaeger_query_requests_total | operation, result | +| go_gc_duration_seconds | N/A | N/A | N/A | +| go_goroutines | N/A | N/A | N/A | +| go_info | version | N/A | N/A | +| go_memstats_alloc_bytes | N/A | N/A | N/A | +| go_memstats_alloc_bytes_total | N/A | N/A | N/A | +| go_memstats_buck_hash_sys_bytes | N/A | N/A | N/A | +| go_memstats_frees_total | N/A | N/A | N/A | +| go_memstats_gc_sys_bytes | N/A | N/A | N/A | +| go_memstats_heap_alloc_bytes | N/A | N/A | N/A | +| go_memstats_heap_idle_bytes | N/A | N/A | N/A | +| go_memstats_heap_inuse_bytes | N/A | N/A | N/A | +| go_memstats_heap_objects | N/A | N/A | N/A | +| go_memstats_heap_released_bytes | N/A | N/A | N/A | +| go_memstats_heap_sys_bytes | N/A | N/A | N/A | +| go_memstats_last_gc_time_seconds | N/A | N/A | N/A | +| go_memstats_lookups_total | N/A | N/A | N/A | +| go_memstats_mallocs_total | N/A | N/A | N/A | +| go_memstats_mcache_inuse_bytes | N/A | N/A | N/A | +| go_memstats_mcache_sys_bytes | N/A | N/A | N/A | +| go_memstats_mspan_inuse_bytes | N/A | N/A | N/A | +| go_memstats_mspan_sys_bytes | N/A | N/A | N/A | +| go_memstats_next_gc_bytes | N/A | N/A | N/A | +| go_memstats_other_sys_bytes | N/A | N/A | N/A | +| go_memstats_stack_inuse_bytes | N/A | N/A | N/A | +| go_memstats_stack_sys_bytes | N/A | N/A | N/A | +| go_memstats_sys_bytes | N/A | N/A | N/A | +| go_threads | N/A | N/A | N/A | +| jaeger_build_info | build_date, revision, version | N/A | N/A | +| jaeger_collector_batch_size | host | N/A | N/A | +| jaeger_collector_http_request_duration | method, path, status | N/A | N/A | +| jaeger_collector_http_server_errors_total | source, status | N/A | N/A | +| jaeger_collector_http_server_requests_total | type | N/A | N/A | +| jaeger_collector_in_queue_latency | host | N/A | N/A | +| jaeger_collector_queue_capacity | host | N/A | N/A | +| jaeger_collector_queue_length | host | N/A | N/A | +| jaeger_collector_save_latency | host | N/A | N/A | +| jaeger_collector_spans_bytes | host | N/A | N/A | +| jaeger_collector_spans_dropped_total | host | N/A | N/A | +| jaeger_collector_spans_received_total | debug, format, svc, transport | N/A | N/A | +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | N/A | N/A | +| jaeger_collector_spans_saved_by_svc_total | debug, result, svc | N/A | N/A | +| jaeger_collector_spans_serviceNames | host | N/A | N/A | +| jaeger_collector_traces_received_total | debug, format, sampler_type, svc, transport | N/A | N/A | +| jaeger_collector_traces_rejected_total | debug, format, sampler_type, svc, transport | N/A | N/A | +| jaeger_collector_traces_saved_by_svc_total | debug, result, sampler_type, svc | N/A | N/A | +| process_cpu_seconds_total | N/A | N/A | N/A | +| process_max_fds | N/A | N/A | N/A | +| process_open_fds | N/A | N/A | N/A | +| process_resident_memory_bytes | N/A | N/A | N/A | +| process_start_time_seconds | N/A | N/A | N/A | +| process_virtual_memory_bytes | N/A | N/A | N/A | +| process_virtual_memory_max_bytes | N/A | N/A | N/A | +| N/A | N/A | exporter_send_failed_spans | exporter, service_instance_id, service_name, service_version | +| N/A | N/A | exporter_sent_spans | exporter, service_instance_id, service_name, service_version | +| N/A | N/A | process_cpu_seconds | service_instance_id, service_name, service_version | +| N/A | N/A | process_memory_rss | service_instance_id, service_name, service_version | +| N/A | N/A | process_runtime_heap_alloc_bytes | service_instance_id, service_name, service_version | +| N/A | N/A | process_runtime_total_alloc_bytes | service_instance_id, service_name, service_version | +| N/A | N/A | process_runtime_total_sys_memory_bytes | service_instance_id, service_name, service_version | +| N/A | N/A | process_uptime | service_instance_id, service_name, service_version | +| N/A | N/A | processor_batch_batch_send_size | processor, service_instance_id, service_name, service_version | +| N/A | N/A | processor_batch_batch_send_size_bytes | processor, service_instance_id, service_name, service_version | +| N/A | N/A | processor_batch_metadata_cardinality | processor, service_instance_id, service_name, service_version | +| N/A | N/A | processor_batch_timeout_trigger_send | processor, service_instance_id, service_name, service_version | +| N/A | N/A | receiver_accepted_spans | receiver, service_instance_id, service_name, service_version, transport | +| N/A | N/A | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| N/A | N/A | rpc_server_duration | rpc_grpc_status_code, rpc_method, rpc_service, rpc_system, service_instance_id, service_name, service_version | +| N/A | N/A | rpc_server_request_size | rpc_method, rpc_service, rpc_system, service_instance_id, service_name, service_version | +| N/A | N/A | rpc_server_requests_per_rpc | rpc_grpc_status_code, rpc_method, rpc_service, rpc_system, service_instance_id, service_name, service_version | +| N/A | N/A | rpc_server_response_size | rpc_method, rpc_service, rpc_system, service_instance_id, service_name, service_version | +| N/A | N/A | rpc_server_responses_per_rpc | rpc_grpc_status_code, rpc_method, rpc_service, rpc_system, service_instance_id, service_name, service_version | +| N/A | N/A | target_info | service_instance_id, service_name, service_version | +### Equivalent Metrics + +| V1 Metric | V1 Labels | V2 Metric | V2 Labels | +|-----------|---------------|-----------|---------------| +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| jaeger_build_info | build_date, revision, version | target_info | service_instance_id, service_name, service_version | diff --git a/cmd/jaeger/docs/migration/badger-metrics.md b/cmd/jaeger/docs/migration/badger-metrics.md new file mode 100644 index 000000000000..65656e44c6a4 --- /dev/null +++ b/cmd/jaeger/docs/migration/badger-metrics.md @@ -0,0 +1,33 @@ +# BADGER METRICS + +### Combined Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +| ------------------------------------------ | ------------- | ---------------------------------------- | ------------- | +| jaeger_badger_compaction_current_num_lsm | N/A | jaeger_badger_compaction_current_num_lsm | N/A | +| jaeger_badger_get_num_memtable | N/A | jaeger_badger_get_num_memtable | N/A | +| jaeger_badger_get_num_user | N/A | jaeger_badger_get_num_user | N/A | +| jaeger_badger_get_with_result_num_user | N/A | jaeger_badger_get_with_result_num_user | N/A | +| jaeger_badger_iterator_num_user | N/A | jaeger_badger_iterator_num_user | N/A | +| jaeger_badger_put_num_user | N/A | jaeger_badger_put_num_user | N/A | +| jaeger_badger_read_bytes_lsm | N/A | jaeger_badger_read_bytes_lsm | N/A | +| jaeger_badger_read_bytes_vlog | N/A | jaeger_badger_read_bytes_vlog | N/A | +| jaeger_badger_read_num_vlog | N/A | jaeger_badger_read_num_vlog | N/A | +| jaeger_badger_size_bytes_lsm | N/A | jaeger_badger_size_bytes_lsm | N/A | +| jaeger_badger_size_bytes_vlog | N/A | jaeger_badger_size_bytes_vlog | N/A | +| jaeger_badger_write_bytes_l0 | N/A | jaeger_badger_write_bytes_l0 | N/A | +| jaeger_badger_write_bytes_user | N/A | jaeger_badger_write_bytes_user | N/A | +| jaeger_badger_write_bytes_vlog | N/A | jaeger_badger_write_bytes_vlog | N/A | +| jaeger_badger_write_num_vlog | N/A | jaeger_badger_write_num_vlog | N/A | +| jaeger_badger_write_pending_num_memtable | N/A | jaeger_badger_write_pending_num_memtable | N/A | +| jaeger_badger_key_log_bytes_available | N/A | N/A | N/A | +| jaeger_badger_storage_maintenance_last_run | N/A | N/A | N/A | +| jaeger_badger_storage_valueloggc_last_run | N/A | N/A | N/A | +| jaeger_badger_value_log_bytes_available | N/A | N/A | N/A | + +### Equivalent Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +| ------------------------------------- | ------------------------------ | ---------------------- | ----------------------------------------------------------------------- | +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| jaeger_build_info | build_date, revision, version | target_info | service_instance_id, service_name, service_version | diff --git a/cmd/jaeger/docs/migration/cassandra-metrics.md b/cmd/jaeger/docs/migration/cassandra-metrics.md new file mode 100644 index 000000000000..95d453f7ca3d --- /dev/null +++ b/cmd/jaeger/docs/migration/cassandra-metrics.md @@ -0,0 +1,22 @@ +# CASSANDRA METRICS +### Combined Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_cassandra_attempts_total | table | jaeger_cassandra_attempts_total | table | +| jaeger_cassandra_errors_total | table | jaeger_cassandra_errors_total | table | +| jaeger_cassandra_inserts_total | table | jaeger_cassandra_inserts_total | table | +| jaeger_cassandra_latency_err | table | jaeger_cassandra_latency_err | table | +| jaeger_cassandra_latency_ok | table | jaeger_cassandra_latency_ok | table | +| jaeger_cassandra_read_attempts_total | table | jaeger_cassandra_read_attempts_total | table | +| jaeger_cassandra_read_errors_total | table | jaeger_cassandra_read_errors_total | table | +| jaeger_cassandra_read_inserts_total | table | jaeger_cassandra_read_inserts_total | table | +| jaeger_cassandra_read_latency_err | table | jaeger_cassandra_read_latency_err | table | +| jaeger_cassandra_read_latency_ok | table | jaeger_cassandra_read_latency_ok | table | +| jaeger_cassandra_tag_index_skipped_total | N/A | jaeger_cassandra_tag_index_skipped_total | N/A | +### Equivalent Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| jaeger_build_info | build_date, revision, version | target_info | service_instance_id, service_name, service_version | diff --git a/cmd/jaeger/docs/migration/elasticsearch-metrics.md b/cmd/jaeger/docs/migration/elasticsearch-metrics.md new file mode 100644 index 000000000000..9b5a0a0b6081 --- /dev/null +++ b/cmd/jaeger/docs/migration/elasticsearch-metrics.md @@ -0,0 +1,21 @@ +# ELASTICSEARCH METRICS +### Combined Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_bulk_index_attempts_total | N/A | jaeger_bulk_index_attempts_total | N/A | +| jaeger_bulk_index_errors_total | N/A | jaeger_bulk_index_errors_total | N/A | +| jaeger_bulk_index_inserts_total | N/A | jaeger_bulk_index_inserts_total | N/A | +| jaeger_bulk_index_latency_err | N/A | jaeger_bulk_index_latency_err | N/A | +| jaeger_bulk_index_latency_ok | N/A | jaeger_bulk_index_latency_ok | N/A | +| jaeger_index_create_attempts_total | N/A | jaeger_index_create_attempts_total | N/A | +| jaeger_index_create_errors_total | N/A | jaeger_index_create_errors_total | N/A | +| jaeger_index_create_inserts_total | N/A | jaeger_index_create_inserts_total | N/A | +| jaeger_index_create_latency_err | N/A | jaeger_index_create_latency_err | N/A | +| jaeger_index_create_latency_ok | N/A | jaeger_index_create_latency_ok | N/A | +### Equivalent Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| jaeger_build_info | build_date, revision, version | target_info | service_instance_id, service_name, service_version | diff --git a/cmd/jaeger/docs/migration/opensearch-metrics.md b/cmd/jaeger/docs/migration/opensearch-metrics.md new file mode 100644 index 000000000000..aa5052c270b6 --- /dev/null +++ b/cmd/jaeger/docs/migration/opensearch-metrics.md @@ -0,0 +1,21 @@ +# OPENSEARCH METRICS +### Combined Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_bulk_index_attempts_total | N/A | jaeger_bulk_index_attempts_total | N/A | +| jaeger_bulk_index_errors_total | N/A | jaeger_bulk_index_errors_total | N/A | +| jaeger_bulk_index_inserts_total | N/A | jaeger_bulk_index_inserts_total | N/A | +| jaeger_bulk_index_latency_err | N/A | jaeger_bulk_index_latency_err | N/A | +| jaeger_bulk_index_latency_ok | N/A | jaeger_bulk_index_latency_ok | N/A | +| jaeger_index_create_attempts_total | N/A | jaeger_index_create_attempts_total | N/A | +| jaeger_index_create_errors_total | N/A | jaeger_index_create_errors_total | N/A | +| jaeger_index_create_inserts_total | N/A | jaeger_index_create_inserts_total | N/A | +| jaeger_index_create_latency_err | N/A | jaeger_index_create_latency_err | N/A | +| jaeger_index_create_latency_ok | N/A | jaeger_index_create_latency_ok | N/A | +### Equivalent Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| jaeger_build_info | build_date, revision, version | target_info | service_instance_id, service_name, service_version | diff --git a/cmd/query/app/server_test.go b/cmd/query/app/server_test.go index 1baa793a367e..097f13171892 100644 --- a/cmd/query/app/server_test.go +++ b/cmd/query/app/server_test.go @@ -761,12 +761,12 @@ func TestServerHTTPTenancy(t *testing.T) { { name: "no tenant", // no value for tenant header - status: 401, + status: http.StatusUnauthorized, }, { name: "tenant", tenant: "acme", - status: 200, + status: http.StatusOK, }, } diff --git a/crossdock/main.go b/crossdock/main.go index f4833886a429..686f6ff515db 100644 --- a/crossdock/main.go +++ b/crossdock/main.go @@ -52,7 +52,7 @@ func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // when method is HEAD, report back with a 200 when ready to run tests - if r.Method == "HEAD" { + if r.Method == http.MethodHead { if !handler.isInitialized() { http.Error(w, "Components not ready", http.StatusServiceUnavailable) } @@ -92,7 +92,7 @@ func (h *clientHandler) isInitialized() bool { } func is2xxStatusCode(statusCode int) bool { - return statusCode >= 200 && statusCode <= 299 + return statusCode >= http.StatusOK && statusCode < http.StatusMultipleChoices } func httpHealthCheck(logger *zap.Logger, service, healthURL string) { diff --git a/examples/hotrod/pkg/tracing/http.go b/examples/hotrod/pkg/tracing/http.go index 0e938ba60b80..a37d7e70df2d 100644 --- a/examples/hotrod/pkg/tracing/http.go +++ b/examples/hotrod/pkg/tracing/http.go @@ -48,7 +48,7 @@ func (c *HTTPClient) GetJSON(ctx context.Context, _ string /* endpoint */, url s defer res.Body.Close() - if res.StatusCode >= 400 { + if res.StatusCode >= http.StatusBadRequest { body, err := io.ReadAll(res.Body) if err != nil { return err diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go b/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go index 48556e921700..5daa89f21dea 100644 --- a/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go +++ b/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go @@ -5,6 +5,7 @@ package rpcmetrics import ( + "net/http" "sync" "github.com/jaegertracing/jaeger/pkg/metrics" @@ -45,13 +46,13 @@ type Metrics struct { func (m *Metrics) recordHTTPStatusCode(statusCode int64) { switch { - case statusCode >= 200 && statusCode < 300: + case statusCode >= http.StatusOK && statusCode < http.StatusMultipleChoices: m.HTTPStatusCode2xx.Inc(1) - case statusCode >= 300 && statusCode < 400: + case statusCode >= http.StatusMultipleChoices && statusCode < http.StatusBadRequest: m.HTTPStatusCode3xx.Inc(1) - case statusCode >= 400 && statusCode < 500: + case statusCode >= http.StatusBadRequest && statusCode < http.StatusInternalServerError: m.HTTPStatusCode4xx.Inc(1) - case statusCode >= 500 && statusCode < 600: + case statusCode >= http.StatusInternalServerError && statusCode < 600: m.HTTPStatusCode5xx.Inc(1) } } diff --git a/idl b/idl index bb133107c5e4..de97430b579c 160000 --- a/idl +++ b/idl @@ -1 +1 @@ -Subproject commit bb133107c5e47ea943a475823c9d238ee487483a +Subproject commit de97430b579cac669422048a0becc5db981b05ad diff --git a/internal/tools/go.mod b/internal/tools/go.mod index 76cfbb14e054..230994c0c17f 100644 --- a/internal/tools/go.mod +++ b/internal/tools/go.mod @@ -3,7 +3,7 @@ module github.com/jaegertracing/jaeger/internal/tools go 1.23.0 require ( - github.com/golangci/golangci-lint v1.62.0 + github.com/golangci/golangci-lint v1.62.2 github.com/josephspurrier/goversioninfo v1.4.1 github.com/vektra/mockery/v2 v2.49.0 mvdan.cc/gofumpt v0.7.0 @@ -16,9 +16,9 @@ require ( github.com/Abirdcfly/dupword v0.1.3 // indirect github.com/Antonboom/errname v1.0.0 // indirect github.com/Antonboom/nilnil v1.0.0 // indirect - github.com/Antonboom/testifylint v1.5.0 // indirect + github.com/Antonboom/testifylint v1.5.2 // indirect github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect - github.com/Crocmagnon/fatcontext v0.5.2 // indirect + github.com/Crocmagnon/fatcontext v0.5.3 // indirect github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0 // indirect github.com/Masterminds/semver/v3 v3.3.0 // indirect @@ -113,18 +113,18 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/mgechev/revive v1.5.0 // indirect + github.com/mgechev/revive v1.5.1 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/moricho/tparallel v0.3.2 // indirect github.com/nakabonne/nestif v0.3.1 // indirect github.com/nishanths/exhaustive v0.12.0 // indirect github.com/nishanths/predeclared v0.2.2 // indirect - github.com/nunnatsa/ginkgolinter v0.18.0 // indirect + github.com/nunnatsa/ginkgolinter v0.18.3 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/polyfloyd/go-errorlint v1.6.0 // indirect + github.com/polyfloyd/go-errorlint v1.7.0 // indirect github.com/prometheus/client_golang v1.12.1 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect @@ -160,7 +160,7 @@ require ( github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect github.com/stretchr/objx v0.5.2 // indirect - github.com/stretchr/testify v1.9.0 // indirect + github.com/stretchr/testify v1.10.0 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/tdakkota/asciicheck v0.2.0 // indirect github.com/tetafro/godot v1.4.18 // indirect @@ -171,7 +171,7 @@ require ( github.com/ultraware/funlen v0.1.0 // indirect github.com/ultraware/whitespace v0.1.1 // indirect github.com/uudashr/gocognit v1.1.3 // indirect - github.com/uudashr/iface v1.2.0 // indirect + github.com/uudashr/iface v1.2.1 // indirect github.com/xen0n/gosmopolitan v1.2.2 // indirect github.com/yagipy/maintidx v1.0.0 // indirect github.com/yeya24/promlinter v0.3.0 // indirect @@ -184,7 +184,7 @@ require ( go.uber.org/multierr v1.8.0 // indirect go.uber.org/zap v1.24.0 // indirect golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect - golang.org/x/exp/typeparams v0.0.0-20240909161429-701f63a606c0 // indirect + golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f // indirect golang.org/x/mod v0.22.0 // indirect golang.org/x/sync v0.9.0 // indirect golang.org/x/sys v0.27.0 // indirect diff --git a/internal/tools/go.sum b/internal/tools/go.sum index 8961289417ae..c6b7df9a2591 100644 --- a/internal/tools/go.sum +++ b/internal/tools/go.sum @@ -43,14 +43,14 @@ github.com/Antonboom/errname v1.0.0 h1:oJOOWR07vS1kRusl6YRSlat7HFnb3mSfMl6sDMRoT github.com/Antonboom/errname v1.0.0/go.mod h1:gMOBFzK/vrTiXN9Oh+HFs+e6Ndl0eTFbtsRTSRdXyGI= github.com/Antonboom/nilnil v1.0.0 h1:n+v+B12dsE5tbAqRODXmEKfZv9j2KcTBrp+LkoM4HZk= github.com/Antonboom/nilnil v1.0.0/go.mod h1:fDJ1FSFoLN6yoG65ANb1WihItf6qt9PJVTn/s2IrcII= -github.com/Antonboom/testifylint v1.5.0 h1:dlUIsDMtCrZWUnvkaCz3quJCoIjaGi41GzjPBGkkJ8A= -github.com/Antonboom/testifylint v1.5.0/go.mod h1:wqaJbu0Blb5Wag2wv7Z5xt+CIV+eVLxtGZrlK13z3AE= +github.com/Antonboom/testifylint v1.5.2 h1:4s3Xhuv5AvdIgbd8wOOEeo0uZG7PbDKQyKY5lGoQazk= +github.com/Antonboom/testifylint v1.5.2/go.mod h1:vxy8VJ0bc6NavlYqjZfmp6EfqXMtBgQ4+mhCojwC1P8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs= github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Crocmagnon/fatcontext v0.5.2 h1:vhSEg8Gqng8awhPju2w7MKHqMlg4/NI+gSDHtR3xgwA= -github.com/Crocmagnon/fatcontext v0.5.2/go.mod h1:87XhRMaInHP44Q7Tlc7jkgKKB7kZAOPiDkFMdKCC+74= +github.com/Crocmagnon/fatcontext v0.5.3 h1:zCh/wjc9oyeF+Gmp+V60wetm8ph2tlsxocgg/J0hOps= +github.com/Crocmagnon/fatcontext v0.5.3/go.mod h1:XoCQYY1J+XTfyv74qLXvNw4xFunr3L1wkopIIKG7wGM= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rWPdisA5ynNEsoARbiCBOyGcJM4/OzsM= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0 h1:/fTUt5vmbkAcMBt4YQiuC23cV0kEsN1MVMNqeOW43cU= @@ -236,8 +236,8 @@ github.com/golangci/go-printf-func-name v0.1.0 h1:dVokQP+NMTO7jwO4bwsRwLWeudOVUP github.com/golangci/go-printf-func-name v0.1.0/go.mod h1:wqhWFH5mUdJQhweRnldEywnR5021wTdZSNgwYceV14s= github.com/golangci/gofmt v0.0.0-20240816233607-d8596aa466a9 h1:/1322Qns6BtQxUZDTAT4SdcoxknUki7IAoK4SAXr8ME= github.com/golangci/gofmt v0.0.0-20240816233607-d8596aa466a9/go.mod h1:Oesb/0uFAyWoaw1U1qS5zyjCg5NP9C9iwjnI4tIsXEE= -github.com/golangci/golangci-lint v1.62.0 h1:/G0g+bi1BhmGJqLdNQkKBWjcim8HjOPc4tsKuHDOhcI= -github.com/golangci/golangci-lint v1.62.0/go.mod h1:jtoOhQcKTz8B6dGNFyfQV3WZkQk+YvBDewDtNpiAJts= +github.com/golangci/golangci-lint v1.62.2 h1:b8K5K9PN+rZN1+mKLtsZHz2XXS9aYKzQ9i25x3Qnxxw= +github.com/golangci/golangci-lint v1.62.2/go.mod h1:ILWWyeFUrctpHVGMa1dg2xZPKoMUTc5OIMgW7HZr34g= github.com/golangci/misspell v0.6.0 h1:JCle2HUTNWirNlDIAUO44hUsKhOFqGPoC4LZxlaSXDs= github.com/golangci/misspell v0.6.0/go.mod h1:keMNyY6R9isGaSAu+4Q8NMBwMPkh15Gtc8UCVoDtAWo= github.com/golangci/modinfo v0.3.4 h1:oU5huX3fbxqQXdfspamej74DFX0kyGLkw1ppvXoJ8GA= @@ -385,8 +385,8 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mgechev/revive v1.5.0 h1:oaSmjA7rP8+HyoRuCgC531VHwnLH1AlJdjj+1AnQceQ= -github.com/mgechev/revive v1.5.0/go.mod h1:L6T3H8EoerRO86c7WuGpvohIUmiploGiyoYbtIWFmV8= +github.com/mgechev/revive v1.5.1 h1:hE+QPeq0/wIzJwOphdVyUJ82njdd8Khp4fUIHGZHW3M= +github.com/mgechev/revive v1.5.1/go.mod h1:lC9AhkJIBs5zwx8wkudyHrU+IJkrEKmpCmGMnIJPk4o= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -406,8 +406,8 @@ github.com/nishanths/exhaustive v0.12.0 h1:vIY9sALmw6T/yxiASewa4TQcFsVYZQQRUQJhK github.com/nishanths/exhaustive v0.12.0/go.mod h1:mEZ95wPIZW+x8kC4TgC+9YCUgiST7ecevsVDTgc2obs= github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm/w98Vk= github.com/nishanths/predeclared v0.2.2/go.mod h1:RROzoN6TnGQupbC+lqggsOlcgysk3LMK/HI84Mp280c= -github.com/nunnatsa/ginkgolinter v0.18.0 h1:ZXO1wKhPg3A6LpbN5dMuqwhfOjN5c3ous8YdKOuqk9k= -github.com/nunnatsa/ginkgolinter v0.18.0/go.mod h1:vPrWafSULmjMGCMsfGA908if95VnHQNAahvSBOjTuWs= +github.com/nunnatsa/ginkgolinter v0.18.3 h1:WgS7X3zzmni3vwHSBhvSgqrRgUecN6PQUcfB0j1noDw= +github.com/nunnatsa/ginkgolinter v0.18.3/go.mod h1:BE1xyB/PNtXXG1azrvrqJW5eFH0hSRylNzFy8QHPwzs= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4= @@ -429,8 +429,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polyfloyd/go-errorlint v1.6.0 h1:tftWV9DE7txiFzPpztTAwyoRLKNj9gpVm2cg8/OwcYY= -github.com/polyfloyd/go-errorlint v1.6.0/go.mod h1:HR7u8wuP1kb1NeN1zqTd1ZMlqUKPPHF+Id4vIPvDqVw= +github.com/polyfloyd/go-errorlint v1.7.0 h1:Zp6lzCK4hpBDj8y8a237YK4EPrMXQWvOe3nGoH4pFrU= +github.com/polyfloyd/go-errorlint v1.7.0/go.mod h1:dGWKu85mGHnegQ2SWpEybFityCg3j7ZbwsVUxAOk9gY= github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -539,8 +539,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/tdakkota/asciicheck v0.2.0 h1:o8jvnUANo0qXtnslk2d3nMKTFNlOnJjRrNcj0j9qkHM= @@ -565,8 +565,8 @@ github.com/ultraware/whitespace v0.1.1 h1:bTPOGejYFulW3PkcrqkeQwOd6NKOOXvmGD9bo/ github.com/ultraware/whitespace v0.1.1/go.mod h1:XcP1RLD81eV4BW8UhQlpaR+SDc2givTvyI8a586WjW8= github.com/uudashr/gocognit v1.1.3 h1:l+a111VcDbKfynh+airAy/DJQKaXh2m9vkoysMPSZyM= github.com/uudashr/gocognit v1.1.3/go.mod h1:aKH8/e8xbTRBwjbCkwZ8qt4l2EpKXl31KMHgSS+lZ2U= -github.com/uudashr/iface v1.2.0 h1:ECJjh5q/1Zmnv/2yFpWV6H3oMg5+Mo+vL0aqw9Gjazo= -github.com/uudashr/iface v1.2.0/go.mod h1:Ux/7d/rAF3owK4m53cTVXL4YoVHKNqnoOeQHn2xrlp0= +github.com/uudashr/iface v1.2.1 h1:vHHyzAUmWZ64Olq6NZT3vg/z1Ws56kyPdBOd5kTXDF8= +github.com/uudashr/iface v1.2.1/go.mod h1:4QvspiRd3JLPAEXBQ9AiZpLbJlrWWgRChOKDJEuQTdg= github.com/vektra/mockery/v2 v2.49.0 h1:KFJKqRa0zd4h+ntM+JFr9Z6fIz++CUgAAogPWnwTwJY= github.com/vektra/mockery/v2 v2.49.0/go.mod h1:xO2DeYemEPC2tCzIZ+a1tifZ/7Laf/Chxg3vlc+oDsI= github.com/xen0n/gosmopolitan v1.2.2 h1:/p2KTnMzwRexIW8GlKawsTWOxn7UHA+jCMF/V8HHtvU= @@ -630,8 +630,8 @@ golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWB golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY= golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= -golang.org/x/exp/typeparams v0.0.0-20240909161429-701f63a606c0 h1:bVwtbF629Xlyxk6xLQq2TDYmqP0uiWaet5LwRebuY0k= -golang.org/x/exp/typeparams v0.0.0-20240909161429-701f63a606c0/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= +golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f h1:WTyX8eCCyfdqiPYkRGm0MqElSfYFH3yR1+rl/mct9sA= +golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/model/adjuster/sort_tags_and_log_fields_test.go b/model/adjuster/sort_tags_and_log_fields_test.go index 4d31c7248b6f..afd1983cac0e 100644 --- a/model/adjuster/sort_tags_and_log_fields_test.go +++ b/model/adjuster/sort_tags_and_log_fields_test.go @@ -5,6 +5,7 @@ package adjuster import ( + "net/http" "testing" "github.com/stretchr/testify/assert" @@ -88,7 +89,7 @@ func TestSortTagsAndLogFieldsDoesSortFields(t *testing.T) { func TestSortTagsAndLogFieldsDoesSortTags(t *testing.T) { testCases := []model.KeyValues{ { - model.String("http.method", "GET"), + model.String("http.method", http.MethodGet), model.String("http.url", "http://wikipedia.org"), model.Int64("http.status_code", 200), model.String("guid:x-request-id", "f61defd2-7a77-11ef-b54f-4fbb67a6d181"), diff --git a/pkg/bearertoken/transport_test.go b/pkg/bearertoken/transport_test.go index b578934cb38f..e03ca8dd8a00 100644 --- a/pkg/bearertoken/transport_test.go +++ b/pkg/bearertoken/transport_test.go @@ -78,7 +78,7 @@ func TestRoundTripper(t *testing.T) { t.Run(tc.name, func(t *testing.T) { server := httptest.NewServer(nil) defer server.Close() - req, err := http.NewRequestWithContext(tc.requestContext, "GET", server.URL, nil) + req, err := http.NewRequestWithContext(tc.requestContext, http.MethodGet, server.URL, nil) require.NoError(t, err) tr := RoundTripper{ diff --git a/pkg/clientcfg/clientcfghttp/handler_test.go b/pkg/clientcfg/clientcfghttp/handler_test.go index 296468b458d3..fa16f52d71c6 100644 --- a/pkg/clientcfg/clientcfghttp/handler_test.go +++ b/pkg/clientcfg/clientcfghttp/handler_test.go @@ -283,14 +283,14 @@ func TestHTTPHandlerErrors(t *testing.T) { withServer("", probabilistic(0.001), restrictions("luggage", 10), withGorilla, func(ts *testServer) { handler := ts.handler - req := httptest.NewRequest("GET", "http://localhost:80/?service=X", nil) + req := httptest.NewRequest(http.MethodGet, "http://localhost:80/?service=X", nil) w := &mockWriter{header: make(http.Header)} handler.serveSamplingHTTP(w, req, handler.encodeThriftLegacy) ts.metricsFactory.AssertCounterMetrics(t, metricstest.ExpectedMetric{Name: "http-server.errors", Tags: map[string]string{"source": "write", "status": "5xx"}, Value: 1}) - req = httptest.NewRequest("GET", "http://localhost:80/baggageRestrictions?service=X", nil) + req = httptest.NewRequest(http.MethodGet, "http://localhost:80/baggageRestrictions?service=X", nil) handler.serveBaggageHTTP(w, req) ts.metricsFactory.AssertCounterMetrics(t, diff --git a/pkg/es/wrapper/wrapper.go b/pkg/es/wrapper/wrapper.go index cdca19fd7686..e34b8c495905 100644 --- a/pkg/es/wrapper/wrapper.go +++ b/pkg/es/wrapper/wrapper.go @@ -7,6 +7,7 @@ package eswrapper import ( "context" "fmt" + "net/http" "strings" esV8 "github.com/elastic/go-elasticsearch/v8" @@ -193,7 +194,7 @@ func (c TemplateCreatorWrapperV8) Do(context.Context) (*elastic.IndicesPutTempla if err != nil { return nil, fmt.Errorf("error creating index template %s: %w", c.templateName, err) } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("error creating index template %s: %s", c.templateName, resp) } return nil, nil // no response expected by span writer diff --git a/pkg/version/handler.go b/pkg/version/handler.go index bb094af94a9c..a92cd11ff3b8 100644 --- a/pkg/version/handler.go +++ b/pkg/version/handler.go @@ -18,7 +18,7 @@ func RegisterHandler(mu *http.ServeMux, logger *zap.Logger) { logger.Fatal("Could not get Jaeger version", zap.Error(err)) } mu.HandleFunc("/version", func(w http.ResponseWriter, _ *http.Request) { - w.WriteHeader(200) + w.WriteHeader(http.StatusOK) w.Write(jsonData) }) } diff --git a/plugin/sampling/strategyprovider/adaptive/aggregator_test.go b/plugin/sampling/strategyprovider/adaptive/aggregator_test.go index eec8ab768925..a2145f80c351 100644 --- a/plugin/sampling/strategyprovider/adaptive/aggregator_test.go +++ b/plugin/sampling/strategyprovider/adaptive/aggregator_test.go @@ -4,6 +4,7 @@ package adaptive import ( + "net/http" "testing" "time" @@ -37,12 +38,12 @@ func TestAggregator(t *testing.T) { a, err := NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage) require.NoError(t, err) - a.RecordThroughput("A", "GET", model.SamplerTypeProbabilistic, 0.001) - a.RecordThroughput("B", "POST", model.SamplerTypeProbabilistic, 0.001) - a.RecordThroughput("C", "GET", model.SamplerTypeProbabilistic, 0.001) - a.RecordThroughput("A", "POST", model.SamplerTypeProbabilistic, 0.001) - a.RecordThroughput("A", "GET", model.SamplerTypeProbabilistic, 0.001) - a.RecordThroughput("A", "GET", model.SamplerTypeLowerBound, 0.001) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("B", http.MethodPost, model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("C", http.MethodGet, model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("A", http.MethodPost, model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeLowerBound, 0.001) a.Start() defer a.Close() @@ -74,17 +75,17 @@ func TestIncrementThroughput(t *testing.T) { require.NoError(t, err) // 20 different probabilities for i := 0; i < 20; i++ { - a.RecordThroughput("A", "GET", model.SamplerTypeProbabilistic, 0.001*float64(i)) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeProbabilistic, 0.001*float64(i)) } - assert.Len(t, a.(*aggregator).currentThroughput["A"]["GET"].Probabilities, 10) + assert.Len(t, a.(*aggregator).currentThroughput["A"][http.MethodGet].Probabilities, 10) a, err = NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage) require.NoError(t, err) // 20 of the same probabilities for i := 0; i < 20; i++ { - a.RecordThroughput("A", "GET", model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeProbabilistic, 0.001) } - assert.Len(t, a.(*aggregator).currentThroughput["A"]["GET"].Probabilities, 1) + assert.Len(t, a.(*aggregator).currentThroughput["A"][http.MethodGet].Probabilities, 1) } func TestLowerboundThroughput(t *testing.T) { @@ -100,9 +101,9 @@ func TestLowerboundThroughput(t *testing.T) { a, err := NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage) require.NoError(t, err) - a.RecordThroughput("A", "GET", model.SamplerTypeLowerBound, 0.001) - assert.EqualValues(t, 0, a.(*aggregator).currentThroughput["A"]["GET"].Count) - assert.Empty(t, a.(*aggregator).currentThroughput["A"]["GET"].Probabilities["0.001000"]) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeLowerBound, 0.001) + assert.EqualValues(t, 0, a.(*aggregator).currentThroughput["A"][http.MethodGet].Count) + assert.Empty(t, a.(*aggregator).currentThroughput["A"][http.MethodGet].Probabilities["0.001000"]) } func TestRecordThroughput(t *testing.T) { @@ -132,7 +133,7 @@ func TestRecordThroughput(t *testing.T) { require.Empty(t, a.(*aggregator).currentThroughput) // Testing span with service name and operation but no probabilistic sampling tags - span.OperationName = "GET" + span.OperationName = http.MethodGet a.HandleRootSpan(span, logger) require.Empty(t, a.(*aggregator).currentThroughput) @@ -142,7 +143,7 @@ func TestRecordThroughput(t *testing.T) { model.String("sampler.param", "0.001"), } a.HandleRootSpan(span, logger) - assert.EqualValues(t, 1, a.(*aggregator).currentThroughput["A"]["GET"].Count) + assert.EqualValues(t, 1, a.(*aggregator).currentThroughput["A"][http.MethodGet].Count) } func TestRecordThroughputFunc(t *testing.T) { @@ -173,7 +174,7 @@ func TestRecordThroughputFunc(t *testing.T) { require.Empty(t, a.(*aggregator).currentThroughput) // Testing span with service name and operation but no probabilistic sampling tags - span.OperationName = "GET" + span.OperationName = http.MethodGet a.HandleRootSpan(span, logger) require.Empty(t, a.(*aggregator).currentThroughput) @@ -183,5 +184,5 @@ func TestRecordThroughputFunc(t *testing.T) { model.String("sampler.param", "0.001"), } a.HandleRootSpan(span, logger) - assert.EqualValues(t, 1, a.(*aggregator).currentThroughput["A"]["GET"].Count) + assert.EqualValues(t, 1, a.(*aggregator).currentThroughput["A"][http.MethodGet].Count) } diff --git a/plugin/sampling/strategyprovider/adaptive/post_aggregator_test.go b/plugin/sampling/strategyprovider/adaptive/post_aggregator_test.go index 6a0f71b1eb6e..fd0da089ac64 100644 --- a/plugin/sampling/strategyprovider/adaptive/post_aggregator_test.go +++ b/plugin/sampling/strategyprovider/adaptive/post_aggregator_test.go @@ -5,6 +5,7 @@ package adaptive import ( "errors" + "net/http" "testing" "time" @@ -24,10 +25,10 @@ import ( func testThroughputs() []*model.Throughput { return []*model.Throughput{ - {Service: "svcA", Operation: "GET", Count: 4, Probabilities: map[string]struct{}{"0.1": {}}}, - {Service: "svcA", Operation: "GET", Count: 4, Probabilities: map[string]struct{}{"0.2": {}}}, - {Service: "svcA", Operation: "PUT", Count: 5, Probabilities: map[string]struct{}{"0.1": {}}}, - {Service: "svcB", Operation: "GET", Count: 3, Probabilities: map[string]struct{}{"0.1": {}}}, + {Service: "svcA", Operation: http.MethodGet, Count: 4, Probabilities: map[string]struct{}{"0.1": {}}}, + {Service: "svcA", Operation: http.MethodGet, Count: 4, Probabilities: map[string]struct{}{"0.2": {}}}, + {Service: "svcA", Operation: http.MethodPut, Count: 5, Probabilities: map[string]struct{}{"0.1": {}}}, + {Service: "svcB", Operation: http.MethodGet, Count: 3, Probabilities: map[string]struct{}{"0.1": {}}}, } } @@ -36,12 +37,12 @@ func testThroughputBuckets() []*throughputBucket { { throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 45}, - "PUT": {Count: 60}, + http.MethodGet: {Count: 45}, + http.MethodPut: {Count: 60}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30}, - "PUT": {Count: 15}, + http.MethodGet: {Count: 30}, + http.MethodPut: {Count: 15}, }, }, interval: 60 * time.Second, @@ -49,10 +50,10 @@ func testThroughputBuckets() []*throughputBucket { { throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 30}, + http.MethodGet: {Count: 30}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 45}, + http.MethodGet: {Count: 45}, }, }, interval: 60 * time.Second, @@ -87,12 +88,12 @@ func TestAggregateThroughput(t *testing.T) { require.True(t, ok) require.Len(t, throughput, 2) - opThroughput, ok := throughput["GET"] + opThroughput, ok := throughput[http.MethodGet] require.True(t, ok) assert.Equal(t, int64(8), opThroughput.Count) assert.Equal(t, map[string]struct{}{"0.1": {}, "0.2": {}}, opThroughput.Probabilities) - opThroughput, ok = throughput["PUT"] + opThroughput, ok = throughput[http.MethodPut] require.True(t, ok) assert.Equal(t, int64(5), opThroughput.Count) assert.Equal(t, map[string]struct{}{"0.1": {}}, opThroughput.Probabilities) @@ -101,7 +102,7 @@ func TestAggregateThroughput(t *testing.T) { require.True(t, ok) require.Len(t, throughput, 1) - opThroughput, ok = throughput["GET"] + opThroughput, ok = throughput[http.MethodGet] require.True(t, ok) assert.Equal(t, int64(3), opThroughput.Count) assert.Equal(t, map[string]struct{}{"0.1": {}}, opThroughput.Probabilities) @@ -112,7 +113,7 @@ func TestInitializeThroughput(t *testing.T) { mockStorage.On("GetThroughput", time.Time{}.Add(time.Minute*19), time.Time{}.Add(time.Minute*20)). Return(testThroughputs(), nil) mockStorage.On("GetThroughput", time.Time{}.Add(time.Minute*18), time.Time{}.Add(time.Minute*19)). - Return([]*model.Throughput{{Service: "svcA", Operation: "GET", Count: 7}}, nil) + Return([]*model.Throughput{{Service: "svcA", Operation: http.MethodGet, Count: 7}}, nil) mockStorage.On("GetThroughput", time.Time{}.Add(time.Minute*17), time.Time{}.Add(time.Minute*18)). Return([]*model.Throughput{}, nil) p := &PostAggregator{storage: mockStorage, Options: Options{CalculationInterval: time.Minute, AggregationBuckets: 3}} @@ -154,22 +155,22 @@ func TestGenerateOperationQPS(t *testing.T) { require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.75, 0.5}, opQPS["GET"]) - assert.Equal(t, []float64{1.0}, opQPS["PUT"]) + assert.Equal(t, []float64{0.75, 0.5}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{1.0}, opQPS[http.MethodPut]) opQPS, ok = svcOpQPS["svcB"] require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.5, 0.75}, opQPS["GET"]) - assert.Equal(t, []float64{0.25}, opQPS["PUT"]) + assert.Equal(t, []float64{0.5, 0.75}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{0.25}, opQPS[http.MethodPut]) // Test using the previous QPS if the throughput is not provided p.prependThroughputBucket( &throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 30}, + http.MethodGet: {Count: 30}, }, }, interval: 60 * time.Second, @@ -182,15 +183,15 @@ func TestGenerateOperationQPS(t *testing.T) { require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.5, 0.75, 0.5}, opQPS["GET"]) - assert.Equal(t, []float64{1.0}, opQPS["PUT"]) + assert.Equal(t, []float64{0.5, 0.75, 0.5}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{1.0}, opQPS[http.MethodPut]) opQPS, ok = svcOpQPS["svcB"] require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.5, 0.75}, opQPS["GET"]) - assert.Equal(t, []float64{0.25}, opQPS["PUT"]) + assert.Equal(t, []float64{0.5, 0.75}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{0.25}, opQPS[http.MethodPut]) } func TestGenerateOperationQPS_UseMostRecentBucketOnly(t *testing.T) { @@ -202,14 +203,14 @@ func TestGenerateOperationQPS_UseMostRecentBucketOnly(t *testing.T) { require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.75}, opQPS["GET"]) - assert.Equal(t, []float64{1.0}, opQPS["PUT"]) + assert.Equal(t, []float64{0.75}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{1.0}, opQPS[http.MethodPut]) p.prependThroughputBucket( &throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 30}, + http.MethodGet: {Count: 30}, }, }, interval: 60 * time.Second, @@ -223,8 +224,8 @@ func TestGenerateOperationQPS_UseMostRecentBucketOnly(t *testing.T) { require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.5}, opQPS["GET"]) - assert.Equal(t, []float64{1.0}, opQPS["PUT"]) + assert.Equal(t, []float64{0.5}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{1.0}, opQPS[http.MethodPut]) } func TestCalculateWeightedQPS(t *testing.T) { @@ -239,14 +240,14 @@ func TestCalculateProbability(t *testing.T) { { throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Probabilities: map[string]struct{}{"0.500000": {}}}, + http.MethodGet: {Probabilities: map[string]struct{}{"0.500000": {}}}, }, }, }, } probabilities := model.ServiceOperationProbabilities{ "svcA": map[string]float64{ - "GET": 0.5, + http.MethodGet: 0.5, }, } cfg := Options{ @@ -269,12 +270,12 @@ func TestCalculateProbability(t *testing.T) { expectedProbability float64 errMsg string }{ - {"svcA", "GET", 2.0, 0.25, "modify existing probability"}, - {"svcA", "PUT", 2.0, 0.0005, "modify default probability"}, - {"svcB", "GET", 0.9, 0.001, "qps within equivalence threshold"}, - {"svcB", "PUT", 0.000001, 1.0, "test max probability"}, - {"svcB", "DELETE", 1000000000, 0.00001, "test min probability"}, - {"svcB", "DELETE", 0.0, 0.002, "test 0 qps"}, + {"svcA", http.MethodGet, 2.0, 0.25, "modify existing probability"}, + {"svcA", http.MethodPut, 2.0, 0.0005, "modify default probability"}, + {"svcB", http.MethodGet, 0.9, 0.001, "qps within equivalence threshold"}, + {"svcB", http.MethodPut, 0.000001, 1.0, "test max probability"}, + {"svcB", http.MethodDelete, 1000000000, 0.00001, "test min probability"}, + {"svcB", http.MethodDelete, 0.0, 0.002, "test 0 qps"}, } for _, test := range tests { probability := p.calculateProbability(test.service, test.operation, test.qps) @@ -285,13 +286,13 @@ func TestCalculateProbability(t *testing.T) { func TestCalculateProbabilitiesAndQPS(t *testing.T) { prevProbabilities := model.ServiceOperationProbabilities{ "svcB": map[string]float64{ - "GET": 0.16, - "PUT": 0.03, + http.MethodGet: 0.16, + http.MethodPut: 0.03, }, } qps := model.ServiceOperationQPS{ "svcB": map[string]float64{ - "GET": 0.625, + http.MethodGet: 0.625, }, } mets := metricstest.NewFactory(0) @@ -309,12 +310,12 @@ func TestCalculateProbabilitiesAndQPS(t *testing.T) { probabilities, qps := p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.00136, "PUT": 0.001}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"GET": 0.16, "PUT": 0.03}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.00136, http.MethodPut: 0.001}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.16, http.MethodPut: 0.03}, probabilities["svcB"]) require.Len(t, qps, 2) - assert.Equal(t, map[string]float64{"GET": 0.7352941176470588, "PUT": 1}, qps["svcA"]) - assert.Equal(t, map[string]float64{"GET": 0.5147058823529411, "PUT": 0.25}, qps["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.7352941176470588, http.MethodPut: 1}, qps["svcA"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.5147058823529411, http.MethodPut: 0.25}, qps["svcB"]) _, gauges := mets.Backend.Snapshot() assert.EqualValues(t, 4, gauges["test"]) @@ -477,11 +478,11 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { { throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 3, Probabilities: map[string]struct{}{"0.001000": {}}}, - "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 3, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "PUT": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -506,8 +507,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps := p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.002, "PUT": 0.001}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.002, http.MethodPut: 0.001}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -518,11 +519,11 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, - "PUT": {Count: 0, Probabilities: map[string]struct{}{"0.002000": {}}}, + http.MethodGet: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 0, Probabilities: map[string]struct{}{"0.002000": {}}}, }, }, interval: 60 * time.Second, @@ -531,8 +532,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.002, "PUT": 0.001}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.004, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.002, http.MethodPut: 0.001}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.004, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -543,11 +544,11 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 0, Probabilities: map[string]struct{}{"0.002000": {}}}, - "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 0, Probabilities: map[string]struct{}{"0.002000": {}}}, + http.MethodPut: {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -556,8 +557,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.004, "PUT": 0.001}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.008, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.004, http.MethodPut: 0.001}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.008, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -567,12 +568,12 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 1, Probabilities: map[string]struct{}{"0.004000": {}}}, - "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 1, Probabilities: map[string]struct{}{"0.004000": {}}}, + http.MethodPut: {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, - "PUT": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -581,8 +582,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.008, "PUT": 0.001}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.008, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.008, http.MethodPut: 0.001}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.008, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -591,11 +592,11 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, - "PUT": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -604,8 +605,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.016, "PUT": 0.001468867216804201}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.008, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.016, http.MethodPut: 0.001468867216804201}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.008, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -615,11 +616,11 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, - "PUT": {Count: 1, Probabilities: map[string]struct{}{"0.008000": {}}}, + http.MethodGet: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 1, Probabilities: map[string]struct{}{"0.008000": {}}}, }, }, interval: 60 * time.Second, @@ -628,8 +629,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.032, "PUT": 0.001468867216804201}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.016, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.032, http.MethodPut: 0.001468867216804201}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.016, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -639,10 +640,10 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -651,8 +652,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.064, "PUT": 0.001468867216804201}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.032, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.064, http.MethodPut: 0.001468867216804201}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.032, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -662,10 +663,10 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 20, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 20, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 10, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 10, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -674,8 +675,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.128, "PUT": 0.001468867216804201}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.064, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.128, http.MethodPut: 0.001468867216804201}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.064, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -685,12 +686,12 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 20, Probabilities: map[string]struct{}{"0.001000": {}}}, - "GET": {Count: 120, Probabilities: map[string]struct{}{"0.128000": {}}}, + http.MethodPut: {Count: 20, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 120, Probabilities: map[string]struct{}{"0.128000": {}}}, }, "svcB": map[string]*model.Throughput{ - "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.064000": {}}}, - "GET": {Count: 10, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 60, Probabilities: map[string]struct{}{"0.064000": {}}}, + http.MethodGet: {Count: 10, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -699,8 +700,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.0882586677054928, "PUT": 0.001468867216804201}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.09587513707888091, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.0882586677054928, http.MethodPut: 0.001468867216804201}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.09587513707888091, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps diff --git a/plugin/sampling/strategyprovider/adaptive/provider_test.go b/plugin/sampling/strategyprovider/adaptive/provider_test.go index 8a26d8fc34df..1342cd21790d 100644 --- a/plugin/sampling/strategyprovider/adaptive/provider_test.go +++ b/plugin/sampling/strategyprovider/adaptive/provider_test.go @@ -5,6 +5,7 @@ package adaptive import ( "context" + "net/http" "testing" "time" @@ -68,10 +69,10 @@ func TestProviderRealisticRunCalculationLoop(t *testing.T) { logger := zap.NewNop() // NB: This is an extremely long test since it uses near realistic (1/6th scale) processor config values testThroughputs := []*model.Throughput{ - {Service: "svcA", Operation: "GET", Count: 10}, - {Service: "svcA", Operation: "POST", Count: 9}, - {Service: "svcA", Operation: "PUT", Count: 5}, - {Service: "svcA", Operation: "DELETE", Count: 20}, + {Service: "svcA", Operation: http.MethodGet, Count: 10}, + {Service: "svcA", Operation: http.MethodPost, Count: 9}, + {Service: "svcA", Operation: http.MethodPut, Count: 5}, + {Service: "svcA", Operation: http.MethodDelete, Count: 20}, } mockStorage := &smocks.Store{} mockStorage.On("GetThroughput", mock.AnythingOfType("time.Time"), mock.AnythingOfType("time.Time")). @@ -110,16 +111,16 @@ func TestProviderRealisticRunCalculationLoop(t *testing.T) { for _, s := range strategies { switch s.Operation { - case "GET": + case http.MethodGet: assert.InDelta(t, 0.001, s.ProbabilisticSampling.SamplingRate, 1e-4, "Already at 1QPS, no probability change") - case "POST": + case http.MethodPost: assert.InDelta(t, 0.001, s.ProbabilisticSampling.SamplingRate, 1e-4, "Within epsilon of 1QPS, no probability change") - case "PUT": + case http.MethodPut: assert.InEpsilon(t, 0.002, s.ProbabilisticSampling.SamplingRate, 0.025, "Under sampled, double probability") - case "DELETE": + case http.MethodDelete: assert.InEpsilon(t, 0.0005, s.ProbabilisticSampling.SamplingRate, 0.025, "Over sampled, halve probability") } @@ -129,7 +130,7 @@ func TestProviderRealisticRunCalculationLoop(t *testing.T) { func TestProviderGenerateStrategyResponses(t *testing.T) { probabilities := model.ServiceOperationProbabilities{ "svcA": map[string]float64{ - "GET": 0.5, + http.MethodGet: 0.5, }, } p := &Provider{ @@ -149,7 +150,7 @@ func TestProviderGenerateStrategyResponses(t *testing.T) { DefaultLowerBoundTracesPerSecond: 0.0001, PerOperationStrategies: []*api_v2.OperationSamplingStrategy{ { - Operation: "GET", + Operation: http.MethodGet, ProbabilisticSampling: &api_v2.ProbabilisticSamplingStrategy{ SamplingRate: 0.5, }, diff --git a/plugin/sampling/strategyprovider/static/provider.go b/plugin/sampling/strategyprovider/static/provider.go index 56890ed63c0e..8c801de8f797 100644 --- a/plugin/sampling/strategyprovider/static/provider.go +++ b/plugin/sampling/strategyprovider/static/provider.go @@ -104,7 +104,7 @@ func (h *samplingProvider) downloadSamplingStrategies(samplingURL string) ([]byt ctx, cx := context.WithTimeout(context.Background(), time.Second) defer cx() - req, err := http.NewRequestWithContext(ctx, "GET", samplingURL, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, samplingURL, nil) if err != nil { return nil, fmt.Errorf("cannot construct HTTP request: %w", err) } diff --git a/plugin/sampling/strategyprovider/static/provider_test.go b/plugin/sampling/strategyprovider/static/provider_test.go index ba7992f18f8c..783caeb5c546 100644 --- a/plugin/sampling/strategyprovider/static/provider_test.go +++ b/plugin/sampling/strategyprovider/static/provider_test.go @@ -73,15 +73,15 @@ func mockStrategyServer(t *testing.T) (*httptest.Server, *atomic.Pointer[string] return case "/bad-status": - w.WriteHeader(404) + w.WriteHeader(http.StatusNotFound) return case "/service-unavailable": - w.WriteHeader(503) + w.WriteHeader(http.StatusServiceUnavailable) return default: - w.WriteHeader(200) + w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") w.Write([]byte(*strategy.Load())) } diff --git a/plugin/storage/cassandra/samplingstore/storage_test.go b/plugin/storage/cassandra/samplingstore/storage_test.go index 238d9723f56c..774ffeb54227 100644 --- a/plugin/storage/cassandra/samplingstore/storage_test.go +++ b/plugin/storage/cassandra/samplingstore/storage_test.go @@ -6,6 +6,7 @@ package samplingstore import ( "errors" + "net/http" "testing" "time" @@ -329,12 +330,12 @@ func TestStringToThroughput(t *testing.T) { func TestProbabilitiesAndQPSToString(t *testing.T) { probabilities := model.ServiceOperationProbabilities{ "svc,1": map[string]float64{ - "GET": 0.001, + http.MethodGet: 0.001, }, } qps := model.ServiceOperationQPS{ "svc,1": map[string]float64{ - "GET": 62.3, + http.MethodGet: 62.3, }, } str := probabilitiesAndQPSToString(probabilities, qps) @@ -348,17 +349,17 @@ func TestStringToProbabilitiesAndQPS(t *testing.T) { assert.Len(t, probabilities, 2) assert.Equal(t, map[string]*model.ProbabilityAndQPS{ - "GET": { + http.MethodGet: { Probability: 0.001, QPS: 63.2, }, - "PUT": { + http.MethodPut: { Probability: 0.002, QPS: 0.0, }, }, probabilities["svc1"]) assert.Equal(t, map[string]*model.ProbabilityAndQPS{ - "GET": { + http.MethodGet: { Probability: 0.5, QPS: 34.2, }, @@ -371,8 +372,8 @@ func TestStringToProbabilities(t *testing.T) { probabilities := s.stringToProbabilities(testStr) assert.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.001, "PUT": 0.002}, probabilities["svc1"]) - assert.Equal(t, map[string]float64{"GET": 0.5}, probabilities["svc2"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.001, http.MethodPut: 0.002}, probabilities["svc1"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.5}, probabilities["svc2"]) } func TestProbabilitiesSetToString(t *testing.T) { diff --git a/plugin/storage/es/options_test.go b/plugin/storage/es/options_test.go index 33d933b5830b..87b2ce11d7f8 100644 --- a/plugin/storage/es/options_test.go +++ b/plugin/storage/es/options_test.go @@ -5,6 +5,7 @@ package es import ( + "net/http" "testing" "time" @@ -117,7 +118,7 @@ func TestOptionsWithFlags(t *testing.T) { assert.Equal(t, "2006.01.02", aux.Indices.Services.DateLayout) assert.Equal(t, "2006.01.02.15", aux.Indices.Spans.DateLayout) assert.True(t, primary.UseILM) - assert.Equal(t, "POST", aux.SendGetBodyAs) + assert.Equal(t, http.MethodPost, aux.SendGetBodyAs) } func TestEmptyRemoteReadClusters(t *testing.T) { diff --git a/scripts/compare_metrics.py b/scripts/compare_metrics.py deleted file mode 100755 index 36fe190d5929..000000000000 --- a/scripts/compare_metrics.py +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright (c) 2024 The Jaeger Authors. -# SPDX-License-Identifier: Apache-2.0 - -import json - -v1_metrics_path = "./V1_Metrics.json" -v2_metrics_path = "./V2_Metrics.json" - -with open(v1_metrics_path, 'r') as file: - v1_metrics = json.load(file) - -with open(v2_metrics_path, 'r') as file: - v2_metrics = json.load(file) - -# Extract names and labels of the metrics -def extract_metrics_with_labels(metrics, strip_prefix=None): - result = {} - for metric in metrics: - name = metric['name'] - if strip_prefix and name.startswith(strip_prefix): - name = name[len(strip_prefix):] - labels = {} - if 'metrics' in metric and 'labels' in metric['metrics'][0]: - labels = metric['metrics'][0]['labels'] - result[name] = labels - return result - - -v1_metrics_with_labels = extract_metrics_with_labels(v1_metrics) -v2_metrics_with_labels = extract_metrics_with_labels( - v2_metrics, strip_prefix="otelcol_") - -# Compare the metrics names and labels -common_metrics = {} -v1_only_metrics = {} -v2_only_metrics = {} - -for name, labels in v1_metrics_with_labels.items(): - if name in v2_metrics_with_labels: - common_metrics[name] = labels - elif not name.startswith("jaeger_agent"): - v1_only_metrics[name] = labels - -for name, labels in v2_metrics_with_labels.items(): - if name not in v1_metrics_with_labels: - v2_only_metrics[name] = labels - -differences = { - "common_metrics": common_metrics, - "v1_only_metrics": v1_only_metrics, - "v2_only_metrics": v2_only_metrics -} - -# Write the differences to a new JSON file -differences_path = "./differences.json" -with open(differences_path, 'w') as file: - json.dump(differences, file, indent=4) - -print(f"Differences written to {differences_path}") diff --git a/scripts/utils/compare_metrics.py b/scripts/utils/compare_metrics.py new file mode 100755 index 000000000000..390f2b7d4707 --- /dev/null +++ b/scripts/utils/compare_metrics.py @@ -0,0 +1,130 @@ +# Copyright (c) 2024 The Jaeger Authors. +# SPDX-License-Identifier: Apache-2.0 + +import json +import argparse +import subprocess + +#Instructions of use: + +# To generate V1_Metrics.json and V2_Metrics.json, run the following commands: +# i.e for elastic search first run the following command: +# docker compose -f docker-compose/elasticsearch/v7/docker-compose.yml up +# 1. Generate V1_Metrics.json and V2_Metrics.json by the following commands: +# V1 binary cmd: SPAN_STORAGE_TYPE=elasticsearch go run -tags=ui ./cmd/all-in-one +# extract the metrics by running the following command: +# prom2json http://localhost:14269/metrics > V1_Metrics.json +# Stop the v1 binary and for v2 binary run the following command: +# go run -tags ui ./cmd/jaeger/main.go --config ./cmd/jaeger/config-elasticsearch.yaml +# extract the metrics by running the following command: +# prom2json http://localhost:8888/metrics > V2_Metrics.json +# it is first recomended to generate the differences for all-in-one.json by running the following command: +# python3 compare_metrics.py --out md --is_storage F +# rename that file to all_in_one.json and use it to filter out the overlapping metrics by using the is_storage falg to T +# 2. Run the script with the following command: +# python3 compare_metrics.py --out {json or md} --is_storage {T or F} +# 3. The script will compare the metrics in V1_Metrics.json and V2_Metrics.json and output the differences to differences.json + + +# Extract names and labels of the metrics +def extract_metrics_with_labels(metrics, strip_prefix=None): + result = {} + for metric in metrics: + + name = metric['name'] + print(name) + if strip_prefix and name.startswith(strip_prefix): + name = name[len(strip_prefix):] + labels = {} + if 'metrics' in metric and 'labels' in metric['metrics'][0]: + labels = metric['metrics'][0]['labels'] + result[name] = labels + return result + +def remove_overlapping_metrics(all_in_one_data, other_json_data): + """Remove overlapping metrics found in all_in-one.json from another JSON.""" + # Loop through v1 and v2 metrics to remove overlaps + for metric_category in ['common_metrics', 'v1_only_metrics', 'v2_only_metrics']: + if metric_category in all_in_one_data and metric_category in other_json_data: + for metric in all_in_one_data[metric_category]: + if metric in other_json_data[metric_category]: + del other_json_data[metric_category][metric] + + return other_json_data + + +# Your current compare_metrics.py logic goes here +def main(): + parser = argparse.ArgumentParser(description='Compare metrics and output format.') + parser.add_argument('--out', choices=['json', 'md'], default='json', + help='Output format: json (default) or md') + parser.add_argument('--is_storage', choices=['T','F'],default='F', help='Remove overlapping storage metrics') + # Parse the arguments + args = parser.parse_args() + + # Call your existing compare logic here + print("Running metric comparison...") + v1_metrics_path = "" #Add the path to the V1_Metrics.json file + v2_metrics_path = "" #Add the path to the V2_Metrics.json file + + with open(v1_metrics_path, 'r') as file: + v1_metrics = json.load(file) + + with open(v2_metrics_path, 'r') as file: + v2_metrics = json.load(file) + + v1_metrics_with_labels = extract_metrics_with_labels(v1_metrics) + v2_metrics_with_labels = extract_metrics_with_labels( + v2_metrics, strip_prefix="otelcol_") + + # Compare the metrics names and labels + common_metrics = {} + v1_only_metrics = {} + v2_only_metrics = {} + + for name, labels in v1_metrics_with_labels.items(): + if name in v2_metrics_with_labels: + common_metrics[name] = labels + elif not name.startswith("jaeger_agent"): + v1_only_metrics[name] = labels + + for name, labels in v2_metrics_with_labels.items(): + if name not in v1_metrics_with_labels: + v2_only_metrics[name] = labels + + differences = { + "common_metrics": common_metrics, + "v1_only_metrics": v1_only_metrics, + "v2_only_metrics": v2_only_metrics, + } + + #Write the differences to a new JSON file + differences_path = "./differences.json" + with open(differences_path, 'w') as file: + json.dump(differences, file, indent=4) + + print(f"Differences written to {differences_path}") + if args.is_storage == 'T': + all_in_one_path = "" #Add the path to the all_in_one.json file + with open(all_in_one_path, 'r') as file: + all_in_one_data = json.load(file) + with open(differences_path, 'r') as file: + other_json_data = json.load(file) + other_json_data = remove_overlapping_metrics(all_in_one_data, other_json_data) + with open(differences_path, 'w') as file: + json.dump(other_json_data, file, indent=4) + print(f"Overlapping storage metrics removed from {differences_path}") + # If the user requested markdown output, run metrics_md.py + if args.out == 'md': + try: + print("Running metrics_md.py to generate markdown output...") + subprocess.run(['python3', 'metrics-md.py'], check=True) + except subprocess.CalledProcessError as e: + print(f"Error running metrics_md.py: {e}") + + # If json output is requested or no output type is provided (default is json) + else: + print("Output in JSON format.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts/utils/metrics-md.py b/scripts/utils/metrics-md.py new file mode 100644 index 000000000000..2b158697257f --- /dev/null +++ b/scripts/utils/metrics-md.py @@ -0,0 +1,117 @@ +# Copyright (c) 2024 The Jaeger Authors. +# SPDX-License-Identifier: Apache-2.0 + +import json + + +def generate_spans_markdown_table(v1_spans, v2_spans): + """ + Generates a markdown table specifically for spans metrics with two main columns V1 and V2. + + Args: + v1_spans (dict): The dictionary of V1 spans metrics. + v2_spans (dict): The dictionary of V2 spans metrics. + + Returns: + str: The generated markdown table as a string. + """ + table = "### Equivalent Metrics\n\n" + table += "| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters |\n" + table += "|-----------|---------------|-----------|---------------|\n" + + + # Iterate through the metrics using zip_longest to handle mismatched lengths + from itertools import zip_longest + + for (v1_metric, v1_params), (v2_metric, v2_params) in zip_longest(v1_spans.items(), v2_spans.items(), fillvalue=('', {})): + v1_inner_keys = ', '.join(v1_params.keys()) if v1_params else '' + v2_inner_keys = ', '.join(v2_params.keys()) if v2_params else '' + table += f"| {v1_metric} | {v1_inner_keys} | {v2_metric} | {v2_inner_keys} |\n" + + return table + + + +def generate_combined_markdown_table(common_metrics, v1_metrics, v2_metrics): + """ + Generates a markdown table for combined metrics from common, V1, and V2. + + Args: + common_metrics (dict): The dictionary of common metrics. + v1_metrics (dict): The dictionary of V1 only metrics. + v2_metrics (dict): The dictionary of V2 only metrics. + + Returns: + str: The generated markdown table as a string. + """ + table = "### Combined Metrics\n\n" + table += "| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters |\n" + table += "|-----------|---------------|-----------|---------------|\n" + for metric_name, params in common_metrics.items(): + v1_params = ', '.join(common_metrics[metric_name].keys()) if params else 'N/A' + v2_params = ', '.join(common_metrics[metric_name].keys()) if params else 'N/A' + table += f"| {metric_name} | {v1_params} | {metric_name} | {v2_params} |\n" + + # Then, handle V1-only metrics (V2 shows as N/A) + for metric_name, v1_params in v1_metrics.items(): + v1_params_str = ', '.join(v1_params.keys()) if v1_params else 'N/A' + table += f"| {metric_name} | {v1_params_str} | N/A | N/A |\n" + + # Then, handle V2-only metrics (V1 shows as N/A) + for metric_name, v2_params in v2_metrics.items(): + v2_params_str = ', '.join(v2_params.keys()) if v2_params else 'N/A' + table += f"| N/A | N/A | {metric_name} | {v2_params_str} |\n" + + return table + +class ConvertJson: + + def __init__(self, json_fp, h1): + self.fp = json_fp + self.h1 = h1 + self.jdata = self.get_json() + self.mddata = self.format_json_to_md() + + def get_json(self): + with open(self.fp) as f: + res = json.load(f) + return res + + def format_json_to_md(self): + text = f'# {self.h1}\n' + dct = self.jdata + + # Extracting individual metric dictionaries + common_metrics = dct.get("common_metrics", {}) + v1_only_metrics = dct.get("v1_only_metrics", {}) + v2_only_metrics = dct.get("v2_only_metrics", {}) + + # Generate combined table + combined_metrics_table = generate_combined_markdown_table( + common_metrics, v1_only_metrics, v2_only_metrics + ) + + filtered_v1_metrics = { + "jaeger_collector_spans_rejected_total": {"debug": "false", "format": "","svc": "","transport":""}, + "jaeger_build_info": {"build_date": "","revision": ""," version": ""} # Add more metrics as needed + } + + # Hardcoding filtered v2 metrics + filtered_v2_metrics = { + "receiver_refused_spans": {"receiver": "","service_instance_id": "","service_name": "","service_version": "","transport": ""}, + "target_info": {"service_instance_id": "","service_name": "","service_version": ""} # Add more metrics as needed + } + spans_metrics_table = generate_spans_markdown_table(filtered_v1_metrics, filtered_v2_metrics) + text += combined_metrics_table+spans_metrics_table + return text + + def convert_dict_to_md(self, output_fn): + with open(output_fn, 'w') as writer: + writer.writelines(self.mddata) + print('Dict successfully converted to md') + +# Usage +fn = '' # Enter the path of the JSON file generated by compare_metrics.py +title = "TITLE" +converter = ConvertJson(fn, title) +converter.convert_dict_to_md(output_fn='metrics.md') \ No newline at end of file