Skip to content

Commit

Permalink
feat(inputs): remove checks for service inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsStegman committed Oct 8, 2024
1 parent 3e5fbcd commit a753fec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
28 changes: 12 additions & 16 deletions models/running_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions models/running_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -457,7 +457,7 @@ func TestMakeMetricWithGatherStartTimeSource(t *testing.T) {
Filter: Filter{},
AlwaysIncludeLocalTags: false,
AlwaysIncludeGlobalTags: false,
TimeSource: TimeSourceCollectionStart,
TimeSource: "collection_start",
})
ri.gatherStart = start

Expand All @@ -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

Expand Down

0 comments on commit a753fec

Please sign in to comment.