Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/confighandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type InfluxConfig struct {
Token string
User string
Password string
Buffer time.Duration
}

// AdapterConfig describes device communication parameters
Expand Down
8 changes: 1 addition & 7 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ any type is considered valid.
"",
"InfluxDB password (optional)",
)
runCmd.PersistentFlags().Duration(
"influx-buffer",
time.Hour,
"Keep unsent data in memory for this long while InfluxDB is unavailable. Set 0 to disable.",
)

pflags := runCmd.PersistentFlags()

Expand All @@ -171,7 +166,7 @@ any type is considered valid.
bindPFlagsWithPrefix(pflags, "mqtt", "broker", "topic", "user", "password", "clientid", "qos", "homie")

// influx
bindPFlagsWithPrefix(pflags, "influx", "url", "database", "measurement", "organization", "token", "user", "password", "buffer")
bindPFlagsWithPrefix(pflags, "influx", "url", "database", "measurement", "organization", "token", "user", "password")
}

// checkVersion validates if updates are available
Expand Down Expand Up @@ -343,7 +338,6 @@ func run(cmd *cobra.Command, args []string) {
viper.GetString("influx.token"),
viper.GetString("influx.user"),
viper.GetString("influx.password"),
viper.GetDuration("influx.buffer"),
)

tee.AttachRunner(server.NewSnipRunner(influx.Run))
Expand Down
1 change: 0 additions & 1 deletion docs/mbmd_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ mbmd run [flags]
If the adapter is a TCP connection (identified by :port), the device type (SUNS) is ignored and
any type is considered valid.
Example: -d SDM:1@/dev/USB11 -d SMA:126@localhost:502
--influx-buffer duration Keep unsent data in memory for this long while InfluxDB is unavailable. Set 0 to disable. (default 1h0m0s)
--influx-database string InfluxDB database
--influx-measurement string InfluxDB measurement (default "data")
--influx-organization string InfluxDB organization
Expand Down
3 changes: 0 additions & 3 deletions mbmd.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mqtt:
topic: mbmd
user:
password:
buffer: 1h # keep unsent data in memory while influx is down, 0 to disable
clientid: mbmd
qos: 0
homie: homie
Expand All @@ -19,7 +18,6 @@ influx:
measurement: mbmd
user:
password:
buffer: 1h # keep unsent data in memory while influx is down, 0 to disable

# influxdb_v2 config
influx:
Expand All @@ -28,7 +26,6 @@ influx:
measurement: mbmd
organization:
token:
buffer: 1h # keep unsent data in memory while influx is down, 0 to disable

# adapters are referenced by device
adapters:
Expand Down
46 changes: 1 addition & 45 deletions server/influx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ import (
api "github.com/influxdata/influxdb-client-go/v2/api"
)

const (
// influxFlushInterval is how often points are sent to the database.
// Each flush creates one batch in the client's retry queue.
influxFlushInterval = time.Second
// influxBatchSize is the maximum number of points per write request
influxBatchSize = 5_000
// influxMaxRetryInterval caps the backoff between retries, so data
// is written soon after the database becomes available again.
influxMaxRetryInterval = 30 * time.Second
)

// Influx is an InfluxDB v2 publisher
type Influx struct {
client influxdb.Client
Expand All @@ -36,14 +25,13 @@ func NewInfluxClient(
token string,
user string,
password string,
buffer time.Duration,
) *Influx {
// InfluxDB v1 compatibility
if token == "" && user != "" {
token = fmt.Sprintf("%s:%s", user, password)
}

client := influxdb.NewClientWithOptions(url, token, influxOptions(buffer))
client := influxdb.NewClient(url, token)

if database == "" {
log.Fatal("influx: missing database")
Expand All @@ -59,38 +47,6 @@ func NewInfluxClient(
}
}

// influxOptions configures the client's in-memory retry buffer so that
// points are kept for the given duration while the database is unreachable.
//
// The client's defaults drop data almost immediately: the retry buffer
// limit is divided by the batch size (50,000 / 5,000 = 10 batches), and with
// one batch per flush interval that only holds ~10s of data. In addition,
// batches expire after 3 minutes and are discarded after 5 retries.
//
// A buffer of 0 disables retrying, so failed writes are dropped.
func influxOptions(buffer time.Duration) *influxdb.Options {
opts := influxdb.DefaultOptions().
SetFlushInterval(uint(influxFlushInterval.Milliseconds())).
SetBatchSize(influxBatchSize)

if buffer <= 0 {
return opts.SetMaxRetries(0)
}

// one batch is created per flush interval
batches := uint(buffer/influxFlushInterval) + 1

return opts.
// the limit is given in points but enforced in batches (limit / batch size)
SetRetryBufferLimit(batches * influxBatchSize).
// batches are dropped once older than this
SetMaxRetryTime(uint(buffer.Milliseconds())).
SetMaxRetryInterval(uint(influxMaxRetryInterval.Milliseconds())).
// retries are bounded by MaxRetryTime, not by count. Retry intervals
// are at least 5s, so this can not be reached before batches expire.
SetMaxRetries(uint(buffer / time.Second))
}

// Run Influx publisher
func (m *Influx) Run(in <-chan QuerySnip) {
// log errors
Expand Down
111 changes: 0 additions & 111 deletions server/influx_test.go

This file was deleted.

Loading