Skip to content

Commit

Permalink
[chore]: enable gofumpt linter for exporter
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Nov 14, 2024
1 parent 40dbf0b commit e156191
Show file tree
Hide file tree
Showing 165 changed files with 759 additions and 639 deletions.
1 change: 0 additions & 1 deletion exporter/alertmanagerexporter/alertmanager_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ func (s *alertmanagerExporter) pushTraces(ctx context.Context, td ptrace.Traces)

alert := s.convertEventsToAlertPayload(events)
err := s.postAlert(ctx, alert)

if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion exporter/alertmanagerexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func TestLoadConfig(t *testing.T) {
id component.ID
expected component.Config
}{

{
id: component.NewIDWithName(metadata.Type, ""),
expected: defaultCfg,
Expand Down
1 change: 0 additions & 1 deletion exporter/alibabacloudlogserviceexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func TestLoadConfig(t *testing.T) {
id component.ID
expected component.Config
}{

{
id: component.NewIDWithName(metadata.Type, ""),
expected: defaultCfg,
Expand Down
3 changes: 2 additions & 1 deletion exporter/alibabacloudlogserviceexporter/logs_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type logServiceLogsSender struct {

func (s *logServiceLogsSender) pushLogsData(
_ context.Context,
md plog.Logs) error {
md plog.Logs,
) error {
var err error
slsLogs := logDataToLogService(md)
if len(slsLogs) > 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func instrumentationScopeToLogContents(instrumentationScope pcommon.Instrumentat

func mapLogRecordToLogService(lr plog.LogRecord,
resourceContents,
instrumentationLibraryContents []*sls.LogContent) *sls.Log {
instrumentationLibraryContents []*sls.LogContent,
) *sls.Log {
if lr.Body().Type() == pcommon.ValueTypeEmpty {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ func newMetricLogFromRaw(
name string,
labels KeyValues,
nsec int64,
value float64) *sls.Log {
value float64,
) *sls.Log {
labels.Sort()
return &sls.Log{
Time: proto.Uint32(uint32(nsec / 1e9)),
Expand Down
3 changes: 0 additions & 3 deletions exporter/awscloudwatchlogsexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func newCwLogsPusher(expConfig *Config, params exp.Settings) (*cwlExporter, erro
// create CWLogs client with aws session config
svcStructuredLog := cwlogs.NewClient(params.Logger, awsConfig, params.BuildInfo, expConfig.LogGroupName, expConfig.LogRetention, expConfig.Tags, session, metadata.Type.String())
collectorIdentifier, err := uuid.NewRandom()

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -105,13 +104,11 @@ func (e *cwlExporter) consumeLogs(_ context.Context, ld plog.Logs) error {
var errs error

err := pushLogsToCWLogs(e.logger, ld, e.Config, pusher)

if err != nil {
errs = errors.Join(errs, fmt.Errorf("Error pushing logs: %w", err))
}

err = pusher.ForceFlush()

if err != nil {
errs = errors.Join(errs, fmt.Errorf("Error flushing logs: %w", err))
}
Expand Down
14 changes: 7 additions & 7 deletions exporter/awsemfexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry"
)

var (
// eMFSupportedUnits contains the unit collection supported by CloudWatch backend service.
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html
eMFSupportedUnits = newEMFSupportedUnits()
)
// eMFSupportedUnits contains the unit collection supported by CloudWatch backend service.
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html
var eMFSupportedUnits = newEMFSupportedUnits()

// Config defines configuration for AWS EMF exporter.
type Config struct {
Expand Down Expand Up @@ -152,11 +150,13 @@ func (config *Config) isAppSignalsEnabled() bool {

func newEMFSupportedUnits() map[string]any {
unitIndexer := map[string]any{}
for _, unit := range []string{"Seconds", "Microseconds", "Milliseconds", "Bytes", "Kilobytes", "Megabytes",
for _, unit := range []string{
"Seconds", "Microseconds", "Milliseconds", "Bytes", "Kilobytes", "Megabytes",
"Gigabytes", "Terabytes", "Bits", "Kilobits", "Megabits", "Gigabits", "Terabits",
"Percent", "Count", "Bytes/Second", "Kilobytes/Second", "Megabytes/Second",
"Gigabytes/Second", "Terabytes/Second", "Bits/Second", "Kilobits/Second",
"Megabits/Second", "Gigabits/Second", "Terabits/Second", "Count/Second", "None"} {
"Megabits/Second", "Gigabits/Second", "Terabits/Second", "Count/Second", "None",
} {
unitIndexer[unit] = nil
}
return unitIndexer
Expand Down
1 change: 1 addition & 0 deletions exporter/awsemfexporter/datapoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ func generateOtelTestMetrics(generatedOtelMetrics ...pmetric.Metrics) pmetric.Me
}
return finalOtelMetrics
}

func generateDeltaMetricMetadata(adjustToDelta bool, metricName string, retainInitialValueForDelta bool) deltaMetricMetadata {
return deltaMetricMetadata{
adjustToDelta: adjustToDelta,
Expand Down
1 change: 0 additions & 1 deletion exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func newEmfExporter(config *Config, set exporter.Settings) (*emfExporter, error)
cwlogs.WithUserAgentExtras(userAgentExtras...),
)
collectorIdentifier, err := uuid.NewRandom()

if err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion exporter/awsemfexporter/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ func translateCWMetricToEMF(cWMetric *cWMetrics, config *Config) (*cwlogs.Event,
func translateGroupedMetricToEmf(groupedMetric *groupedMetric, config *Config, defaultLogStream string) (*cwlogs.Event, error) {
cWMetric := translateGroupedMetricToCWMetric(groupedMetric, config)
event, err := translateCWMetricToEMF(cWMetric, config)

if err != nil {
return nil, err
}
Expand Down
236 changes: 117 additions & 119 deletions exporter/awsemfexporter/metric_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ func TestTranslateCWMetricToEMF(t *testing.T) {
for name, tc := range testCases {
t.Run(name, func(_ *testing.T) {
config := &Config{

// include valid json string, a non-existing key, and keys whose value are not json/string
ParseJSONEncodedAttributeValues: []string{"kubernetes", "Sources", "NonExistingAttributeKey", "spanName", "spanCounter"},
Version: tc.emfVersion,
Expand Down Expand Up @@ -1335,7 +1334,8 @@ func TestGroupedMetricToCWMeasurementsWithFilters(t *testing.T) {
Dimensions: [][]string{{}},
MetricNameSelectors: []string{"metric(1|3)"},
},
}, []cWMeasurement{
},
[]cWMeasurement{
{
Namespace: namespace,
Dimensions: [][]string{{}},
Expand Down Expand Up @@ -2194,123 +2194,121 @@ type logGroupStreamTest struct {
outLogStreamName string
}

var (
logGroupStreamTestCases = []logGroupStreamTest{
{
name: "log_group_stream_expect_same",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
}),
inLogGroupName: "test-log-group",
inLogStreamName: "test-log-stream",
outLogGroupName: "test-log-group",
outLogStreamName: "test-log-stream",
},
{
name: "log_group_pattern_from_resource",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
resourceAttributeMap: map[string]any{
"ClusterName": "test-cluster",
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group-{ClusterName}",
inLogStreamName: "test-log-stream",
outLogGroupName: "test-log-group-test-cluster",
outLogStreamName: "test-log-stream",
},
{
name: "log_stream_pattern_from_resource",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
resourceAttributeMap: map[string]any{
"ClusterName": "test-cluster",
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group",
inLogStreamName: "test-log-stream-{PodName}",
outLogGroupName: "test-log-group",
outLogStreamName: "test-log-stream-test-pod",
},
{
name: "log_group_pattern_from_label",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
attributeMap: map[string]any{
"ClusterName": "test-cluster",
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group-{ClusterName}",
inLogStreamName: "test-log-stream",
outLogGroupName: "test-log-group-test-cluster",
outLogStreamName: "test-log-stream",
},
{
name: "log_stream_pattern_from_label",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
attributeMap: map[string]any{
"ClusterName": "test-cluster",
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group",
inLogStreamName: "test-log-stream-{PodName}",
outLogGroupName: "test-log-group",
outLogStreamName: "test-log-stream-test-pod",
},
{
name: "config_pattern_from_both_attributes",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
resourceAttributeMap: map[string]any{
"ClusterName": "test-cluster",
},
attributeMap: map[string]any{
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group-{ClusterName}",
inLogStreamName: "test-log-stream-{PodName}",
outLogGroupName: "test-log-group-test-cluster",
outLogStreamName: "test-log-stream-test-pod",
},
{
name: "config_pattern_missing_from_both_attributes",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
}),
inLogGroupName: "test-log-group-{ClusterName}",
inLogStreamName: "test-log-stream-{PodName}",
outLogGroupName: "test-log-group-undefined",
outLogStreamName: "test-log-stream-undefined",
},
{
name: "config_pattern_group_missing_stream_present",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
attributeMap: map[string]any{
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group-{ClusterName}",
inLogStreamName: "test-log-stream-{PodName}",
outLogGroupName: "test-log-group-undefined",
outLogStreamName: "test-log-stream-test-pod",
},
}
)
var logGroupStreamTestCases = []logGroupStreamTest{
{
name: "log_group_stream_expect_same",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
}),
inLogGroupName: "test-log-group",
inLogStreamName: "test-log-stream",
outLogGroupName: "test-log-group",
outLogStreamName: "test-log-stream",
},
{
name: "log_group_pattern_from_resource",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
resourceAttributeMap: map[string]any{
"ClusterName": "test-cluster",
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group-{ClusterName}",
inLogStreamName: "test-log-stream",
outLogGroupName: "test-log-group-test-cluster",
outLogStreamName: "test-log-stream",
},
{
name: "log_stream_pattern_from_resource",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
resourceAttributeMap: map[string]any{
"ClusterName": "test-cluster",
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group",
inLogStreamName: "test-log-stream-{PodName}",
outLogGroupName: "test-log-group",
outLogStreamName: "test-log-stream-test-pod",
},
{
name: "log_group_pattern_from_label",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
attributeMap: map[string]any{
"ClusterName": "test-cluster",
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group-{ClusterName}",
inLogStreamName: "test-log-stream",
outLogGroupName: "test-log-group-test-cluster",
outLogStreamName: "test-log-stream",
},
{
name: "log_stream_pattern_from_label",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
attributeMap: map[string]any{
"ClusterName": "test-cluster",
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group",
inLogStreamName: "test-log-stream-{PodName}",
outLogGroupName: "test-log-group",
outLogStreamName: "test-log-stream-test-pod",
},
{
name: "config_pattern_from_both_attributes",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
resourceAttributeMap: map[string]any{
"ClusterName": "test-cluster",
},
attributeMap: map[string]any{
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group-{ClusterName}",
inLogStreamName: "test-log-stream-{PodName}",
outLogGroupName: "test-log-group-test-cluster",
outLogStreamName: "test-log-stream-test-pod",
},
{
name: "config_pattern_missing_from_both_attributes",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
}),
inLogGroupName: "test-log-group-{ClusterName}",
inLogStreamName: "test-log-stream-{PodName}",
outLogGroupName: "test-log-group-undefined",
outLogStreamName: "test-log-stream-undefined",
},
{
name: "config_pattern_group_missing_stream_present",
inputMetrics: generateTestMetrics(testMetric{
metricNames: []string{"metric_1", "metric_2"},
metricValues: [][]float64{{100}, {4}},
attributeMap: map[string]any{
"PodName": "test-pod",
},
}),
inLogGroupName: "test-log-group-{ClusterName}",
inLogStreamName: "test-log-stream-{PodName}",
outLogGroupName: "test-log-group-undefined",
outLogStreamName: "test-log-stream-test-pod",
},
}

func TestTranslateOtToGroupedMetricForLogGroupAndStream(t *testing.T) {
for _, test := range logGroupStreamTestCases {
Expand Down
1 change: 0 additions & 1 deletion exporter/awskinesisexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func createExporter(ctx context.Context, c component.Config, log *zap.Logger, op
batch.WithMaxRecordsPerBatch(conf.MaxRecordsPerBatch),
batch.WithCompressionType(conf.Compression),
)

if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit e156191

Please sign in to comment.