Skip to content

Commit

Permalink
[chore]: enable whitespace linter for exporter (open-telemetry#36311)
Browse files Browse the repository at this point in the history
#### Description

[whitespace](https://golangci-lint.run/usage/linters/#whitespace) is a
linter that checks for unnecessary newlines at the start and end of
functions.

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 authored Nov 12, 2024
1 parent 53402aa commit fd686fc
Show file tree
Hide file tree
Showing 131 changed files with 0 additions and 262 deletions.
8 changes: 0 additions & 8 deletions exporter/alertmanagerexporter/alertmanager_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (s *alertmanagerExporter) convertEventSliceToArray(eventSlice ptrace.SpanEv
}

func (s *alertmanagerExporter) extractEvents(td ptrace.Traces) []*alertmanagerEvent {

// Stitch parent trace ID and span ID
rss := td.ResourceSpans()
var events []*alertmanagerEvent
Expand Down Expand Up @@ -107,7 +106,6 @@ func createAnnotations(event *alertmanagerEvent) model.LabelSet {
}

func (s *alertmanagerExporter) convertEventsToAlertPayload(events []*alertmanagerEvent) []model.Alert {

payload := make([]model.Alert, len(events))

for i, event := range events {
Expand All @@ -126,7 +124,6 @@ func (s *alertmanagerExporter) convertEventsToAlertPayload(events []*alertmanage
}

func (s *alertmanagerExporter) postAlert(ctx context.Context, payload []model.Alert) error {

msg, err := json.Marshal(payload)
if err != nil {
return fmt.Errorf("error marshaling alert to JSON: %w", err)
Expand Down Expand Up @@ -162,7 +159,6 @@ func (s *alertmanagerExporter) postAlert(ctx context.Context, payload []model.Al
}

func (s *alertmanagerExporter) pushTraces(ctx context.Context, td ptrace.Traces) error {

events := s.extractEvents(td)

if len(events) == 0 {
Expand All @@ -180,7 +176,6 @@ func (s *alertmanagerExporter) pushTraces(ctx context.Context, td ptrace.Traces)
}

func (s *alertmanagerExporter) start(ctx context.Context, host component.Host) error {

client, err := s.config.ClientConfig.ToClient(ctx, host, s.settings)
if err != nil {
return fmt.Errorf("failed to create HTTP Client: %w", err)
Expand All @@ -190,15 +185,13 @@ func (s *alertmanagerExporter) start(ctx context.Context, host component.Host) e
}

func (s *alertmanagerExporter) shutdown(context.Context) error {

if s.client != nil {
s.client.CloseIdleConnections()
}
return nil
}

func newAlertManagerExporter(cfg *Config, set component.TelemetrySettings) *alertmanagerExporter {

return &alertmanagerExporter{
config: cfg,
settings: set,
Expand All @@ -211,7 +204,6 @@ func newAlertManagerExporter(cfg *Config, set component.TelemetrySettings) *aler
}

func newTracesExporter(ctx context.Context, cfg component.Config, set exporter.Settings) (exporter.Traces, error) {

config := cfg.(*Config)

s := newAlertManagerExporter(config, set.TelemetrySettings)
Expand Down
3 changes: 0 additions & 3 deletions exporter/alertmanagerexporter/alertmanager_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func TestAlertManagerExporterSeverity(t *testing.T) {

ls = model.LabelSet{"event_name": "unittest-event", "severity": "info"}
assert.Equal(t, ls, alerts[1].Labels)

}

func TestAlertManagerExporterNoDefaultSeverity(t *testing.T) {
Expand Down Expand Up @@ -221,7 +220,6 @@ func TestAlertManagerExporterNoDefaultSeverity(t *testing.T) {

ls := model.LabelSet{"event_name": "unittest-event", "severity": "info"}
assert.Equal(t, ls, alerts[0].Labels)

}

func TestAlertManagerExporterAlertPayload(t *testing.T) {
Expand Down Expand Up @@ -267,7 +265,6 @@ func TestAlertManagerExporterAlertPayload(t *testing.T) {
assert.Equal(t, expect.Labels, got[0].Labels)
assert.Equal(t, expect.Annotations, got[0].Annotations)
assert.Equal(t, expect.GeneratorURL, got[0].GeneratorURL)

}

func TestAlertManagerTracesExporterNoErrors(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion exporter/alertmanagerexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var _ component.Config = (*Config)(nil)

// Validate checks if the exporter configuration is valid
func (cfg *Config) Validate() error {

if cfg.ClientConfig.Endpoint == "" {
return errors.New("endpoint must be non-empty")
}
Expand Down
1 change: 0 additions & 1 deletion exporter/alibabacloudlogserviceexporter/logs_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

// newLogsExporter return a new LogService logs exporter.
func newLogsExporter(set exporter.Settings, cfg component.Config) (exporter.Logs, error) {

l := &logServiceLogsSender{
logger: set.Logger,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func TestLogsDataToLogService(t *testing.T) {
})
}
gotLogPairs = append(gotLogPairs, pairs)

}

wantLogs := make([][]logKeyValuePair, 0, validLogCount)
Expand All @@ -98,7 +97,6 @@ func TestLogsDataToLogService(t *testing.T) {
return
}
for j := 0; j < validLogCount; j++ {

sort.Sort(logKeyValuePairs(gotLogPairs[j]))
sort.Sort(logKeyValuePairs(wantLogs[j]))
assert.Equal(t, wantLogs[j], gotLogPairs[j])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

// newMetricsExporter return a new LogSerice metrics exporter.
func newMetricsExporter(set exporter.Settings, cfg component.Config) (exporter.Metrics, error) {

l := &logServiceMetricsSender{
logger: set.Logger,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ func doubleHistogramMetricsToLogs(name string, data pmetric.HistogramDataPointSl
float64(bucket),
))
}

}
return logs
}
Expand Down Expand Up @@ -289,7 +288,6 @@ func metricsDataToLogServiceData(
_ *zap.Logger,
md pmetric.Metrics,
) (logs []*sls.Log) {

resMetrics := md.ResourceMetrics()
for i := 0; i < resMetrics.Len(); i++ {
resMetricSlice := resMetrics.At(i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func TestMetricDataToLogService(t *testing.T) {
})
}
gotLogPairs = append(gotLogPairs, pairs)

}

wantLogs := make([][]logKeyValuePair, 0, len(gotLogs))
Expand Down
1 change: 0 additions & 1 deletion exporter/alibabacloudlogserviceexporter/trace_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

// newTracesExporter return a new LogSerice trace exporter.
func newTracesExporter(set exporter.Settings, cfg component.Config) (exporter.Traces, error) {

l := &logServiceTraceSender{
logger: set.Logger,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

func TestNewTracesExporter(t *testing.T) {

got, err := newTracesExporter(exportertest.NewNopSettings(), &Config{
Endpoint: "cn-hangzhou.log.aliyuncs.com",
Project: "demo-project",
Expand All @@ -35,7 +34,6 @@ func TestNewTracesExporter(t *testing.T) {
}

func TestNewFailsWithEmptyTracesExporterName(t *testing.T) {

got, err := newTracesExporter(exportertest.NewNopSettings(), &Config{})
assert.Error(t, err)
require.Nil(t, got)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ func eventsToString(events ptrace.SpanEventSlice) string {
}
eventArrayBytes, _ := json.Marshal(&eventArray)
return string(eventArrayBytes)

}

func spanLinksToString(spanLinkSlice ptrace.SpanLinkSlice) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func TestTraceDataToLogService(t *testing.T) {
})
}
gotLogPairs = append(gotLogPairs, pairs)

}

wantLogs := make([][]logKeyValuePair, 0, len(gotLogs))
Expand Down
1 change: 0 additions & 1 deletion exporter/awscloudwatchlogsexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (config *Config) Validate() error {
return retErr
}
return cwlogs.ValidateTagsInput(config.Tags)

}

// TODO(jbd): Add ARN role to config.
2 changes: 0 additions & 2 deletions exporter/awscloudwatchlogsexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func TestRetentionValidateCorrect(t *testing.T) {
},
}
assert.NoError(t, component.ValidateConfig(cfg))

}

func TestRetentionValidateWrong(t *testing.T) {
Expand All @@ -143,7 +142,6 @@ func TestRetentionValidateWrong(t *testing.T) {
},
}
assert.Error(t, component.ValidateConfig(wrongcfg))

}

func TestValidateTags(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion exporter/awscloudwatchlogsexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ func createLogsExporter(_ context.Context, params exporter.Settings, config comp
return nil, errors.New("invalid configuration type; can't cast to awscloudwatchlogsexporter.Config")
}
return newCwLogsExporter(expConfig, params)

}
2 changes: 0 additions & 2 deletions exporter/awsemfexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func TestRetentionValidateCorrect(t *testing.T) {
logger: zap.NewNop(),
}
assert.NoError(t, component.ValidateConfig(cfg))

}

func TestRetentionValidateWrong(t *testing.T) {
Expand All @@ -174,7 +173,6 @@ func TestRetentionValidateWrong(t *testing.T) {
logger: zap.NewNop(),
}
assert.Error(t, component.ValidateConfig(wrongcfg))

}

func TestValidateTags(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion exporter/awsemfexporter/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ func (dps summaryDataPointSlice) CalculateDeltaDatapoints(i int, instrumentation
quantile := values.At(i)
cLabels["quantile"] = strconv.FormatFloat(quantile.Quantile(), 'g', -1, 64)
datapoints = append(datapoints, dataPoint{name: dps.metricName, value: quantile.Value(), labels: cLabels, timestampMs: timestampMs})

}
} else {
metricVal := &cWMetricStats{Count: count, Sum: sum}
Expand Down
16 changes: 0 additions & 16 deletions exporter/awsemfexporter/datapoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ func shutdownEmfCalculators(c *emfCalculators) error {
var errs error
errs = multierr.Append(errs, c.delta.Shutdown())
return multierr.Append(errs, c.summary.Shutdown())

}

func TestIsStaleNaNInf_NumberDataPointSlice(t *testing.T) {
Expand Down Expand Up @@ -398,7 +397,6 @@ func TestIsStaleNaNInf_NumberDataPointSlice(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {

// Given the number datapoint (including Sum and Gauge OTEL metric type) with data type as int or double
numberDPS := pmetric.NewNumberDataPointSlice()

Expand All @@ -425,7 +423,6 @@ func TestCalculateDeltaDatapoints_NumberDataPointSlice(t *testing.T) {
emfCalcs := setupEmfCalculators()
defer require.NoError(t, shutdownEmfCalculators(emfCalcs))
for _, retainInitialValueOfDeltaMetric := range []bool{true, false} {

testCases := []struct {
name string
adjustToDelta bool
Expand Down Expand Up @@ -511,7 +508,6 @@ func TestCalculateDeltaDatapoints_NumberDataPointSlice(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {

// Given the number datapoint (including Sum and Gauge OTEL metric type) with data type as int or double
numberDPS := pmetric.NewNumberDataPointSlice()
numberDP := numberDPS.AppendEmpty()
Expand Down Expand Up @@ -579,7 +575,6 @@ func TestCalculateDeltaDatapoints_HistogramDataPointSlice(t *testing.T) {
histogramDP.SetSum(17.13)
histogramDP.Attributes().PutStr("label1", "value1")
return histogramDPS

}(),
expectedDatapoint: dataPoint{
name: "foo",
Expand Down Expand Up @@ -620,14 +615,11 @@ func TestCalculateDeltaDatapoints_HistogramDataPointSlice(t *testing.T) {
assert.True(t, retained)
assert.Equal(t, 1, histogramDatapointSlice.Len())
assert.Equal(t, tc.expectedDatapoint, dps[0])

})
}

}

func TestIsStaleNaNInf_HistogramDataPointSlice(t *testing.T) {

testCases := []struct {
name string
histogramDPS pmetric.HistogramDataPointSlice
Expand Down Expand Up @@ -791,7 +783,6 @@ func TestIsStaleNaNInf_HistogramDataPointSlice(t *testing.T) {
tc.boolAssertFunc(t, isStaleNanInf)
})
}

}

func TestCalculateDeltaDatapoints_ExponentialHistogramDataPointSlice(t *testing.T) {
Expand Down Expand Up @@ -829,7 +820,6 @@ func TestCalculateDeltaDatapoints_ExponentialHistogramDataPointSlice(t *testing.
histogramDP.SetSum(17.13)
histogramDP.Attributes().PutStr("label1", "value1")
return histogramDPS

}(),
expectedDatapoint: dataPoint{
name: "foo",
Expand Down Expand Up @@ -892,11 +882,9 @@ func TestCalculateDeltaDatapoints_ExponentialHistogramDataPointSlice(t *testing.
assert.Equal(t, tc.expectedDatapoint, dps[0])
})
}

}

func TestIsStaleNaNInf_ExponentialHistogramDataPointSlice(t *testing.T) {

testCases := []struct {
name string
histogramDPS pmetric.ExponentialHistogramDataPointSlice
Expand Down Expand Up @@ -1089,7 +1077,6 @@ func TestIsStaleNaNInf_ExponentialHistogramDataPointSlice(t *testing.T) {
tc.boolAssertFunc(t, isStaleNaNInf)
})
}

}

func TestCalculateDeltaDatapoints_SummaryDataPointSlice(t *testing.T) {
Expand Down Expand Up @@ -1170,7 +1157,6 @@ func TestCalculateDeltaDatapoints_SummaryDataPointSlice(t *testing.T) {
assert.Equal(t, tc.expectedDatapoint[i].labels, dp.labels)
assert.InDelta(t, tc.expectedDatapoint[i].value, dp.value, 0.002)
}

}
})
}
Expand Down Expand Up @@ -1366,7 +1352,6 @@ func TestIsStaleNaNInf_SummaryDataPointSlice(t *testing.T) {
tc.expectedBoolAssert(t, isStaleNaNInf)
})
}

}

func TestCreateLabels(t *testing.T) {
Expand Down Expand Up @@ -1455,7 +1440,6 @@ func TestGetDataPoints(t *testing.T) {
metadata := generateTestMetricMetadata("namespace", time.Now().UnixNano()/int64(time.Millisecond), "log-group", "log-stream", "cloudwatch-otel", metric.Type())

t.Run(tc.name, func(t *testing.T) {

if tc.isPrometheusMetrics {
metadata.receiver = prometheusReceiver
} else {
Expand Down
2 changes: 0 additions & 2 deletions exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ func (emf *emfExporter) pushMetricsData(_ context.Context, md pmetric.Metrics) e
fmt.Println(*putLogEvent.InputLogEvent.Message)
}
} else if strings.EqualFold(outputDestination, outputDestinationCloudWatch) {

emfPusher := emf.getPusher(putLogEvent.StreamKey)
if emfPusher != nil {
returnError := emfPusher.AddLogEntry(putLogEvent)
Expand Down Expand Up @@ -167,7 +166,6 @@ func (emf *emfExporter) pushMetricsData(_ context.Context, md pmetric.Metrics) e
}

func (emf *emfExporter) getPusher(key cwlogs.StreamKey) cwlogs.Pusher {

var ok bool
if _, ok = emf.pusherMap[key]; !ok {
emf.pusherMap[key] = cwlogs.NewPusher(key, emf.retryCnt, *emf.svcStructuredLog, emf.config.logger)
Expand Down
2 changes: 0 additions & 2 deletions exporter/awsemfexporter/emf_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func TestConsumeMetricsWithNaNValues(t *testing.T) {
require.NoError(t, exp.shutdown(ctx))
})
}

}

func TestConsumeMetricsWithInfValues(t *testing.T) {
Expand Down Expand Up @@ -142,7 +141,6 @@ func TestConsumeMetricsWithInfValues(t *testing.T) {
require.NoError(t, exp.shutdown(ctx))
})
}

}

func TestConsumeMetricsWithOutputDestination(t *testing.T) {
Expand Down
Loading

0 comments on commit fd686fc

Please sign in to comment.