Skip to content

Commit af3db55

Browse files
authored
[receiver/statsd] fix lint for statsdreceiver (open-telemetry#12780)
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
1 parent 5cc7ded commit af3db55

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

receiver/statsdreceiver/protocol/statsd_parser_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// nolint:errcheck
1615
package protocol
1716

1817
import (
@@ -668,7 +667,7 @@ func TestStatsDParser_Aggregate(t *testing.T) {
668667
t.Run(tt.name, func(t *testing.T) {
669668
var err error
670669
p := &StatsDParser{}
671-
p.Initialize(false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})
670+
assert.NoError(t, p.Initialize(false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}}))
672671
p.lastIntervalTime = time.Unix(611, 0)
673672
for _, line := range tt.input {
674673
err = p.Aggregate(line)
@@ -737,7 +736,7 @@ func TestStatsDParser_AggregateWithMetricType(t *testing.T) {
737736
t.Run(tt.name, func(t *testing.T) {
738737
var err error
739738
p := &StatsDParser{}
740-
p.Initialize(true, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})
739+
assert.NoError(t, p.Initialize(true, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}}))
741740
p.lastIntervalTime = time.Unix(611, 0)
742741
for _, line := range tt.input {
743742
err = p.Aggregate(line)
@@ -785,7 +784,7 @@ func TestStatsDParser_AggregateWithIsMonotonicCounter(t *testing.T) {
785784
t.Run(tt.name, func(t *testing.T) {
786785
var err error
787786
p := &StatsDParser{}
788-
p.Initialize(false, true, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})
787+
assert.NoError(t, p.Initialize(false, true, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}}))
789788
p.lastIntervalTime = time.Unix(611, 0)
790789
for _, line := range tt.input {
791790
err = p.Aggregate(line)
@@ -881,7 +880,7 @@ func TestStatsDParser_AggregateTimerWithSummary(t *testing.T) {
881880
t.Run(tt.name, func(t *testing.T) {
882881
var err error
883882
p := &StatsDParser{}
884-
p.Initialize(false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "summary"}, {StatsdType: "histogram", ObserverType: "summary"}})
883+
assert.NoError(t, p.Initialize(false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "summary"}, {StatsdType: "histogram", ObserverType: "summary"}}))
885884
for _, line := range tt.input {
886885
err = p.Aggregate(line)
887886
}
@@ -896,7 +895,7 @@ func TestStatsDParser_AggregateTimerWithSummary(t *testing.T) {
896895

897896
func TestStatsDParser_Initialize(t *testing.T) {
898897
p := &StatsDParser{}
899-
p.Initialize(true, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})
898+
assert.NoError(t, p.Initialize(true, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}}))
900899
teststatsdDMetricdescription := statsDMetricDescription{
901900
name: "test",
902901
metricType: "g",
@@ -909,7 +908,7 @@ func TestStatsDParser_Initialize(t *testing.T) {
909908

910909
func TestStatsDParser_GetMetricsWithMetricType(t *testing.T) {
911910
p := &StatsDParser{}
912-
p.Initialize(true, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})
911+
assert.NoError(t, p.Initialize(true, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}}))
913912
p.gauges[testDescription("statsdTestMetric1", "g",
914913
[]string{"mykey", "metric_type"}, []string{"myvalue", "gauge"})] =
915914
buildGaugeMetric(testStatsDMetric("testGauge1", 1, false, "g", 0, []string{"mykey", "metric_type"}, []string{"myvalue", "gauge"}), time.Unix(711, 0))
@@ -982,10 +981,10 @@ func TestStatsDParser_Mappings(t *testing.T) {
982981
t.Run(tc.name, func(t *testing.T) {
983982
p := &StatsDParser{}
984983

985-
p.Initialize(false, false, tc.mapping)
984+
assert.NoError(t, p.Initialize(false, false, tc.mapping))
986985

987-
p.Aggregate("H:10|h")
988-
p.Aggregate("T:10|ms")
986+
assert.NoError(t, p.Aggregate("H:10|h"))
987+
assert.NoError(t, p.Aggregate("T:10|ms"))
989988

990989
typeNames := map[string]string{}
991990

receiver/statsdreceiver/receiver.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// nolint:errcheck
1615
package statsdreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver"
1716

1817
import (
@@ -90,7 +89,10 @@ func (r *statsdReceiver) Start(ctx context.Context, host component.Host) error {
9089
ctx, r.cancel = context.WithCancel(ctx)
9190
var transferChan = make(chan string, 10)
9291
ticker := time.NewTicker(r.config.AggregationInterval)
93-
r.parser.Initialize(r.config.EnableMetricType, r.config.IsMonotonicCounter, r.config.TimerHistogramMapping)
92+
err := r.parser.Initialize(r.config.EnableMetricType, r.config.IsMonotonicCounter, r.config.TimerHistogramMapping)
93+
if err != nil {
94+
return err
95+
}
9496
go func() {
9597
if err := r.server.ListenAndServe(r.parser, r.nextConsumer, r.reporter, transferChan); err != nil {
9698
if !errors.Is(err, net.ErrClosed) {
@@ -107,7 +109,7 @@ func (r *statsdReceiver) Start(ctx context.Context, host component.Host) error {
107109
r.Flush(ctx, metrics, r.nextConsumer)
108110
}
109111
case rawMetric := <-transferChan:
110-
r.parser.Aggregate(rawMetric)
112+
_ = r.parser.Aggregate(rawMetric)
111113
case <-ctx.Done():
112114
ticker.Stop()
113115
return

receiver/statsdreceiver/receiver_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// nolint:errcheck
1615
package statsdreceiver
1716

1817
import (
@@ -88,8 +87,8 @@ func TestStatsdReceiver_Flush(t *testing.T) {
8887
r := rcv.(*statsdReceiver)
8988
var metrics = pmetric.NewMetrics()
9089
assert.Nil(t, r.Flush(ctx, metrics, nextConsumer))
91-
r.Start(ctx, componenttest.NewNopHost())
92-
r.Shutdown(ctx)
90+
assert.NoError(t, r.Start(ctx, componenttest.NewNopHost()))
91+
assert.NoError(t, r.Shutdown(ctx))
9392
}
9493

9594
func Test_statsdreceiver_EndToEnd(t *testing.T) {
@@ -136,7 +135,9 @@ func Test_statsdreceiver_EndToEnd(t *testing.T) {
136135
r.reporter = mr
137136

138137
require.NoError(t, r.Start(context.Background(), componenttest.NewNopHost()))
139-
defer r.Shutdown(context.Background())
138+
defer func() {
139+
assert.NoError(t, r.Shutdown(context.Background()))
140+
}()
140141

141142
statsdClient := tt.clientFn(t)
142143

receiver/statsdreceiver/reporter_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// nolint:errcheck
1615
package statsdreceiver
1716

1817
import (
@@ -28,7 +27,9 @@ import (
2827
func TestReporterObservability(t *testing.T) {
2928
tt, err := obsreporttest.SetupTelemetry()
3029
require.NoError(t, err)
31-
defer tt.Shutdown(context.Background())
30+
defer func() {
31+
require.NoError(t, tt.Shutdown(context.Background()))
32+
}()
3233

3334
receiverID := config.NewComponentIDWithName(typeStr, "fake_receiver")
3435
reporter := newReporter(receiverID, tt.ToReceiverCreateSettings())

0 commit comments

Comments
 (0)