From a753fec954e744dd1f9b379890e8694dfc9577bc Mon Sep 17 00:00:00 2001 From: Lars Stegman Date: Tue, 8 Oct 2024 13:38:28 +0200 Subject: [PATCH] feat(inputs): remove checks for service inputs --- models/running_input.go | 28 ++++++++++++---------------- models/running_input_test.go | 6 +++--- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/models/running_input.go b/models/running_input.go index 99ea18586710c..7858d0e3e662b 100644 --- a/models/running_input.go +++ b/models/running_input.go @@ -117,14 +117,12 @@ func (r *RunningInput) Init() error { return fmt.Errorf("invalid 'startup_error_behavior' setting %q", r.Config.StartupErrorBehavior) } - if _, ok := r.Input.(telegraf.ServiceInput); !ok { - switch r.Config.TimeSource { - case "": - r.Config.TimeSource = "metric" - case "metric", "collection_start", "collection_end": - default: - return fmt.Errorf("invalid 'time_source' setting %q", r.Config.TimeSource) - } + switch r.Config.TimeSource { + case "": + r.Config.TimeSource = "metric" + case "metric", "collection_start", "collection_end": + default: + return fmt.Errorf("invalid 'time_source' setting %q", r.Config.TimeSource) } if p, ok := r.Input.(telegraf.Initializer); ok { @@ -219,14 +217,12 @@ func (r *RunningInput) MakeMetric(metric telegraf.Metric) telegraf.Metric { makemetric(metric, "", "", "", local, global) } - if _, ok := r.Input.(telegraf.ServiceInput); !ok { - switch r.Config.TimeSource { - case "collection_start": - metric.SetTime(r.gatherStart) - case "collection_end": - metric.SetTime(r.gatherEnd) - default: - } + switch r.Config.TimeSource { + case "collection_start": + metric.SetTime(r.gatherStart) + case "collection_end": + metric.SetTime(r.gatherEnd) + default: } r.MetricsGathered.Incr(1) diff --git a/models/running_input_test.go b/models/running_input_test.go index b3628f09f4de1..9bf7d6d9eb855 100644 --- a/models/running_input_test.go +++ b/models/running_input_test.go @@ -435,7 +435,7 @@ func TestMakeMetricWithGatherMetricTimeSource(t *testing.T) { Filter: Filter{}, AlwaysIncludeLocalTags: false, AlwaysIncludeGlobalTags: false, - TimeSource: TimeSourceMetric, + TimeSource: "metric", }) start := time.Now() ri.gatherStart = start @@ -457,7 +457,7 @@ func TestMakeMetricWithGatherStartTimeSource(t *testing.T) { Filter: Filter{}, AlwaysIncludeLocalTags: false, AlwaysIncludeGlobalTags: false, - TimeSource: TimeSourceCollectionStart, + TimeSource: "collection_start", }) ri.gatherStart = start @@ -474,7 +474,7 @@ func TestMakeMetricWithGatherEndTimeSource(t *testing.T) { end := time.Now() ri := NewRunningInput(&testInput{}, &InputConfig{ Name: "TestRunningInput", - TimeSource: TimeSourceCollectionEnd, + TimeSource: "collection_end", }) ri.gatherEnd = end