Skip to content

Commit

Permalink
Get rid of deprecated internal.{Duration,Size,Number} (influxdata#8969)
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan authored Apr 9, 2021
1 parent c66ccee commit 9853bf6
Show file tree
Hide file tree
Showing 194 changed files with 1,563 additions and 1,540 deletions.
22 changes: 11 additions & 11 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ type outputUnit struct {
func (a *Agent) Run(ctx context.Context) error {
log.Printf("I! [agent] Config: Interval:%s, Quiet:%#v, Hostname:%#v, "+
"Flush Interval:%s",
a.Config.Agent.Interval.Duration, a.Config.Agent.Quiet,
a.Config.Agent.Hostname, a.Config.Agent.FlushInterval.Duration)
time.Duration(a.Config.Agent.Interval), a.Config.Agent.Quiet,
a.Config.Agent.Hostname, time.Duration(a.Config.Agent.FlushInterval))

log.Printf("D! [agent] Initializing plugins")
err := a.initPlugins()
Expand Down Expand Up @@ -274,19 +274,19 @@ func (a *Agent) runInputs(
var wg sync.WaitGroup
for _, input := range unit.inputs {
// Overwrite agent interval if this plugin has its own.
interval := a.Config.Agent.Interval.Duration
interval := time.Duration(a.Config.Agent.Interval)
if input.Config.Interval != 0 {
interval = input.Config.Interval
}

// Overwrite agent precision if this plugin has its own.
precision := a.Config.Agent.Precision.Duration
precision := time.Duration(a.Config.Agent.Precision)
if input.Config.Precision != 0 {
precision = input.Config.Precision
}

// Overwrite agent collection_jitter if this plugin has its own.
jitter := a.Config.Agent.CollectionJitter.Duration
jitter := time.Duration(a.Config.Agent.CollectionJitter)
if input.Config.CollectionJitter != 0 {
jitter = input.Config.CollectionJitter
}
Expand Down Expand Up @@ -373,13 +373,13 @@ func (a *Agent) testRunInputs(
defer wg.Done()

// Overwrite agent interval if this plugin has its own.
interval := a.Config.Agent.Interval.Duration
interval := time.Duration(a.Config.Agent.Interval)
if input.Config.Interval != 0 {
interval = input.Config.Interval
}

// Overwrite agent precision if this plugin has its own.
precision := a.Config.Agent.Precision.Duration
precision := time.Duration(a.Config.Agent.Precision)
if input.Config.Precision != 0 {
precision = input.Config.Precision
}
Expand Down Expand Up @@ -611,8 +611,8 @@ func (a *Agent) runAggregators(
go func(agg *models.RunningAggregator) {
defer wg.Done()

interval := a.Config.Agent.Interval.Duration
precision := a.Config.Agent.Precision.Duration
interval := time.Duration(a.Config.Agent.Interval)
precision := time.Duration(a.Config.Agent.Precision)

acc := NewAccumulator(agg, unit.aggC)
acc.SetPrecision(getPrecision(precision, interval))
Expand Down Expand Up @@ -723,8 +723,8 @@ func (a *Agent) runOutputs(
var wg sync.WaitGroup

// Start flush loop
interval := a.Config.Agent.FlushInterval.Duration
jitter := a.Config.Agent.FlushJitter.Duration
interval := time.Duration(a.Config.Agent.FlushInterval)
jitter := time.Duration(a.Config.Agent.FlushJitter)

ctx, cancel := context.WithCancel(context.Background())

Expand Down
10 changes: 4 additions & 6 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,12 @@ func runAgent(ctx context.Context,
return errors.New("Error: no inputs found, did you provide a valid config file?")
}

if int64(c.Agent.Interval.Duration) <= 0 {
return fmt.Errorf("Agent interval must be positive, found %s",
c.Agent.Interval.Duration)
if int64(c.Agent.Interval) <= 0 {
return fmt.Errorf("Agent interval must be positive, found %v", c.Agent.Interval)
}

if int64(c.Agent.FlushInterval.Duration) <= 0 {
return fmt.Errorf("Agent flush_interval must be positive; found %s",
c.Agent.Interval.Duration)
if int64(c.Agent.FlushInterval) <= 0 {
return fmt.Errorf("Agent flush_interval must be positive; found %v", c.Agent.Interval)
}

ag, err := agent.NewAgent(c)
Expand Down
18 changes: 9 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func NewConfig() *Config {

// Agent defaults:
Agent: &AgentConfig{
Interval: internal.Duration{Duration: 10 * time.Second},
Interval: Duration(10 * time.Second),
RoundInterval: true,
FlushInterval: internal.Duration{Duration: 10 * time.Second},
FlushInterval: Duration(10 * time.Second),
LogTarget: "file",
LogfileRotationMaxArchives: 5,
},
Expand All @@ -111,7 +111,7 @@ func NewConfig() *Config {
// AgentConfig defines configuration that will be used by the Telegraf agent
type AgentConfig struct {
// Interval at which to gather information
Interval internal.Duration
Interval Duration

// RoundInterval rounds collection interval to 'interval'.
// ie, if Interval=10s then always collect on :00, :10, :20, etc.
Expand All @@ -123,22 +123,22 @@ type AgentConfig struct {
// when interval = "250ms", precision will be "1ms"
// Precision will NOT be used for service inputs. It is up to each individual
// service input to set the timestamp at the appropriate precision.
Precision internal.Duration
Precision Duration

// CollectionJitter is used to jitter the collection by a random amount.
// Each plugin will sleep for a random time within jitter before collecting.
// This can be used to avoid many plugins querying things like sysfs at the
// same time, which can have a measurable effect on the system.
CollectionJitter internal.Duration
CollectionJitter Duration

// FlushInterval is the Interval at which to flush data
FlushInterval internal.Duration
FlushInterval Duration

// FlushJitter Jitters the flush interval by a random amount.
// This is primarily to avoid large write spikes for users running a large
// number of telegraf instances.
// ie, a jitter of 5s and interval 10s means flushes will happen every 10-15s
FlushJitter internal.Duration
FlushJitter Duration

// MetricBatchSize is the maximum number of metrics that is wrote to an
// output plugin in one call.
Expand Down Expand Up @@ -178,11 +178,11 @@ type AgentConfig struct {

// The file will be rotated after the time interval specified. When set
// to 0 no time based rotation is performed.
LogfileRotationInterval internal.Duration `toml:"logfile_rotation_interval"`
LogfileRotationInterval Duration `toml:"logfile_rotation_interval"`

// The logfile will be rotated when it becomes larger than the specified
// size. When set to 0 no size based rotation is performed.
LogfileRotationMaxSize internal.Size `toml:"logfile_rotation_max_size"`
LogfileRotationMaxSize Size `toml:"logfile_rotation_max_size"`

// Maximum number of rotated archives to keep, any older logs are deleted.
// If set to -1, no archives are removed.
Expand Down
Loading

0 comments on commit 9853bf6

Please sign in to comment.