Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maint: remove remaining references to obsolete fields #720

Merged
merged 6 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions collect/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package collect

import (
"errors"
"fmt"
"os"
"runtime"
"sort"
Expand Down Expand Up @@ -33,20 +32,7 @@ type Collector interface {
}

func GetCollectorImplementation(c config.Config) Collector {
var collector Collector
collectorType, err := c.GetCollectorType()
if err != nil {
fmt.Printf("unable to get collector type from config: %v\n", err)
os.Exit(1)
}
switch collectorType {
case "InMemCollector":
collector = &InMemCollector{}
default:
fmt.Printf("unknown collector type %s. Exiting.\n", collectorType)
os.Exit(1)
}
return collector
return &InMemCollector{}
}

// These are the names of the metrics we use to track our send decisions.
Expand Down Expand Up @@ -505,9 +491,8 @@ func (i *InMemCollector) dealWithSentTrace(keep bool, sampleRate uint, spanCount
}
isDryRun := i.Config.GetIsDryRun()
if isDryRun {
field := i.Config.GetDryRunFieldName()
// if dry run mode is enabled, we keep all traces and mark the spans with the sampling decision
sp.Data[field] = keep
sp.Data[config.DryRunFieldName] = keep
if !keep {
i.Logger.Debug().WithField("trace_id", sp.TraceID).Logf("Sending span that would have been dropped, but dry run mode is enabled")
i.addAdditionalAttributes(sp)
Expand Down Expand Up @@ -653,8 +638,7 @@ func (i *InMemCollector) send(trace *types.Trace, reason string) {

isDryRun := i.Config.GetIsDryRun()
if isDryRun {
field := i.Config.GetDryRunFieldName()
sp.Data[field] = shouldSend
sp.Data[config.DryRunFieldName] = shouldSend
}
if i.hostname != "" {
sp.Data["meta.refinery.local_hostname"] = i.hostname
Expand Down
21 changes: 9 additions & 12 deletions collect/collect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ func TestAddSpan(t *testing.T) {
func TestDryRunMode(t *testing.T) {
transmission := &transmit.MockTransmission{}
transmission.Start()
field := "test_kept"
conf := &config.MockConfig{
GetSendDelayVal: 0,
GetTraceTimeoutVal: 60 * time.Second,
Expand All @@ -340,7 +339,6 @@ func TestDryRunMode(t *testing.T) {
},
SendTickerVal: 20 * time.Millisecond,
DryRun: true,
DryRunFieldName: field,
ParentIdFieldNames: []string{"trace.parent_id", "parentId"},
}
samplerFactory := &sample.SamplerFactory{
Expand Down Expand Up @@ -400,7 +398,7 @@ func TestDryRunMode(t *testing.T) {
assert.Nil(t, coll.getFromCache(traceID1), "after sending the span, it should be removed from the cache")
transmission.Mux.RLock()
assert.Equal(t, 1, len(transmission.Events), "adding a root span should send the span")
assert.Equal(t, keepTraceID1, transmission.Events[0].Data[field], "field should match sampling decision for its trace ID")
assert.Equal(t, keepTraceID1, transmission.Events[0].Data[config.DryRunFieldName], "config.DryRunFieldName should match sampling decision for its trace ID")
transmission.Mux.RUnlock()

// add a non-root span, create the trace in the cache
Expand Down Expand Up @@ -431,8 +429,8 @@ func TestDryRunMode(t *testing.T) {
transmission.Mux.RLock()
assert.Equal(t, 3, len(transmission.Events), "adding another root span should send the span")
// both spans should be marked with the sampling decision
assert.Equal(t, keepTraceID2, transmission.Events[1].Data[field], "field should match sampling decision for its trace ID")
assert.Equal(t, keepTraceID2, transmission.Events[2].Data[field], "field should match sampling decision for its trace ID")
assert.Equal(t, keepTraceID2, transmission.Events[1].Data[config.DryRunFieldName], "config.DryRunFieldName should match sampling decision for its trace ID")
assert.Equal(t, keepTraceID2, transmission.Events[2].Data[config.DryRunFieldName], "config.DryRunFieldName should match sampling decision for its trace ID")
// check that meta value associated with dry run mode is properly applied
assert.Equal(t, uint(10), transmission.Events[1].Data["meta.dryrun.sample_rate"])
// check expected sampleRate against span data
Expand All @@ -456,7 +454,7 @@ func TestDryRunMode(t *testing.T) {
assert.Nil(t, coll.getFromCache(traceID3), "after sending the span, it should be removed from the cache")
transmission.Mux.RLock()
assert.Equal(t, 4, len(transmission.Events), "adding a root span should send the span")
assert.Equal(t, keepTraceID3, transmission.Events[3].Data[field], "field should match sampling decision for its trace ID")
assert.Equal(t, keepTraceID3, transmission.Events[3].Data[config.DryRunFieldName], "field should match sampling decision for its trace ID")
transmission.Mux.RUnlock()
}

Expand Down Expand Up @@ -633,12 +631,11 @@ func TestStableMaxAlloc(t *testing.T) {
transmission := &transmit.MockTransmission{}
transmission.Start()
conf := &config.MockConfig{
GetSendDelayVal: 0,
GetTraceTimeoutVal: 10 * time.Minute,
GetSamplerTypeVal: &config.DeterministicSamplerConfig{SampleRate: 1},
SendTickerVal: 2 * time.Millisecond,
CacheOverrunStrategy: "impact",
ParentIdFieldNames: []string{"trace.parent_id", "parentId"},
GetSendDelayVal: 0,
GetTraceTimeoutVal: 10 * time.Minute,
GetSamplerTypeVal: &config.DeterministicSamplerConfig{SampleRate: 1},
SendTickerVal: 2 * time.Millisecond,
ParentIdFieldNames: []string{"trace.parent_id", "parentId"},
}
coll := &InMemCollector{
Config: conf,
Expand Down
16 changes: 4 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"time"
)

const (
DryRunFieldName = "meta.refinery.dryrun.kept"
)

// Config defines the interface the rest of the code uses to get items from the
// config. There are different implementations of the config using different
// backends to store the config. FileConfig is the default and uses a
Expand Down Expand Up @@ -98,10 +102,6 @@ type Config interface {
// GetHoneycombLoggerConfig returns the config specific to the HoneycombLogger
GetHoneycombLoggerConfig() (HoneycombLoggerConfig, error)

// GetCollectorType returns the type of the collector to use. Valid types
// are in the collect package
GetCollectorType() (string, error)

// GetInMemCollectorCacheCapacity returns the config specific to the InMemCollector
GetInMemCollectorCacheCapacity() (CollectionConfig, error)

Expand All @@ -112,10 +112,6 @@ type Config interface {
// GetAllSamplerRules returns all rules in a single map, including the default rules
GetAllSamplerRules() (*V2SamplerConfig, error)

// GetMetricsType returns the type of metrics to use. Valid types are in the
// metrics package
GetMetricsType() (string, error)

// GetLegacyMetricsConfig returns the config specific to LegacyMetrics
GetLegacyMetricsConfig() LegacyMetricsConfig

Expand Down Expand Up @@ -147,8 +143,6 @@ type Config interface {

GetIsDryRun() bool

GetDryRunFieldName() string

GetAddHostMetadataToTrace() bool

GetAddRuleReasonToTrace() bool
Expand Down Expand Up @@ -176,8 +170,6 @@ type Config interface {

GetAddSpanCountToRoot() bool

GetCacheOverrunStrategy() string

GetConfigMetadata() []ConfigMetadata

GetSampleCacheConfig() SampleCacheConfig
Expand Down
4 changes: 0 additions & 4 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,6 @@ func TestReadDefaults(t *testing.T) {
t.Error("received", d, "expected", false)
}

if d := c.GetDryRunFieldName(); d != "meta.refinery.dryrun.kept" {
t.Error("received", d, "expected", "meta.refinery.dryrun.kept")
}

if d := c.GetAddHostMetadataToTrace(); d != false {
t.Error("received", d, "expected", false)
}
Expand Down
32 changes: 0 additions & 32 deletions config/file_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,6 @@ func (f *fileConfig) GetHoneycombLoggerConfig() (HoneycombLoggerConfig, error) {
return f.mainConfig.HoneycombLogger, nil
}

// TODO: DEPRECATED
func (f *fileConfig) GetCollectorType() (string, error) {
f.mux.RLock()
defer f.mux.RUnlock()

return "InMemCollector", nil
}

func (f *fileConfig) GetAllSamplerRules() (*V2SamplerConfig, error) {
f.mux.RLock()
defer f.mux.RUnlock()
Expand Down Expand Up @@ -619,14 +611,6 @@ func (f *fileConfig) GetInMemCollectorCacheCapacity() (CollectionConfig, error)
return f.mainConfig.Collection, nil
}

// TODO: REMOVE THIS
func (f *fileConfig) GetMetricsType() (string, error) {
f.mux.RLock()
defer f.mux.RUnlock()

return "", nil
}

func (f *fileConfig) GetLegacyMetricsConfig() LegacyMetricsConfig {
f.mux.RLock()
defer f.mux.RUnlock()
Expand Down Expand Up @@ -715,14 +699,6 @@ func (f *fileConfig) GetIsDryRun() bool {
return f.mainConfig.Debugging.DryRun
}

// TODO: DEPRECATED
func (f *fileConfig) GetDryRunFieldName() string {
f.mux.RLock()
defer f.mux.RUnlock()

return "meta.refinery.dryrun.kept"
}

func (f *fileConfig) GetAddHostMetadataToTrace() bool {
f.mux.RLock()
defer f.mux.RUnlock()
Expand Down Expand Up @@ -814,14 +790,6 @@ func (f *fileConfig) GetAddSpanCountToRoot() bool {
return f.mainConfig.Telemetry.AddSpanCountToRoot
}

// TODO: DEPRECATE
func (f *fileConfig) GetCacheOverrunStrategy() string {
f.mux.RLock()
defer f.mux.RUnlock()

return "impact"
}

func (f *fileConfig) GetSampleCacheConfig() SampleCacheConfig {
f.mux.RLock()
defer f.mux.RUnlock()
Expand Down
34 changes: 0 additions & 34 deletions config/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
type MockConfig struct {
Callbacks []func()
IsAPIKeyValidFunc func(string) bool
GetCollectorTypeErr error
GetCollectorTypeVal string
GetInMemoryCollectorCacheCapacityErr error
GetInMemoryCollectorCacheCapacityVal CollectionConfig
GetHoneycombAPIErr error
Expand Down Expand Up @@ -46,8 +44,6 @@ type MockConfig struct {
GetSamplerTypeErr error
GetSamplerTypeName string
GetSamplerTypeVal interface{}
GetMetricsTypeErr error
GetMetricsTypeVal string
GetLegacyMetricsConfigVal LegacyMetricsConfig
GetPrometheusMetricsConfigVal PrometheusMetricsConfig
GetOTelMetricsConfigVal OTelMetricsConfig
Expand All @@ -66,7 +62,6 @@ type MockConfig struct {
PeerManagementType string
DebugServiceAddr string
DryRun bool
DryRunFieldName string
AddHostMetadataToTrace bool
AddRuleReasonToTrace bool
EnvironmentCacheTTL time.Duration
Expand All @@ -80,7 +75,6 @@ type MockConfig struct {
PeerTimeout time.Duration
AdditionalErrorFields []string
AddSpanCountToRoot bool
CacheOverrunStrategy string
SampleCache SampleCacheConfig
StressRelief StressReliefConfig
AdditionalAttributes map[string]string
Expand Down Expand Up @@ -118,13 +112,6 @@ func (m *MockConfig) IsAPIKeyValid(key string) bool {
return m.IsAPIKeyValidFunc(key)
}

func (m *MockConfig) GetCollectorType() (string, error) {
m.Mux.RLock()
defer m.Mux.RUnlock()

return m.GetCollectorTypeVal, m.GetCollectorTypeErr
}

func (m *MockConfig) GetInMemCollectorCacheCapacity() (CollectionConfig, error) {
m.Mux.RLock()
defer m.Mux.RUnlock()
Expand Down Expand Up @@ -244,13 +231,6 @@ func (m *MockConfig) GetUseTLSInsecure() (bool, error) {
return m.GetUseTLSInsecureVal, m.GetUseTLSInsecureErr
}

func (m *MockConfig) GetMetricsType() (string, error) {
m.Mux.RLock()
defer m.Mux.RUnlock()

return m.GetMetricsTypeVal, m.GetMetricsTypeErr
}

func (m *MockConfig) GetLegacyMetricsConfig() LegacyMetricsConfig {
m.Mux.RLock()
defer m.Mux.RUnlock()
Expand Down Expand Up @@ -400,13 +380,6 @@ func (m *MockConfig) GetIsDryRun() bool {
return m.DryRun
}

func (m *MockConfig) GetDryRunFieldName() string {
m.Mux.RLock()
defer m.Mux.RUnlock()

return m.DryRunFieldName
}

func (m *MockConfig) GetAddHostMetadataToTrace() bool {
m.Mux.RLock()
defer m.Mux.RUnlock()
Expand Down Expand Up @@ -498,13 +471,6 @@ func (f *MockConfig) GetAddSpanCountToRoot() bool {
return f.AddSpanCountToRoot
}

func (f *MockConfig) GetCacheOverrunStrategy() string {
f.Mux.RLock()
defer f.Mux.RUnlock()

return f.CacheOverrunStrategy
}

func (f *MockConfig) GetSampleCacheConfig() SampleCacheConfig {
f.Mux.RLock()
defer f.Mux.RUnlock()
Expand Down