Moving the Duration wrapper to it's own package to break import loops.
This commit is contained in:
9
agent.go
9
agent.go
@@ -8,6 +8,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/influxdb/telegraf/duration"
|
||||
"github.com/influxdb/telegraf/outputs"
|
||||
"github.com/influxdb/telegraf/plugins"
|
||||
|
||||
@@ -29,10 +30,10 @@ type runningPlugin struct {
|
||||
type Agent struct {
|
||||
|
||||
// Interval at which to gather information
|
||||
Interval Duration
|
||||
Interval duration.Duration
|
||||
|
||||
// Interval at which to flush data
|
||||
FlushInterval Duration
|
||||
FlushInterval duration.Duration
|
||||
|
||||
// FlushRetries is the number of times to retry each data flush
|
||||
FlushRetries int
|
||||
@@ -62,8 +63,8 @@ type Agent struct {
|
||||
func NewAgent(config *Config) (*Agent, error) {
|
||||
agent := &Agent{
|
||||
Tags: make(map[string]string),
|
||||
Interval: Duration{10 * time.Second},
|
||||
FlushInterval: Duration{10 * time.Second},
|
||||
Interval: duration.Duration{10 * time.Second},
|
||||
FlushInterval: duration.Duration{10 * time.Second},
|
||||
FlushRetries: 2,
|
||||
UTC: true,
|
||||
Precision: "s",
|
||||
|
||||
17
config.go
17
config.go
@@ -15,23 +15,6 @@ import (
|
||||
"github.com/naoina/toml/ast"
|
||||
)
|
||||
|
||||
// Duration just wraps time.Duration
|
||||
type Duration struct {
|
||||
time.Duration
|
||||
}
|
||||
|
||||
// UnmarshalTOML parses the duration from the TOML config file
|
||||
func (d *Duration) UnmarshalTOML(b []byte) error {
|
||||
dur, err := time.ParseDuration(string(b[1 : len(b)-1]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.Duration = dur
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Config specifies the URL/user/password for the database that telegraf
|
||||
// will be logging to, as well as all the plugins that the user has
|
||||
// specified
|
||||
|
||||
20
duration/duration.go
Normal file
20
duration/duration.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package duration
|
||||
|
||||
import "time"
|
||||
|
||||
// Duration just wraps time.Duration
|
||||
type Duration struct {
|
||||
time.Duration
|
||||
}
|
||||
|
||||
// UnmarshalTOML parses the duration from the TOML config file
|
||||
func (d *Duration) UnmarshalTOML(b []byte) error {
|
||||
dur, err := time.ParseDuration(string(b[1 : len(b)-1]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.Duration = dur
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -9,13 +9,13 @@ import (
|
||||
"sort"
|
||||
|
||||
"github.com/influxdb/influxdb/client/v2"
|
||||
t "github.com/influxdb/telegraf"
|
||||
"github.com/influxdb/telegraf/duration"
|
||||
"github.com/influxdb/telegraf/outputs"
|
||||
)
|
||||
|
||||
type Datadog struct {
|
||||
Apikey string
|
||||
Timeout t.Duration
|
||||
Timeout duration.Duration
|
||||
|
||||
apiUrl string
|
||||
client *http.Client
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/influxdb/influxdb/client/v2"
|
||||
t "github.com/influxdb/telegraf"
|
||||
"github.com/influxdb/telegraf/duration"
|
||||
"github.com/influxdb/telegraf/outputs"
|
||||
)
|
||||
|
||||
@@ -22,7 +22,7 @@ type InfluxDB struct {
|
||||
Database string
|
||||
UserAgent string
|
||||
Precision string
|
||||
Timeout t.Duration
|
||||
Timeout duration.Duration
|
||||
|
||||
conns []client.Client
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
paho "git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git"
|
||||
"github.com/influxdb/influxdb/client/v2"
|
||||
t "github.com/influxdb/telegraf"
|
||||
"github.com/influxdb/telegraf/duration"
|
||||
"github.com/influxdb/telegraf/outputs"
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ type MQTT struct {
|
||||
Username string
|
||||
Password string
|
||||
Database string
|
||||
Timeout t.Duration
|
||||
Timeout duration.Duration
|
||||
TopicPrefix string
|
||||
|
||||
Client *paho.Client
|
||||
|
||||
Reference in New Issue
Block a user