Skip to content

Commit

Permalink
Merge branch 'main' into getDimensionValue
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredTan95 authored Aug 30, 2024
2 parents 471d241 + 184e954 commit 140dda4
Show file tree
Hide file tree
Showing 161 changed files with 1,093 additions and 664 deletions.
27 changes: 27 additions & 0 deletions .chloggen/redaction-add-metrics-and-logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: redactionprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add support for logs and metrics

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [34479]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ linters-settings:
- expected-actual
- float-compare
- go-require
- len
- negative-positive
- nil-compare
- require-error
Expand Down
6 changes: 3 additions & 3 deletions cmd/telemetrygen/internal/traces/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func TestSpansWithNoAttrs(t *testing.T) {
assert.Len(t, syncer.spans, 4) // each trace has two spans
for _, span := range syncer.spans {
attributes := span.Attributes()
assert.Equal(t, 2, len(attributes), "it shouldn't have more than 2 fixed attributes")
assert.Len(t, attributes, 2, "it shouldn't have more than 2 fixed attributes")
}
}

Expand All @@ -284,7 +284,7 @@ func TestSpansWithOneAttrs(t *testing.T) {
assert.Len(t, syncer.spans, 4) // each trace has two spans
for _, span := range syncer.spans {
attributes := span.Attributes()
assert.Equal(t, 3, len(attributes), "it should have more than 3 attributes")
assert.Len(t, attributes, 3, "it should have more than 3 attributes")
}
}

Expand All @@ -306,7 +306,7 @@ func TestSpansWithMultipleAttrs(t *testing.T) {
assert.Len(t, syncer.spans, 4) // each trace has two spans
for _, span := range syncer.spans {
attributes := span.Attributes()
assert.Equal(t, 4, len(attributes), "it should have more than 4 attributes")
assert.Len(t, attributes, 4, "it should have more than 4 attributes")
}
}

Expand Down
6 changes: 3 additions & 3 deletions connector/countconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func TestTracesToMetrics(t *testing.T) {
assert.NoError(t, conn.ConsumeTraces(context.Background(), testSpans))

allMetrics := sink.AllMetrics()
assert.Equal(t, 1, len(allMetrics))
assert.Len(t, allMetrics, 1)

// golden.WriteMetrics(t, filepath.Join("testdata", "traces", tc.name+".yaml"), allMetrics[0])
expected, err := golden.ReadMetrics(filepath.Join("testdata", "traces", tc.name+".yaml"))
Expand Down Expand Up @@ -507,7 +507,7 @@ func TestMetricsToMetrics(t *testing.T) {
assert.NoError(t, conn.ConsumeMetrics(context.Background(), testMetrics))

allMetrics := sink.AllMetrics()
assert.Equal(t, 1, len(allMetrics))
assert.Len(t, allMetrics, 1)

// golden.WriteMetrics(t, filepath.Join("testdata", "metrics", tc.name+".yaml"), allMetrics[0])
expected, err := golden.ReadMetrics(filepath.Join("testdata", "metrics", tc.name+".yaml"))
Expand Down Expand Up @@ -679,7 +679,7 @@ func TestLogsToMetrics(t *testing.T) {
assert.NoError(t, conn.ConsumeLogs(context.Background(), testLogs))

allMetrics := sink.AllMetrics()
assert.Equal(t, 1, len(allMetrics))
assert.Len(t, allMetrics, 1)

// golden.WriteMetrics(t, filepath.Join("testdata", "logs", tc.name+".yaml"), allMetrics[0])
expected, err := golden.ReadMetrics(filepath.Join("testdata", "logs", tc.name+".yaml"))
Expand Down
6 changes: 3 additions & 3 deletions connector/datadogconnector/connector_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestContainerTagsNative(t *testing.T) {

// check if the container tags are added to the metrics
metrics := metricsSink.AllMetrics()
assert.Equal(t, 1, len(metrics))
assert.Len(t, metrics, 1)

ch := make(chan []byte, 100)
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
Expand All @@ -117,7 +117,7 @@ func TestContainerTagsNative(t *testing.T) {
require.NoError(t, err)

tags := sp.Stats[0].Tags
assert.Equal(t, 3, len(tags))
assert.Len(t, tags, 3)
assert.ElementsMatch(t, []string{"region:my-region", "zone:my-zone", "az:my-az"}, tags)
}

Expand Down Expand Up @@ -187,7 +187,7 @@ func TestMeasuredAndClientKindNative(t *testing.T) {
}

metrics := metricsSink.AllMetrics()
require.Equal(t, 1, len(metrics))
require.Len(t, metrics, 1)

ch := make(chan []byte, 100)
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
Expand Down
6 changes: 3 additions & 3 deletions connector/datadogconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestContainerTags(t *testing.T) {
err = connector.ConsumeTraces(context.Background(), trace2)
assert.NoError(t, err)
// check if the container tags are added to the cache
assert.Equal(t, 1, len(connector.containerTagCache.Items()))
assert.Len(t, connector.containerTagCache.Items(), 1)
count := 0
connector.containerTagCache.Items()["my-container-id"].Object.(*sync.Map).Range(func(_, _ any) bool {
count++
Expand All @@ -175,7 +175,7 @@ func TestContainerTags(t *testing.T) {

// check if the container tags are added to the metrics
metrics := metricsSink.AllMetrics()
assert.Equal(t, 1, len(metrics))
assert.Len(t, metrics, 1)

ch := make(chan []byte, 100)
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
Expand All @@ -188,7 +188,7 @@ func TestContainerTags(t *testing.T) {
require.NoError(t, err)

tags := sp.Stats[0].Tags
assert.Equal(t, 3, len(tags))
assert.Len(t, tags, 3)
assert.ElementsMatch(t, []string{"region:my-region", "zone:my-zone", "az:my-az"}, tags)
}

Expand Down
36 changes: 18 additions & 18 deletions connector/roundrobinconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ func TestLogsRoundRobin(t *testing.T) {
assert.NoError(t, logs.ConsumeLogs(ctx, plog.NewLogs()))
assert.NoError(t, logs.ConsumeLogs(ctx, plog.NewLogs()))

assert.Equal(t, 1, len(sink1.AllLogs()))
assert.Equal(t, 1, len(sink2.AllLogs()))
assert.Equal(t, 1, len(sink3.AllLogs()))
assert.Len(t, sink1.AllLogs(), 1)
assert.Len(t, sink2.AllLogs(), 1)
assert.Len(t, sink3.AllLogs(), 1)

assert.NoError(t, logs.ConsumeLogs(ctx, plog.NewLogs()))
assert.NoError(t, logs.ConsumeLogs(ctx, plog.NewLogs()))
assert.NoError(t, logs.ConsumeLogs(ctx, plog.NewLogs()))

assert.Equal(t, 2, len(sink1.AllLogs()))
assert.Equal(t, 2, len(sink2.AllLogs()))
assert.Equal(t, 2, len(sink3.AllLogs()))
assert.Len(t, sink1.AllLogs(), 2)
assert.Len(t, sink2.AllLogs(), 2)
assert.Len(t, sink3.AllLogs(), 2)

assert.NoError(t, logs.Shutdown(ctx))
}
Expand All @@ -87,17 +87,17 @@ func TestMetricsRoundRobin(t *testing.T) {
assert.NoError(t, metrics.ConsumeMetrics(ctx, pmetric.NewMetrics()))
assert.NoError(t, metrics.ConsumeMetrics(ctx, pmetric.NewMetrics()))

assert.Equal(t, 1, len(sink1.AllMetrics()))
assert.Equal(t, 1, len(sink2.AllMetrics()))
assert.Equal(t, 1, len(sink3.AllMetrics()))
assert.Len(t, sink1.AllMetrics(), 1)
assert.Len(t, sink2.AllMetrics(), 1)
assert.Len(t, sink3.AllMetrics(), 1)

assert.NoError(t, metrics.ConsumeMetrics(ctx, pmetric.NewMetrics()))
assert.NoError(t, metrics.ConsumeMetrics(ctx, pmetric.NewMetrics()))
assert.NoError(t, metrics.ConsumeMetrics(ctx, pmetric.NewMetrics()))

assert.Equal(t, 2, len(sink1.AllMetrics()))
assert.Equal(t, 2, len(sink2.AllMetrics()))
assert.Equal(t, 2, len(sink3.AllMetrics()))
assert.Len(t, sink1.AllMetrics(), 2)
assert.Len(t, sink2.AllMetrics(), 2)
assert.Len(t, sink3.AllMetrics(), 2)

assert.NoError(t, metrics.Shutdown(ctx))
}
Expand All @@ -124,17 +124,17 @@ func TestTracesRoundRobin(t *testing.T) {
assert.NoError(t, traces.ConsumeTraces(ctx, ptrace.NewTraces()))
assert.NoError(t, traces.ConsumeTraces(ctx, ptrace.NewTraces()))

assert.Equal(t, 1, len(sink1.AllTraces()))
assert.Equal(t, 1, len(sink2.AllTraces()))
assert.Equal(t, 1, len(sink3.AllTraces()))
assert.Len(t, sink1.AllTraces(), 1)
assert.Len(t, sink2.AllTraces(), 1)
assert.Len(t, sink3.AllTraces(), 1)

assert.NoError(t, traces.ConsumeTraces(ctx, ptrace.NewTraces()))
assert.NoError(t, traces.ConsumeTraces(ctx, ptrace.NewTraces()))
assert.NoError(t, traces.ConsumeTraces(ctx, ptrace.NewTraces()))

assert.Equal(t, 2, len(sink1.AllTraces()))
assert.Equal(t, 2, len(sink2.AllTraces()))
assert.Equal(t, 2, len(sink3.AllTraces()))
assert.Len(t, sink1.AllTraces(), 2)
assert.Len(t, sink2.AllTraces(), 2)
assert.Len(t, sink3.AllTraces(), 2)

assert.NoError(t, traces.Shutdown(ctx))
}
12 changes: 6 additions & 6 deletions connector/servicegraphconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func TestStaleSeriesCleanup(t *testing.T) {
p.keyToMetric[key] = metric
}
p.cleanCache()
assert.Equal(t, 0, len(p.keyToMetric))
assert.Len(t, p.keyToMetric, 0)

// ConsumeTraces with a trace with different attribute value
td = buildSampleTrace(t, "second")
Expand Down Expand Up @@ -526,8 +526,8 @@ func TestMapsAreConsistentDuringCleanup(t *testing.T) {
go p.cleanCache()

// Since everything is locked, nothing has happened, so both should still have length 1
assert.Equal(t, 1, len(p.reqTotal))
assert.Equal(t, 1, len(p.keyToMetric))
assert.Len(t, p.reqTotal, 1)
assert.Len(t, p.keyToMetric, 1)

// Now we pretend that we have stopped collecting metrics, by unlocking seriesMutex
p.seriesMutex.Unlock()
Expand All @@ -540,8 +540,8 @@ func TestMapsAreConsistentDuringCleanup(t *testing.T) {
// for dimensions from that series. It's important that it happens this way around,
// instead of deleting it from `keyToMetric`, otherwise the metrics collector will try
// and fail to find dimensions for a series that is about to be removed.
assert.Equal(t, 0, len(p.reqTotal))
assert.Equal(t, 1, len(p.keyToMetric))
assert.Len(t, p.reqTotal, 0)
assert.Len(t, p.keyToMetric, 1)

p.metricMutex.RUnlock()
p.seriesMutex.Unlock()
Expand Down Expand Up @@ -575,7 +575,7 @@ func TestValidateOwnTelemetry(t *testing.T) {
p.keyToMetric[key] = metric
}
p.cleanCache()
assert.Equal(t, 0, len(p.keyToMetric))
assert.Len(t, p.keyToMetric, 0)

// ConsumeTraces with a trace with different attribute value
td = buildSampleTrace(t, "second")
Expand Down
4 changes: 2 additions & 2 deletions exporter/alertmanagerexporter/alertmanager_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestAlertManagerExporterExtractEvents(t *testing.T) {

// test - events
got := am.extractEvents(traces)
assert.Equal(t, tt.events, len(got))
assert.Len(t, got, tt.events)
})
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestAlertManagerExporterEventNameAttributes(t *testing.T) {
got := am.extractEvents(traces)

// test - result length
assert.Equal(t, 1, len(got))
assert.Len(t, got, 1)

// test - count of attributes
assert.Equal(t, 3, got[0].spanEvent.Attributes().Len())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestLogsDataToLogService(t *testing.T) {
totalLogCount := 10
validLogCount := totalLogCount - 1
gotLogs := logDataToLogService(createLogData(10))
assert.Equal(t, len(gotLogs), 9)
assert.Len(t, gotLogs, 9)

gotLogPairs := make([][]logKeyValuePair, 0, len(gotLogs))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (kv logKeyValuePairs) Less(i, j int) bool { return kv[i].Key < kv[j].Key }

func TestTraceDataToLogService(t *testing.T) {
gotLogs := traceDataToLogServiceData(constructSpanData())
assert.Equal(t, len(gotLogs), 2)
assert.Len(t, gotLogs, 2)

gotLogPairs := make([][]logKeyValuePair, 0, len(gotLogs))

Expand Down
2 changes: 1 addition & 1 deletion exporter/awsemfexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestConfigValidate(t *testing.T) {
}
assert.NoError(t, component.ValidateConfig(cfg))

assert.Equal(t, 2, len(cfg.MetricDescriptors))
assert.Len(t, cfg.MetricDescriptors, 2)
assert.Equal(t, []MetricDescriptor{
{Unit: "Count", MetricName: "apiserver_total", Overwrite: true},
{Unit: "Megabytes", MetricName: "memory_usage"},
Expand Down
4 changes: 2 additions & 2 deletions exporter/awsemfexporter/emf_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ func TestNewExporterWithMetricDeclarations(t *testing.T) {
assert.NoError(t, err)

// Invalid metric declaration should be filtered out
assert.Equal(t, 3, len(exp.config.MetricDeclarations))
assert.Len(t, exp.config.MetricDeclarations, 3)
// Invalid dimensions (> 10 dims) should be filtered out
assert.Equal(t, 1, len(exp.config.MetricDeclarations[2].Dimensions))
assert.Len(t, exp.config.MetricDeclarations[2].Dimensions, 1)

// Test output warning logs
expectedLogs := []observer.LoggedEntry{
Expand Down
12 changes: 6 additions & 6 deletions exporter/awsemfexporter/grouped_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ func TestAddToGroupedMetric(t *testing.T) {
assert.NoError(t, err)
}

assert.Equal(t, 1, len(groupedMetrics))
assert.Len(t, groupedMetrics, 1)
for _, v := range groupedMetrics {
assert.Equal(t, len(tc.expectedMetricInfo), len(v.metrics))
assert.Equal(t, tc.expectedMetricInfo, v.metrics)
assert.Equal(t, 2, len(v.labels))
assert.Len(t, v.labels, 2)
assert.Equal(t, generateTestMetricMetadata(namespace, timestamp, logGroup, logStreamName, instrumentationLibName, tc.expectedMetricType), v.metadata)
assert.Equal(t, tc.expectedLabels, v.labels)
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestAddToGroupedMetric(t *testing.T) {
assert.NoError(t, err)
}

assert.Equal(t, 4, len(groupedMetrics))
assert.Len(t, groupedMetrics, 4)
for _, group := range groupedMetrics {
for metricName, metricInfo := range group.metrics {
switch metricName {
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestAddToGroupedMetric(t *testing.T) {
assert.NoError(t, err)
}

assert.Equal(t, 4, len(groupedMetrics))
assert.Len(t, groupedMetrics, 4)
for _, group := range groupedMetrics {
for metricName, metricInfo := range group.metrics {
switch metricName {
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestAddToGroupedMetric(t *testing.T) {
)
assert.NoError(t, err)
}
assert.Equal(t, 1, len(groupedMetrics))
assert.Len(t, groupedMetrics, 1)

labels := map[string]string{
oTellibDimensionKey: instrumentationLibName,
Expand Down Expand Up @@ -389,7 +389,7 @@ func TestAddToGroupedMetric(t *testing.T) {
emfCalcs,
)
assert.NoError(t, err)
assert.Equal(t, 0, len(groupedMetrics))
assert.Len(t, groupedMetrics, 0)

// Test output warning logs
expectedLogs := []observer.LoggedEntry{
Expand Down
Loading

0 comments on commit 140dda4

Please sign in to comment.