diff --git a/.circleci/config.yml b/.circleci/config.yml index 83af331a0d61b..7ad01a38e8367 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ executors: working_directory: '/go/src/github.com/influxdata/telegraf' resource_class: large docker: - - image: 'quay.io/influxdb/telegraf-ci:1.23.1' + - image: 'quay.io/influxdb/telegraf-ci:1.23.2' environment: GOFLAGS: -p=4 mac: diff --git a/.github/workflows/readme-linter.yml b/.github/workflows/readme-linter.yml index ae58f33eac2d0..86007a14376c6 100644 --- a/.github/workflows/readme-linter.yml +++ b/.github/workflows/readme-linter.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: '1.23.1' + go-version: '1.23.2' - uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.golangci.yml b/.golangci.yml index e5a4f7c95c14f..31859c348839a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -254,6 +254,7 @@ linters-settings: - name: constant-logical-expr - name: context-as-argument - name: context-keys-type + - name: datarace - name: deep-exit - name: defer - name: dot-imports @@ -289,6 +290,23 @@ linters-settings: - name: receiver-naming - name: redefines-builtin-id - name: redundant-import-alias + - name: string-format + arguments: + - - 'fmt.Errorf[0]' + - '/^([^A-Z]|$)/' + - 'Error string must not start with a capital letter.' + - - 'fmt.Errorf[0]' + - '/(^|[^\.!?])$/' + - 'Error string must not end in punctuation.' + - - 'errors.New[0]' + - '/^([^A-Z]|$)/' + - 'Error string must not start with a capital letter.' + - - 'errors.New[0]' + - '/(^|[^\.!?])$/' + - 'Error string must not end in punctuation.' + - - 'panic' + - '/^[^\n]*$/' + - 'Must not contain line breaks.' - name: string-of-int - name: struct-tag - name: superfluous-else diff --git a/CHANGELOG.md b/CHANGELOG.md index 416dff1f69ea9..5236850fd69a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog -## Unreleased +## v1.32.1 [2024-10-07] ### Important Changes @@ -10,6 +10,43 @@ requeueing. This way, those messages are not lost and can optionally be handled using a dead-letter exchange by other means. +### Bugfixes + +- [#15969](https://github.com/influxdata/telegraf/pull/15969) `agent` Fix buffer not flushing if all metrics are written +- [#15937](https://github.com/influxdata/telegraf/pull/15937) `config` Correctly print removal version info +- [#15900](https://github.com/influxdata/telegraf/pull/15900) `common.http` Keep timeout after creating oauth client +- [#15796](https://github.com/influxdata/telegraf/pull/15796) `inputs.amqp_consumer` NACKing messages on non-delivery related errors +- [#15923](https://github.com/influxdata/telegraf/pull/15923) `inputs.cisco_telemetry_mdt` Handle NXOS DME subtree telemetry format +- [#15907](https://github.com/influxdata/telegraf/pull/15907) `inputs.consul` Move config checking to Init method +- [#15982](https://github.com/influxdata/telegraf/pull/15982) `inputs.influxdb_v2_listener` Fix concurrent read/write dict +- [#15960](https://github.com/influxdata/telegraf/pull/15960) `inputs.vsphere` Add tags to VSAN ESA disks +- [#15921](https://github.com/influxdata/telegraf/pull/15921) `parsers.avro` Add mutex to cache access +- [#15965](https://github.com/influxdata/telegraf/pull/15965) `processors.aws_ec2` Remove leading slash and cancel worker only if it exists + +### Dependency Updates + +- [#15932](https://github.com/influxdata/telegraf/pull/15932) `deps` Bump cloud.google.com/go/monitoring from 1.20.2 to 1.21.1 +- [#15863](https://github.com/influxdata/telegraf/pull/15863) `deps` Bump github.com/Azure/azure-kusto-go from 0.15.3 to 0.16.1 +- [#15862](https://github.com/influxdata/telegraf/pull/15862) `deps` Bump github.com/Azure/azure-sdk-for-go/sdk/azcore from 1.13.0 to 1.14.0 +- [#15957](https://github.com/influxdata/telegraf/pull/15957) `deps` Bump github.com/aws/aws-sdk-go-v2/feature/ec2/imds from 1.16.12 to 1.16.14 +- [#15859](https://github.com/influxdata/telegraf/pull/15859) `deps` Bump github.com/aws/aws-sdk-go-v2/service/dynamodb from 1.34.4 to 1.34.9 +- [#15931](https://github.com/influxdata/telegraf/pull/15931) `deps` Bump github.com/boschrexroth/ctrlx-datalayer-golang from 1.3.0 to 1.3.1 +- [#15890](https://github.com/influxdata/telegraf/pull/15890) `deps` Bump github.com/harlow/kinesis-consumer from v0.3.6-0.20240606153816-553e2392fdf3 to v0.3.6-0.20240916192723-43900507c911 +- [#15904](https://github.com/influxdata/telegraf/pull/15904) `deps` Bump github.com/netsampler/goflow2/v2 from 2.1.5 to 2.2.1 +- [#15903](https://github.com/influxdata/telegraf/pull/15903) `deps` Bump github.com/p4lang/p4runtime from 1.3.0 to 1.4.0 +- [#15905](https://github.com/influxdata/telegraf/pull/15905) `deps` Bump github.com/prometheus/client_golang from 1.20.2 to 1.20.3 +- [#15930](https://github.com/influxdata/telegraf/pull/15930) `deps` Bump github.com/prometheus/client_golang from 1.20.3 to 1.20.4 +- [#15962](https://github.com/influxdata/telegraf/pull/15962) `deps` Bump github.com/prometheus/common from 0.55.0 to 0.60.0 +- [#15860](https://github.com/influxdata/telegraf/pull/15860) `deps` Bump github.com/snowflakedb/gosnowflake from 1.10.0 to 1.11.1 +- [#15954](https://github.com/influxdata/telegraf/pull/15954) `deps` Bump github.com/srebhan/protobufquery from 0.0.0-20230803132024-ae4c0d878e55 to 1.0.1 +- [#15929](https://github.com/influxdata/telegraf/pull/15929) `deps` Bump go.mongodb.org/mongo-driver from 1.16.0 to 1.17.0 +- [#15902](https://github.com/influxdata/telegraf/pull/15902) `deps` Bump golang.org/x/mod from 0.19.0 to 0.21.0 +- [#15955](https://github.com/influxdata/telegraf/pull/15955) `deps` Bump golang.org/x/oauth2 from 0.21.0 to 0.23.0 +- [#15861](https://github.com/influxdata/telegraf/pull/15861) `deps` Bump golang.org/x/term from 0.23.0 to 0.24.0 +- [#15856](https://github.com/influxdata/telegraf/pull/15856) `deps` Bump golangci-lint from v1.60.3 to v1.61.0 +- [#15933](https://github.com/influxdata/telegraf/pull/15933) `deps` Bump k8s.io/apimachinery from 0.30.1 to 0.31.1 +- [#15901](https://github.com/influxdata/telegraf/pull/15901) `deps` Bump modernc.org/sqlite from 1.32.0 to 1.33.1 + ## v1.32.0 [2024-09-09] ### Important Changes diff --git a/Makefile b/Makefile index a243a86617b75..f591ed8e992d9 100644 --- a/Makefile +++ b/Makefile @@ -257,8 +257,8 @@ plugins/parsers/influx/machine.go: plugins/parsers/influx/machine.go.rl .PHONY: ci ci: - docker build -t quay.io/influxdb/telegraf-ci:1.23.1 - < scripts/ci.docker - docker push quay.io/influxdb/telegraf-ci:1.23.1 + docker build -t quay.io/influxdb/telegraf-ci:1.23.2 - < scripts/ci.docker + docker push quay.io/influxdb/telegraf-ci:1.23.2 .PHONY: install install: $(buildbin) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index fe29de3c9f16a..717efdb9fdec2 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -343,10 +343,10 @@ func (t *Telegraf) runAgent(ctx context.Context, reloadConfig bool) error { } if !(t.test || t.testWait != 0) && len(c.Outputs) == 0 { - return errors.New("no outputs found, did you provide a valid config file?") + return errors.New("no outputs found, probably invalid config file provided") } if t.plugindDir == "" && len(c.Inputs) == 0 { - return errors.New("no inputs found, did you provide a valid config file?") + return errors.New("no inputs found, probably invalid config file provided") } if int64(c.Agent.Interval) <= 0 { diff --git a/config/config.go b/config/config.go index 2b1cf117c0153..008316fc5a6aa 100644 --- a/config/config.go +++ b/config/config.go @@ -1488,6 +1488,8 @@ func (c *Config) buildInput(name string, tbl *ast.Table) (*models.InputConfig, e cp.CollectionJitter, _ = c.getFieldDuration(tbl, "collection_jitter") cp.CollectionOffset, _ = c.getFieldDuration(tbl, "collection_offset") cp.StartupErrorBehavior = c.getFieldString(tbl, "startup_error_behavior") + cp.TimeSource = c.getFieldString(tbl, "time_source") + cp.MeasurementPrefix = c.getFieldString(tbl, "name_prefix") cp.MeasurementSuffix = c.getFieldString(tbl, "name_suffix") cp.NameOverride = c.getFieldString(tbl, "name_override") diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 313c6fa91163a..c87c6e233e5a5 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -396,6 +396,14 @@ Parameters that can be used with any input plugin: When this value is set on a service input, multiple events occurring at the same timestamp may be merged by the output database. +- **time_source**: + Specifies the source of the timestamp on metrics. Possible values are: + - `metric` will not alter the metric (default) + - `collection_start` sets the timestamp to when collection started + - `collection_end` set the timestamp to when collection finished + + `time_source` will NOT be used for service inputs. It is up to each individual + service input to set the timestamp. - **collection_jitter**: Overrides the `collection_jitter` setting of the [agent][Agent] for the plugin. Collection jitter is used to jitter the collection by a random diff --git a/go.mod b/go.mod index fe6be89edf12e..5dc959299af5e 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/influxdata/telegraf go 1.23.0 require ( - cloud.google.com/go/bigquery v1.62.0 - cloud.google.com/go/monitoring v1.20.2 - cloud.google.com/go/pubsub v1.40.0 + cloud.google.com/go/bigquery v1.63.1 + cloud.google.com/go/monitoring v1.21.1 + cloud.google.com/go/pubsub v1.42.0 cloud.google.com/go/storage v1.43.0 collectd.org v0.6.0 github.com/99designs/keyring v1.2.2 @@ -44,18 +44,18 @@ require ( github.com/aristanetworks/goarista v0.0.0-20190325233358-a123909ec740 github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 github.com/awnumar/memguard v0.22.5 - github.com/aws/aws-sdk-go-v2 v1.31.0 + github.com/aws/aws-sdk-go-v2 v1.32.1 github.com/aws/aws-sdk-go-v2/config v1.27.27 github.com/aws/aws-sdk-go-v2/credentials v1.17.27 github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14 - github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.40.4 + github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.42.1 github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.38.0 github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.9 github.com/aws/aws-sdk-go-v2/service/ec2 v1.162.1 github.com/aws/aws-sdk-go-v2/service/kinesis v1.29.3 github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 github.com/aws/aws-sdk-go-v2/service/timestreamwrite v1.27.4 - github.com/aws/smithy-go v1.21.0 + github.com/aws/smithy-go v1.22.0 github.com/benbjohnson/clock v1.3.5 github.com/blues/jsonata-go v1.5.4 github.com/bmatcuk/doublestar/v3 v3.0.0 @@ -106,9 +106,9 @@ require ( github.com/gorcon/rcon v1.3.5 github.com/gorilla/mux v1.8.1 github.com/gorilla/websocket v1.5.3 - github.com/gosnmp/gosnmp v1.37.0 + github.com/gosnmp/gosnmp v1.38.0 github.com/grid-x/modbus v0.0.0-20240503115206-582f2ab60a18 - github.com/gwos/tcg/sdk v0.0.0-20231124052037-1e832b843240 + github.com/gwos/tcg/sdk v0.0.0-20240830123415-f8a34bba6358 github.com/harlow/kinesis-consumer v0.3.6-0.20240916192723-43900507c911 github.com/hashicorp/consul/api v1.29.2 github.com/hashicorp/go-uuid v1.0.3 @@ -180,11 +180,11 @@ require ( github.com/sensu/sensu-go/api/core/v2 v2.16.0 github.com/shirou/gopsutil/v3 v3.24.4 github.com/showwin/speedtest-go v1.7.9 - github.com/signalfx/golib/v3 v3.3.53 + github.com/signalfx/golib/v3 v3.3.54 github.com/sijms/go-ora/v2 v2.8.19 github.com/sirupsen/logrus v1.9.3 github.com/sleepinggenius2/gosmi v0.4.4 - github.com/snowflakedb/gosnowflake v1.11.1 + github.com/snowflakedb/gosnowflake v1.11.2 github.com/srebhan/cborquery v1.0.1 github.com/srebhan/protobufquery v1.0.1 github.com/stretchr/testify v1.9.0 @@ -222,9 +222,9 @@ require ( golang.org/x/text v0.18.0 golang.zx2c4.com/wireguard/wgctrl v0.0.0-20211230205640-daad0b7ba671 gonum.org/v1/gonum v0.15.1 - google.golang.org/api v0.189.0 - google.golang.org/genproto/googleapis/api v0.0.0-20240722135656-d784300faade - google.golang.org/grpc v1.65.0 + google.golang.org/api v0.197.0 + google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 + google.golang.org/grpc v1.66.2 google.golang.org/protobuf v1.34.2 gopkg.in/gorethink/gorethink.v3 v3.0.5 gopkg.in/olivere/elastic.v5 v5.0.86 @@ -238,11 +238,11 @@ require ( ) require ( - cloud.google.com/go v0.115.0 // indirect - cloud.google.com/go/auth v0.7.2 // indirect - cloud.google.com/go/auth/oauth2adapt v0.2.3 // indirect + cloud.google.com/go v0.115.1 // indirect + cloud.google.com/go/auth v0.9.3 // indirect + cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect cloud.google.com/go/compute/metadata v0.5.0 // indirect - cloud.google.com/go/iam v1.1.10 // indirect + cloud.google.com/go/iam v1.2.1 // indirect code.cloudfoundry.org/clock v1.0.0 // indirect dario.cat/mergo v1.0.0 // indirect filippo.io/edwards25519 v1.1.0 // indirect @@ -280,8 +280,8 @@ require ( github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 // indirect github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.13.7 // indirect github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.15 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.20 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.20 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 // indirect github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.20.1 // indirect @@ -350,8 +350,8 @@ require ( github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/gofuzz v1.2.0 // indirect - github.com/google/s2a-go v0.1.7 // indirect - github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect + github.com/google/s2a-go v0.1.8 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect github.com/googleapis/gax-go/v2 v2.13.0 // indirect github.com/gorilla/securecookie v1.1.2 // indirect github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect @@ -483,22 +483,22 @@ require ( go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/collector/consumer v0.101.0 // indirect go.opentelemetry.io/collector/semconv v0.105.0 // indirect - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect - go.opentelemetry.io/otel v1.28.0 // indirect - go.opentelemetry.io/otel/metric v1.28.0 // indirect - go.opentelemetry.io/otel/sdk v1.28.0 // indirect - go.opentelemetry.io/otel/trace v1.28.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect + go.opentelemetry.io/otel v1.29.0 // indirect + go.opentelemetry.io/otel/metric v1.29.0 // indirect + go.opentelemetry.io/otel/sdk v1.29.0 // indirect + go.opentelemetry.io/otel/trace v1.29.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect - golang.org/x/time v0.5.0 // indirect - golang.org/x/tools v0.23.0 // indirect - golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect + golang.org/x/time v0.6.0 // indirect + golang.org/x/tools v0.24.0 // indirect + golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect golang.zx2c4.com/wireguard v0.0.0-20211209221555-9c9e7e272434 // indirect - google.golang.org/genproto v0.0.0-20240722135656-d784300faade // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade // indirect + google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect gopkg.in/fatih/pool.v2 v2.0.0 // indirect gopkg.in/fsnotify.v1 v1.4.7 // indirect gopkg.in/inf.v0 v0.9.1 // indirect diff --git a/go.sum b/go.sum index d870633cd3b57..ede21f48498fe 100644 --- a/go.sum +++ b/go.sum @@ -36,8 +36,8 @@ cloud.google.com/go v0.104.0/go.mod h1:OO6xxXdJyvuJPcEPBLN9BJPD+jep5G1+2U5B5gkRY cloud.google.com/go v0.105.0/go.mod h1:PrLgOJNe5nfE9UMxKxgXj4mD3voiP+YQ6gdt6KMFOKM= cloud.google.com/go v0.107.0/go.mod h1:wpc2eNrD7hXUTy8EKS10jkxpZBjASrORK7goS+3YX2I= cloud.google.com/go v0.110.0/go.mod h1:SJnCLqQ0FCFGSZMUNUf84MV3Aia54kn7pi8st7tMzaY= -cloud.google.com/go v0.115.0 h1:CnFSK6Xo3lDYRoBKEcAtia6VSC837/ZkJuRduSFnr14= -cloud.google.com/go v0.115.0/go.mod h1:8jIM5vVgoAEoiVxQ/O4BFTfHqulPZgs/ufEzMcFMdWU= +cloud.google.com/go v0.115.1 h1:Jo0SM9cQnSkYfp44+v+NQXHpcHqlnRJk2qxh6yvxxxQ= +cloud.google.com/go v0.115.1/go.mod h1:DuujITeaufu3gL68/lOFIirVNJwQeyf5UXyi+Wbgknc= cloud.google.com/go/accessapproval v1.4.0/go.mod h1:zybIuC3KpDOvotz59lFe5qxRZx6C75OtwbisN56xYB4= cloud.google.com/go/accessapproval v1.5.0/go.mod h1:HFy3tuiGvMdcd/u+Cu5b9NkO1pEICJ46IR82PoUdplw= cloud.google.com/go/accessapproval v1.6.0/go.mod h1:R0EiYnwV5fsRFiKZkPHr6mwyk2wxUJ30nL4j2pcFY2E= @@ -99,10 +99,10 @@ cloud.google.com/go/assuredworkloads v1.7.0/go.mod h1:z/736/oNmtGAyU47reJgGN+KVo cloud.google.com/go/assuredworkloads v1.8.0/go.mod h1:AsX2cqyNCOvEQC8RMPnoc0yEarXQk6WEKkxYfL6kGIo= cloud.google.com/go/assuredworkloads v1.9.0/go.mod h1:kFuI1P78bplYtT77Tb1hi0FMxM0vVpRC7VVoJC3ZoT0= cloud.google.com/go/assuredworkloads v1.10.0/go.mod h1:kwdUQuXcedVdsIaKgKTp9t0UJkE5+PAVNhdQm4ZVq2E= -cloud.google.com/go/auth v0.7.2 h1:uiha352VrCDMXg+yoBtaD0tUF4Kv9vrtrWPYXwutnDE= -cloud.google.com/go/auth v0.7.2/go.mod h1:VEc4p5NNxycWQTMQEDQF0bd6aTMb6VgYDXEwiJJQAbs= -cloud.google.com/go/auth/oauth2adapt v0.2.3 h1:MlxF+Pd3OmSudg/b1yZ5lJwoXCEaeedAguodky1PcKI= -cloud.google.com/go/auth/oauth2adapt v0.2.3/go.mod h1:tMQXOfZzFuNuUxOypHlQEXgdfX5cuhwU+ffUuXRJE8I= +cloud.google.com/go/auth v0.9.3 h1:VOEUIAADkkLtyfr3BLa3R8Ed/j6w1jTBmARx+wb5w5U= +cloud.google.com/go/auth v0.9.3/go.mod h1:7z6VY+7h3KUdRov5F1i8NDP5ZzWKYmEPO842BgCsmTk= +cloud.google.com/go/auth/oauth2adapt v0.2.4 h1:0GWE/FUsXhf6C+jAkWgYm7X9tK8cuEIfy19DBn6B6bY= +cloud.google.com/go/auth/oauth2adapt v0.2.4/go.mod h1:jC/jOpwFP6JBxhB3P5Rr0a9HLMC/Pe3eaL4NmdvqPtc= cloud.google.com/go/automl v1.5.0/go.mod h1:34EjfoFGMZ5sgJ9EoLsRtdPSNZLcfflJR39VbVNS2M0= cloud.google.com/go/automl v1.6.0/go.mod h1:ugf8a6Fx+zP0D59WLhqgTDsQI9w07o64uf/Is3Nh5p8= cloud.google.com/go/automl v1.7.0/go.mod h1:RL9MYCCsJEOmt0Wf3z9uzG0a7adTT1fe+aObgSpkCt8= @@ -131,8 +131,8 @@ cloud.google.com/go/bigquery v1.47.0/go.mod h1:sA9XOgy0A8vQK9+MWhEQTY6Tix87M/Zur cloud.google.com/go/bigquery v1.48.0/go.mod h1:QAwSz+ipNgfL5jxiaK7weyOhzdoAy1zFm0Nf1fysJac= cloud.google.com/go/bigquery v1.49.0/go.mod h1:Sv8hMmTFFYBlt/ftw2uN6dFdQPzBlREY9yBh7Oy7/4Q= cloud.google.com/go/bigquery v1.50.0/go.mod h1:YrleYEh2pSEbgTBZYMJ5SuSr0ML3ypjRB1zgf7pvQLU= -cloud.google.com/go/bigquery v1.62.0 h1:SYEA2f7fKqbSRRBHb7g0iHTtZvtPSPYdXfmqsjpsBwo= -cloud.google.com/go/bigquery v1.62.0/go.mod h1:5ee+ZkF1x/ntgCsFQJAQTM3QkAZOecfCmvxhkJsWRSA= +cloud.google.com/go/bigquery v1.63.1 h1:/6syiWrSpardKNxdvldS5CUTRJX1iIkSPXCjLjiGL+g= +cloud.google.com/go/bigquery v1.63.1/go.mod h1:ufaITfroCk17WTqBhMpi8CRjsfHjMX07pDrQaRKKX2o= cloud.google.com/go/billing v1.4.0/go.mod h1:g9IdKBEFlItS8bTtlrZdVLWSSdSyFUZKXNS02zKMOZY= cloud.google.com/go/billing v1.5.0/go.mod h1:mztb1tBc3QekhjSgmpf/CV4LzWXLzCArwpLmP2Gm88s= cloud.google.com/go/billing v1.6.0/go.mod h1:WoXzguj+BeHXPbKfNWkqVtDdzORazmCjraY+vrxcyvI= @@ -206,8 +206,8 @@ cloud.google.com/go/datacatalog v1.8.0/go.mod h1:KYuoVOv9BM8EYz/4eMFxrr4DUKhGIOX cloud.google.com/go/datacatalog v1.8.1/go.mod h1:RJ58z4rMp3gvETA465Vg+ag8BGgBdnRPEMMSTr5Uv+M= cloud.google.com/go/datacatalog v1.12.0/go.mod h1:CWae8rFkfp6LzLumKOnmVh4+Zle4A3NXLzVJ1d1mRm0= cloud.google.com/go/datacatalog v1.13.0/go.mod h1:E4Rj9a5ZtAxcQJlEBTLgMTphfP11/lNaAshpoBgemX8= -cloud.google.com/go/datacatalog v1.20.3 h1:lzMtWaUlaz9Bd9anvq2KBZwcFujzhVuxhIz1MsqRJv8= -cloud.google.com/go/datacatalog v1.20.3/go.mod h1:AKC6vAy5urnMg5eJK3oUjy8oa5zMbiY33h125l8lmlo= +cloud.google.com/go/datacatalog v1.22.1 h1:i0DyKb/o7j+0vgaFtimcRFjYsD6wFw1jpnODYUyiYRs= +cloud.google.com/go/datacatalog v1.22.1/go.mod h1:MscnJl9B2lpYlFoxRjicw19kFTwEke8ReKL5Y/6TWg8= cloud.google.com/go/dataflow v0.6.0/go.mod h1:9QwV89cGoxjjSR9/r7eFDqqjtvbKxAK2BaYU6PVk9UM= cloud.google.com/go/dataflow v0.7.0/go.mod h1:PX526vb4ijFMesO1o202EaUmouZKBpjHsTlCtB4parQ= cloud.google.com/go/dataflow v0.8.0/go.mod h1:Rcf5YgTKPtQyYz8bLYhFoIV/vP39eL7fWNcSOyFfLJE= @@ -322,8 +322,8 @@ cloud.google.com/go/iam v0.8.0/go.mod h1:lga0/y3iH6CX7sYqypWJ33hf7kkfXJag67naqGE cloud.google.com/go/iam v0.11.0/go.mod h1:9PiLDanza5D+oWFZiH1uG+RnRCfEGKoyl6yo4cgWZGY= cloud.google.com/go/iam v0.12.0/go.mod h1:knyHGviacl11zrtZUoDuYpDgLjvr28sLQaG0YB2GYAY= cloud.google.com/go/iam v0.13.0/go.mod h1:ljOg+rcNfzZ5d6f1nAUJ8ZIxOaZUVoS14bKCtaLZ/D0= -cloud.google.com/go/iam v1.1.10 h1:ZSAr64oEhQSClwBL670MsJAW5/RLiC6kfw3Bqmd5ZDI= -cloud.google.com/go/iam v1.1.10/go.mod h1:iEgMq62sg8zx446GCaijmA2Miwg5o3UbO+nI47WHJps= +cloud.google.com/go/iam v1.2.1 h1:QFct02HRb7H12J/3utj0qf5tobFh9V4vR6h9eX5EBRU= +cloud.google.com/go/iam v1.2.1/go.mod h1:3VUIJDPpwT6p/amXRC5GY8fCCh70lxPygguVtI0Z4/g= cloud.google.com/go/iap v1.4.0/go.mod h1:RGFwRJdihTINIe4wZ2iCP0zF/qu18ZwyKxrhMhygBEc= cloud.google.com/go/iap v1.5.0/go.mod h1:UH/CGgKd4KyohZL5Pt0jSKE4m3FR51qg6FKQ/z/Ix9A= cloud.google.com/go/iap v1.6.0/go.mod h1:NSuvI9C/j7UdjGjIde7t7HBz+QTwBcapPE07+sSRcLk= @@ -343,8 +343,8 @@ cloud.google.com/go/kms v1.8.0/go.mod h1:4xFEhYFqvW+4VMELtZyxomGSYtSQKzM178ylFW4 cloud.google.com/go/kms v1.9.0/go.mod h1:qb1tPTgfF9RQP8e1wq4cLFErVuTJv7UsSC915J8dh3w= cloud.google.com/go/kms v1.10.0/go.mod h1:ng3KTUtQQU9bPX3+QGLsflZIHlkbn8amFAMY63m8d24= cloud.google.com/go/kms v1.10.1/go.mod h1:rIWk/TryCkR59GMC3YtHtXeLzd634lBbKenvyySAyYI= -cloud.google.com/go/kms v1.18.3 h1:8+Z2S4bQDSCdghB5ZA5dVDDJTLmnkRlowtFiXqMFd74= -cloud.google.com/go/kms v1.18.3/go.mod h1:y/Lcf6fyhbdn7MrG1VaDqXxM8rhOBc5rWcWAhcvZjQU= +cloud.google.com/go/kms v1.19.0 h1:x0OVJDl6UH1BSX4THKlMfdcFWoE4ruh90ZHuilZekrU= +cloud.google.com/go/kms v1.19.0/go.mod h1:e4imokuPJUc17Trz2s6lEXFDt8bgDmvpVynH39bdrHM= cloud.google.com/go/language v1.4.0/go.mod h1:F9dRpNFQmJbkaop6g0JhSBXCNlO90e1KWx5iDdxbWic= cloud.google.com/go/language v1.6.0/go.mod h1:6dJ8t3B+lUYfStgls25GusK04NLh3eDLQnWM3mdEbhI= cloud.google.com/go/language v1.7.0/go.mod h1:DJ6dYN/W+SQOjF8e1hLQXMF21AkH2w9wiPzPCJa2MIE= @@ -358,8 +358,8 @@ cloud.google.com/go/logging v1.7.0/go.mod h1:3xjP2CjkM3ZkO73aj4ASA5wRPGGCRrPIAeN cloud.google.com/go/longrunning v0.1.1/go.mod h1:UUFxuDWkv22EuY93jjmDMFT5GPQKeFVJBIF6QlTqdsE= cloud.google.com/go/longrunning v0.3.0/go.mod h1:qth9Y41RRSUE69rDcOn6DdK3HfQfsUI0YSmW3iIlLJc= cloud.google.com/go/longrunning v0.4.1/go.mod h1:4iWDqhBZ70CvZ6BfETbvam3T8FMvLK+eFj0E6AaRQTo= -cloud.google.com/go/longrunning v0.5.9 h1:haH9pAuXdPAMqHvzX0zlWQigXT7B0+CL4/2nXXdBo5k= -cloud.google.com/go/longrunning v0.5.9/go.mod h1:HD+0l9/OOW0za6UWdKJtXoFAX/BGg/3Wj8p10NeWF7c= +cloud.google.com/go/longrunning v0.6.1 h1:lOLTFxYpr8hcRtcwWir5ITh1PAKUD/sG2lKrTSYjyMc= +cloud.google.com/go/longrunning v0.6.1/go.mod h1:nHISoOZpBcmlwbJmiVk5oDRz0qG/ZxPynEGs1iZ79s0= cloud.google.com/go/managedidentities v1.3.0/go.mod h1:UzlW3cBOiPrzucO5qWkNkh0w33KFtBJU281hacNvsdE= cloud.google.com/go/managedidentities v1.4.0/go.mod h1:NWSBYbEMgqmbZsLIyKvxrYbtqOsxY1ZrGM+9RgDqInM= cloud.google.com/go/managedidentities v1.5.0/go.mod h1:+dWcZ0JlUmpuxpIDfyP5pP5y0bLdRwOS4Lp7gMni/LA= @@ -383,8 +383,8 @@ cloud.google.com/go/monitoring v1.7.0/go.mod h1:HpYse6kkGo//7p6sT0wsIC6IBDET0RhI cloud.google.com/go/monitoring v1.8.0/go.mod h1:E7PtoMJ1kQXWxPjB6mv2fhC5/15jInuulFdYYtlcvT4= cloud.google.com/go/monitoring v1.12.0/go.mod h1:yx8Jj2fZNEkL/GYZyTLS4ZtZEZN8WtDEiEqG4kLK50w= cloud.google.com/go/monitoring v1.13.0/go.mod h1:k2yMBAB1H9JT/QETjNkgdCGD9bPF712XiLTVr+cBrpw= -cloud.google.com/go/monitoring v1.20.2 h1:B/L+xrw9PYO7ywh37sgnjI/6dzEE+yQTAwfytDcpPto= -cloud.google.com/go/monitoring v1.20.2/go.mod h1:36rpg/7fdQ7NX5pG5x1FA7cXTVXusOp6Zg9r9e1+oek= +cloud.google.com/go/monitoring v1.21.1 h1:zWtbIoBMnU5LP9A/fz8LmWMGHpk4skdfeiaa66QdFGc= +cloud.google.com/go/monitoring v1.21.1/go.mod h1:Rj++LKrlht9uBi8+Eb530dIrzG/cU/lB8mt+lbeFK1c= cloud.google.com/go/networkconnectivity v1.4.0/go.mod h1:nOl7YL8odKyAOtzNX73/M5/mGZgqqMeryi6UPZTk/rA= cloud.google.com/go/networkconnectivity v1.5.0/go.mod h1:3GzqJx7uhtlM3kln0+x5wyFvuVH1pIBJjhCpjzSt75o= cloud.google.com/go/networkconnectivity v1.6.0/go.mod h1:OJOoEXW+0LAxHh89nXd64uGG+FbQoeH8DtxCHVOMlaM= @@ -442,8 +442,8 @@ cloud.google.com/go/pubsub v1.26.0/go.mod h1:QgBH3U/jdJy/ftjPhTkyXNj543Tin1pRYcd cloud.google.com/go/pubsub v1.27.1/go.mod h1:hQN39ymbV9geqBnfQq6Xf63yNhUAhv9CZhzp5O6qsW0= cloud.google.com/go/pubsub v1.28.0/go.mod h1:vuXFpwaVoIPQMGXqRyUQigu/AX1S3IWugR9xznmcXX8= cloud.google.com/go/pubsub v1.30.0/go.mod h1:qWi1OPS0B+b5L+Sg6Gmc9zD1Y+HaM0MdUr7LsupY1P4= -cloud.google.com/go/pubsub v1.40.0 h1:0LdP+zj5XaPAGtWr2V6r88VXJlmtaB/+fde1q3TU8M0= -cloud.google.com/go/pubsub v1.40.0/go.mod h1:BVJI4sI2FyXp36KFKvFwcfDRDfR8MiLT8mMhmIhdAeA= +cloud.google.com/go/pubsub v1.42.0 h1:PVTbzorLryFL5ue8esTS2BfehUs0ahyNOY9qcd+HMOs= +cloud.google.com/go/pubsub v1.42.0/go.mod h1:KADJ6s4MbTwhXmse/50SebEhE4SmUwHi48z3/dHar1Y= cloud.google.com/go/pubsublite v1.5.0/go.mod h1:xapqNQ1CuLfGi23Yda/9l4bBCKz/wC3KIJ5gKcxveZg= cloud.google.com/go/pubsublite v1.6.0/go.mod h1:1eFCS0U11xlOuMFV/0iBqw3zP12kddMeCbj/F3FSj9k= cloud.google.com/go/pubsublite v1.7.0/go.mod h1:8hVMwRXfDfvGm3fahVbtDbiLePT3gpoiJYJY+vxWxVM= @@ -859,8 +859,8 @@ github.com/aws/aws-sdk-go-v2 v1.8.1/go.mod h1:xEFuWz+3TYdlPRuo+CqATbeDWIWyaT5uAP github.com/aws/aws-sdk-go-v2 v1.9.0/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4= github.com/aws/aws-sdk-go-v2 v1.11.2/go.mod h1:SQfA+m2ltnu1cA0soUkj4dRSsmITiVQUJvBIZjzfPyQ= github.com/aws/aws-sdk-go-v2 v1.18.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw= -github.com/aws/aws-sdk-go-v2 v1.31.0 h1:3V05LbxTSItI5kUqNwhJrrrY1BAXxXt0sN0l72QmG5U= -github.com/aws/aws-sdk-go-v2 v1.31.0/go.mod h1:ztolYtaEUtdpf9Wftr31CJfLVjOnD/CVRkKOOYgF8hA= +github.com/aws/aws-sdk-go-v2 v1.32.1 h1:8WuZ43ytA+TV6QEPT/R23mr7pWyI7bSSiEHdt9BS2Pw= +github.com/aws/aws-sdk-go-v2 v1.32.1/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 h1:70PVAiL15/aBMh5LThwgXdSQorVr91L127ttckI9QQU= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4/go.mod h1:/MQxMqci8tlqDH+pjmoLu1i0tbWCUP1hhyMRuFxpQCw= github.com/aws/aws-sdk-go-v2/config v1.6.1/go.mod h1:t/y3UPu0XEDy0cEw6mvygaBQaPzWiYAxfP2SzgtvclA= @@ -882,19 +882,19 @@ github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.15 h1:7Zwtt/lP3KNRkeZre7so github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.15/go.mod h1:436h2adoHb57yd+8W+gYPrrA9U/R/SuAuOO42Ushzhw= github.com/aws/aws-sdk-go-v2/internal/configsources v1.0.4/go.mod h1:W5gGbtNXFpF9/ssYZTaItzG/B+j0bjTnwStiCP2AtWU= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33/go.mod h1:7i0PF1ME/2eUPFcjkVIwq+DOygHEoK92t5cDqNgYbIw= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 h1:pI7Bzt0BJtYA0N/JEC6B8fJ4RBrEMi1LBrkMdFYNSnQ= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17/go.mod h1:Dh5zzJYMtxfIjYW+/evjQ8uj2OyR/ve2KROHGHlSFqE= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.20 h1:OErdlGnt+hg3tTwGYAlKvFkKVUo/TXkoHcxDxuhYYU8= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.20/go.mod h1:HsPfuL5gs+407ByRXBMgpYoyrV1sgMrzd18yMXQHJpo= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27/go.mod h1:UrHnn3QV/d0pBZ6QBAEQcqFLf8FAzLmoUfPVIueOvoM= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 h1:Mqr/V5gvrhA2gvgnF42Zh5iMiQNcOYthFYwCyrnuWlc= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17/go.mod h1:aLJpZlCmjE+V+KtN1q1uyZkfnUWpQGpbsn89XPKyzfU= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.20 h1:822cE1CYSwY/EZnErlF46pyynuxvf1p+VydHRQW+XNs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.20/go.mod h1:79/Tn7H7hYC5Gjz6fbnOV4OeBpkao7E8Tv95RO72pMM= github.com/aws/aws-sdk-go-v2/internal/ini v1.2.1/go.mod h1:Pv3WenDjI0v2Jl7UaMFIIbPOBbhn33RmmAmGgkXDoqY= github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34/go.mod h1:Etz2dj6UHYuw+Xw830KfzCfWGMzqvUTCjUj5b76GVDc= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 h1:81KE7vaZzrl7yHBYHVEzYB8sypz11NMOZ40YlWvPxsU= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5/go.mod h1:LIt2rg7Mcgn09Ygbdh/RdIm0rQ+3BNkbP1gyVMFtRK0= -github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.40.4 h1:dl+oQSMPrYCu7sdH/aZRvOplO49dI5KB9FzT+aVebKY= -github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.40.4/go.mod h1:maEDlnDRdhsc0xrUljh3dUJbej11AHz+VTQJsNw1QmE= +github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.42.1 h1:pGImNHNwEKqdjlFsYYNdlCelB38lkwXQYBD6xALuLFE= +github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.42.1/go.mod h1:qH88QnB7P06+AG50N0UiOBPfAVAEgDeCq5CzigEWkCs= github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.38.0 h1:nawnkdqwinpBukRuDd+h0eURWHk67W4OInSJrD4NJsE= github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.38.0/go.mod h1:K27H8p8ZmsntKSSC8det8LuT5WahXoJ4vZqlWwKTRaM= github.com/aws/aws-sdk-go-v2/service/dynamodb v1.5.0/go.mod h1:XY5YhCS9SLul3JSQ08XG/nfxXxrkh6RR21XPq/J//NY= @@ -941,8 +941,8 @@ github.com/aws/smithy-go v1.7.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAm github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= github.com/aws/smithy-go v1.9.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= -github.com/aws/smithy-go v1.21.0 h1:H7L8dtDRk0P1Qm6y0ji7MCYMQObJ5R9CRpyPhRUkLYA= -github.com/aws/smithy-go v1.21.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= +github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= +github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/awslabs/kinesis-aggregation/go v0.0.0-20210630091500-54e17340d32f h1:Pf0BjJDga7C98f0vhw+Ip5EaiE07S3lTKpIYPNS0nMo= github.com/awslabs/kinesis-aggregation/go v0.0.0-20210630091500-54e17340d32f/go.mod h1:SghidfnxvX7ribW6nHI7T+IBbc9puZ9kk5Tx/88h8P4= github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I= @@ -1416,8 +1416,8 @@ github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da h1:xRmpO92tb8y+Z85iUO github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo= github.com/google/protobuf v3.11.4+incompatible/go.mod h1:lUQ9D1ePzbH2PrIS7ob/bjm9HXyH5WHB0Akwh7URreM= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= -github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= +github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -1428,8 +1428,8 @@ github.com/googleapis/enterprise-certificate-proxy v0.1.0/go.mod h1:17drOmN3MwGY github.com/googleapis/enterprise-certificate-proxy v0.2.0/go.mod h1:8C0jb7/mgJe/9KK8Lm7X9ctZC2t60YyIpYEI16jx0Qg= github.com/googleapis/enterprise-certificate-proxy v0.2.1/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k= github.com/googleapis/enterprise-certificate-proxy v0.2.3/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k= -github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs= -github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= +github.com/googleapis/enterprise-certificate-proxy v0.3.4 h1:XYIDZApgAnrN1c855gTgghdIA6Stxb52D5RnLI1SLyw= +github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0= @@ -1467,8 +1467,8 @@ github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/z github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gosnmp/gosnmp v1.37.0 h1:/Tf8D3b9wrnNuf/SfbvO+44mPrjVphBhRtcGg22V07Y= -github.com/gosnmp/gosnmp v1.37.0/go.mod h1:GDH9vNqpsD7f2HvZhKs5dlqSEcAS6s6Qp099oZRCR+M= +github.com/gosnmp/gosnmp v1.38.0 h1:I5ZOMR8kb0DXAFg/88ACurnuwGwYkXWq3eLpJPHMEYc= +github.com/gosnmp/gosnmp v1.38.0/go.mod h1:FE+PEZvKrFz9afP9ii1W3cprXuVZ17ypCcyyfYuu5LY= github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc h1:GN2Lv3MGO7AS6PrRoT6yV5+wkrOpcszoIsO4+4ds248= github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc/go.mod h1:+JKpmjMGhpgPL+rXZ5nsZieVzvarn86asRlBg4uNGnk= github.com/grid-x/modbus v0.0.0-20240503115206-582f2ab60a18 h1:8V5xRtdD70kGC4/IHqFq+kcBSWr4k6nscAUgWwJ6A5k= @@ -1485,8 +1485,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1 github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= -github.com/gwos/tcg/sdk v0.0.0-20231124052037-1e832b843240 h1:dQUb3aqhbE1Z/QximDiPfBbTkq90Pf6p2f4k5M2puus= -github.com/gwos/tcg/sdk v0.0.0-20231124052037-1e832b843240/go.mod h1:H3CAtDtRLVPIkShWzarGiKYVZqrBtWNJMMRtfqJ3rXI= +github.com/gwos/tcg/sdk v0.0.0-20240830123415-f8a34bba6358 h1:QmKzhYk6KMjUutu9Sy4DyOkRgj1Dv+iFnea4t8KrCZg= +github.com/gwos/tcg/sdk v0.0.0-20240830123415-f8a34bba6358/go.mod h1:h40FJV0HuULqXSSKf7kfCbOxEcQAD74a5e2LC2+rYiQ= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= github.com/harlow/kinesis-consumer v0.3.6-0.20240916192723-43900507c911 h1:eLNkr0OcBl7pzM6DCLSgVp3VQyS5ZrLnanXPqH5EmE0= @@ -2195,8 +2195,8 @@ github.com/signalfx/com_signalfx_metrics_protobuf v0.0.3 h1:32k2QLgsKhcEs55q4REP github.com/signalfx/com_signalfx_metrics_protobuf v0.0.3/go.mod h1:gJrXWi7wSGXfiC7+VheQaz+ypdCt5SmZNL+BRxUe7y4= github.com/signalfx/gohistogram v0.0.0-20160107210732-1ccfd2ff5083 h1:WsShHmu12ZztYPfh9b+I+VjYD1o8iOHhB67WZCMEEE8= github.com/signalfx/gohistogram v0.0.0-20160107210732-1ccfd2ff5083/go.mod h1:adPDS6s7WaajdFBV9mQ7i0dKfQ8xiDnF9ZNETVPpp7c= -github.com/signalfx/golib/v3 v3.3.53 h1:gJx0JrrHjidpo2md+YLEN+Ws3RLTaCmKYT575ZSTKUo= -github.com/signalfx/golib/v3 v3.3.53/go.mod h1:lgdUNXjNnZkgEhQFSbfyek4oFUG8t1APhGaitZsSBzc= +github.com/signalfx/golib/v3 v3.3.54 h1:jUwTnaIXLHT0I1+hXoX0cPLdICIwBjB3e5/NGnnjgJY= +github.com/signalfx/golib/v3 v3.3.54/go.mod h1:KDQZIYpJ3yXPz/KysPQQEYooWdpq4eQZPsjwKR5secc= github.com/signalfx/sapm-proto v0.12.0 h1:OtOe+Jm8L61Ml8K6X8a89zc8/RlaaMRElCImeGKR/Ew= github.com/signalfx/sapm-proto v0.12.0/go.mod h1:wQEki8RNCYjkv19jw5aWDcmDMTQru0ckfUbgHI69U2E= github.com/sijms/go-ora/v2 v2.8.19 h1:7LoKZatDYGi18mkpQTR/gQvG9yOdtc7hPAex96Bqisc= @@ -2223,8 +2223,8 @@ github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIK github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/gunit v1.0.0/go.mod h1:qwPWnhz6pn0NnRBP++URONOVyNkPyr4SauJk4cUOwJs= github.com/smartystreets/gunit v1.1.3/go.mod h1:EH5qMBab2UclzXUcpR8b93eHsIlp9u+pDQIRp5DZNzQ= -github.com/snowflakedb/gosnowflake v1.11.1 h1:E91s8vBOSroaSTLsyjO4QPkEuzGmZcCxEFQLg214mvk= -github.com/snowflakedb/gosnowflake v1.11.1/go.mod h1:WFe+8mpsapDaQjHX6BqJBKtfQCGlGD3lHKeDsKfpx2A= +github.com/snowflakedb/gosnowflake v1.11.2 h1:eAMsxrCiC6ij5wX3dHx1TQCBOdDmCK062Ir8rndUkRg= +github.com/snowflakedb/gosnowflake v1.11.2/go.mod h1:WFe+8mpsapDaQjHX6BqJBKtfQCGlGD3lHKeDsKfpx2A= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/sony/gobreaker v0.5.0 h1:dRCvqm0P490vZPmy7ppEk2qCnCieBooFJ+YoXGYB+yg= github.com/sony/gobreaker v0.5.0/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= @@ -2427,26 +2427,26 @@ go.opentelemetry.io/collector/pdata/testdata v0.101.0 h1:JzeUtg5RN1iIFgY8DakGlqB go.opentelemetry.io/collector/pdata/testdata v0.101.0/go.mod h1:ZGobfCus4fWo5RduZ7ENI0+HD9BewgKuO6qU2rBVnUg= go.opentelemetry.io/collector/semconv v0.105.0 h1:8p6dZ3JfxFTjbY38d8xlQGB1TQ3nPUvs+D0RERniZ1g= go.opentelemetry.io/collector/semconv v0.105.0/go.mod h1:yMVUCNoQPZVq/IPfrHrnntZTWsLf5YGZ7qwKulIl5hw= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 h1:4Pp6oUg3+e/6M4C0A/3kJ2VYa++dsWVTtGgLVj5xtHg= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0/go.mod h1:Mjt1i1INqiaoZOMGR1RIUJN+i3ChKoFRqzrRQhlkbs0= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 h1:4K4tsIXefpVJtvA/8srF4V4y0akAoPHkIslgAkjixJA= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0/go.mod h1:jjdQuTGVsXV4vSs+CJ2qYDeDPf9yIJV23qlIzBm73Vg= -go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo= -go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 h1:r6I7RJCN86bpD/FQwedZ0vSixDpwuWREjW9oRMsmqDc= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0/go.mod h1:B9yO6b04uB80CzjedvewuqDhxJxi11s7/GtiGa8bAjI= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8= +go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= +go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.44.0 h1:jd0+5t/YynESZqsSyPz+7PAFdEop0dlN0+PkyHYo8oI= go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.44.0/go.mod h1:U707O40ee1FpQGyhvqnzmCJm1Wh6OX6GGBVn0E6Uyyk= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 h1:j9+03ymgYhPKmeXGk5Zu+cIZOlVzd9Zv7QIiyItjFBU= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0/go.mod h1:Y5+XiUG4Emn1hTfciPzGPJaSI+RpDts6BnCIir0SLqk= -go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q= -go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s= -go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE= -go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg= +go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc= +go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8= +go.opentelemetry.io/otel/sdk v1.29.0 h1:vkqKjk7gwhS8VaWb0POZKmIEDimRCMsopNYnriHyryo= +go.opentelemetry.io/otel/sdk v1.29.0/go.mod h1:pM8Dx5WKnvxLCb+8lG1PRNIDxu9g9b9g59Qr7hfAAok= go.opentelemetry.io/otel/sdk/metric v1.27.0 h1:5uGNOlpXi+Hbo/DRoI31BSb1v+OGcpv2NemcCrOL8gI= go.opentelemetry.io/otel/sdk/metric v1.27.0/go.mod h1:we7jJVrYN2kh3mVBlswtPU22K0SA+769l93J6bsyvqw= -go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= -go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= +go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4= +go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.15.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= @@ -2899,8 +2899,8 @@ golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= -golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= +golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -2978,8 +2978,8 @@ golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= -golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= -golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= +golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= +golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -2990,8 +2990,8 @@ golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= +golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da h1:noIWHXmPHxILtqtCOPIhSt0ABwskkZKjD3bXGnZGpNY= +golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= golang.zx2c4.com/go118/netip v0.0.0-20211111135330-a4a02eeacf9d/go.mod h1:5yyfuiqVIJ7t+3MqrpTQ+QqRkMWiESiyDvPNvKYCecg= golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI= golang.zx2c4.com/wireguard v0.0.0-20211129173154-2dd424e2d808/go.mod h1:TjUWrnD5ATh7bFvmm/ALEJZQ4ivKbETb6pmyj1vUoNI= @@ -3066,8 +3066,8 @@ google.golang.org/api v0.108.0/go.mod h1:2Ts0XTHNVWxypznxWOYUeI4g3WdP9Pk2Qk58+a/ google.golang.org/api v0.110.0/go.mod h1:7FC4Vvx1Mooxh8C5HWjzZHcavuS2f6pmJpZx60ca7iI= google.golang.org/api v0.111.0/go.mod h1:qtFHvU9mhgTJegR31csQ+rwxyUTHOKFqCKWp1J0fdw0= google.golang.org/api v0.114.0/go.mod h1:ifYI2ZsFK6/uGddGfAD5BMxlnkBqCmqHSDUVi45N5Yg= -google.golang.org/api v0.189.0 h1:equMo30LypAkdkLMBqfeIqtyAnlyig1JSZArl4XPwdI= -google.golang.org/api v0.189.0/go.mod h1:FLWGJKb0hb+pU2j+rJqwbnsF+ym+fQs73rbJ+KAUgy8= +google.golang.org/api v0.197.0 h1:x6CwqQLsFiA5JKAiGyGBjc2bNtHtLddhJCE2IKuhhcQ= +google.golang.org/api v0.197.0/go.mod h1:AuOuo20GoQ331nq7DquGHlU6d+2wN2fZ8O0ta60nRNw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -3209,12 +3209,12 @@ google.golang.org/genproto v0.0.0-20230323212658-478b75c54725/go.mod h1:UUQDJDOl google.golang.org/genproto v0.0.0-20230330154414-c0448cd141ea/go.mod h1:UUQDJDOlWu4KYeJZffbWgBkS1YFobzKbLVfK69pe0Ak= google.golang.org/genproto v0.0.0-20230331144136-dcfb400f0633/go.mod h1:UUQDJDOlWu4KYeJZffbWgBkS1YFobzKbLVfK69pe0Ak= google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= -google.golang.org/genproto v0.0.0-20240722135656-d784300faade h1:lKFsS7wpngDgSCeFn7MoLy+wBDQZ1UQIJD4UNM1Qvkg= -google.golang.org/genproto v0.0.0-20240722135656-d784300faade/go.mod h1:FfBgJBJg9GcpPvKIuHSZ/aE1g2ecGL74upMzGZjiGEY= -google.golang.org/genproto/googleapis/api v0.0.0-20240722135656-d784300faade h1:WxZOF2yayUHpHSbUE6NMzumUzBxYc3YGwo0YHnbzsJY= -google.golang.org/genproto/googleapis/api v0.0.0-20240722135656-d784300faade/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade h1:oCRSWfwGXQsqlVdErcyTt4A93Y8fo0/9D4b1gnI++qo= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 h1:BulPr26Jqjnd4eYDVe+YvyR7Yc2vJGkO5/0UxD0/jZU= +google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:hL97c3SYopEHblzpxRL4lSs523++l8DYxGM1FQiYmb4= +google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1:hjSy6tcFQZ171igDaN5QHOw2n6vx40juYbC/x67CEhc= +google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:qpvKtACPCQhAdu3PyQgV4l3LMXZEtft7y8QcarRsp9I= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -3256,8 +3256,8 @@ google.golang.org/grpc v1.52.3/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5v google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw= google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= -google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= -google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= +google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo= +google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= diff --git a/internal/snmp/field.go b/internal/snmp/field.go index b2ed67b6e9f2e..936cc3dda4987 100644 --- a/internal/snmp/field.go +++ b/internal/snmp/field.go @@ -85,11 +85,11 @@ func (f *Field) Init(tr Translator) error { } if f.SecondaryIndexTable && f.SecondaryIndexUse { - return errors.New("SecondaryIndexTable and UseSecondaryIndex are exclusive") + return errors.New("fields SecondaryIndexTable and UseSecondaryIndex are exclusive") } if !f.SecondaryIndexTable && !f.SecondaryIndexUse && f.SecondaryOuterJoin { - return errors.New("SecondaryOuterJoin set to true, but field is not being used in join") + return errors.New("field SecondaryOuterJoin set to true, but field is not being used in join") } switch f.Conversion { diff --git a/internal/snmp/table.go b/internal/snmp/table.go index aa42b3c116a9e..495ef16ad5a05 100644 --- a/internal/snmp/table.go +++ b/internal/snmp/table.go @@ -51,12 +51,12 @@ type RTableRow struct { Fields map[string]interface{} } -// Init() builds & initializes the nested fields. +// Init builds & initializes the nested fields. func (t *Table) Init(tr Translator) error { // makes sure oid or name is set in config file // otherwise snmp will produce metrics with an empty name if t.Oid == "" && t.Name == "" { - return errors.New("SNMP table in config file is not named. One or both of the oid and name settings must be set") + return errors.New("unnamed SNMP table in config file: one or both of the oid and name settings must be set") } if t.initialized { diff --git a/models/buffer_disk.go b/models/buffer_disk.go index e5fc1b219cfda..dabd377cd9e03 100644 --- a/models/buffer_disk.go +++ b/models/buffer_disk.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "log" - "os" "path/filepath" "sync" @@ -27,6 +26,11 @@ type DiskBuffer struct { // Ending point of metrics read from disk on telegraf launch. // Used to know whether to discard tracking metrics. originalEnd uint64 + + // The WAL library currently has no way to "fully empty" the walfile. In this case, + // we have to do our best and track that the walfile "should" be empty, so that next + // write, we can remove the invalid entry (also skipping this entry if it is being read). + isEmpty bool } func NewDiskBuffer(name string, path string, stats BufferStats) (*DiskBuffer, error) { @@ -53,6 +57,9 @@ func (b *DiskBuffer) Len() int { } func (b *DiskBuffer) length() int { + if b.isEmpty { + return 0 + } // Special case for when the read index is zero, it must be empty (otherwise it would be >= 1) if b.readIndex() == 0 { return 0 @@ -87,6 +94,8 @@ func (b *DiskBuffer) Add(metrics ...telegraf.Metric) int { if !b.addSingleMetric(m) { dropped++ } + // as soon as a new metric is added, if this was empty, try to flush the "empty" metric out + b.handleEmptyFile() } b.BufferSize.Set(int64(b.length())) return dropped @@ -169,7 +178,7 @@ func (b *DiskBuffer) Accept(batch []telegraf.Metric) { b.metricWritten(m) } if b.length() == len(batch) { - b.resetWalFile() + b.emptyFile() } else { err := b.file.TruncateFront(b.batchFirst + uint64(len(batch))) if err != nil { @@ -205,15 +214,27 @@ func (b *DiskBuffer) resetBatch() { } // This is very messy and not ideal, but serves as the only way I can find currently -// to actually clear the walfile completely if needed, since Truncate() calls require +// to actually treat the walfile as empty if needed, since Truncate() calls require // that at least one entry remains in them otherwise they return an error. // Related issue: https://github.com/tidwall/wal/issues/20 -func (b *DiskBuffer) resetWalFile() { - b.file.Close() - os.Remove(b.path) - walFile, err := wal.Open(b.path, nil) - if err != nil { +func (b *DiskBuffer) handleEmptyFile() { + if !b.isEmpty { + return + } + if err := b.file.TruncateFront(b.readIndex() + 1); err != nil { + log.Printf("E! readIndex: %d, buffer len: %d", b.readIndex(), b.length()) + panic(err) + } + b.isEmpty = false +} + +func (b *DiskBuffer) emptyFile() { + if b.isEmpty || b.length() == 0 { + return + } + if err := b.file.TruncateFront(b.writeIndex() - 1); err != nil { + log.Printf("E! writeIndex: %d, buffer len: %d", b.writeIndex(), b.length()) panic(err) } - b.file = walFile + b.isEmpty = true } diff --git a/models/buffer_suite_test.go b/models/buffer_suite_test.go index a984df41e1614..fff061694b549 100644 --- a/models/buffer_suite_test.go +++ b/models/buffer_suite_test.go @@ -809,3 +809,26 @@ func (s *BufferSuiteTest) TestBuffer_RejectEmptyBatch() { s.NotNil(m) } } + +func (s *BufferSuiteTest) TestBuffer_FlushedPartial() { + b := s.newTestBuffer(5) + b.Add(MetricTime(1)) + b.Add(MetricTime(2)) + b.Add(MetricTime(3)) + batch := b.Batch(2) + s.Len(batch, 2) + + b.Accept(batch) + s.Equal(1, b.Len()) +} + +func (s *BufferSuiteTest) TestBuffer_FlushedFull() { + b := s.newTestBuffer(5) + b.Add(MetricTime(1)) + b.Add(MetricTime(2)) + batch := b.Batch(2) + s.Len(batch, 2) + + b.Accept(batch) + s.Equal(0, b.Len()) +} diff --git a/models/running_input.go b/models/running_input.go index 8a5ff060731cf..7858d0e3e662b 100644 --- a/models/running_input.go +++ b/models/running_input.go @@ -24,9 +24,11 @@ type RunningInput struct { log telegraf.Logger defaultTags map[string]string - startAcc telegraf.Accumulator - started bool - retries uint64 + startAcc telegraf.Accumulator + started bool + retries uint64 + gatherStart time.Time + gatherEnd time.Time MetricsGathered selfstat.Stat GatherTime selfstat.Stat @@ -87,6 +89,7 @@ type InputConfig struct { CollectionJitter time.Duration CollectionOffset time.Duration Precision time.Duration + TimeSource string StartupErrorBehavior string LogLevel string @@ -114,6 +117,14 @@ func (r *RunningInput) Init() error { return fmt.Errorf("invalid 'startup_error_behavior' setting %q", r.Config.StartupErrorBehavior) } + 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 { return p.Init() } @@ -206,6 +217,14 @@ func (r *RunningInput) MakeMetric(metric telegraf.Metric) telegraf.Metric { makemetric(metric, "", "", "", local, global) } + switch r.Config.TimeSource { + case "collection_start": + metric.SetTime(r.gatherStart) + case "collection_end": + metric.SetTime(r.gatherEnd) + default: + } + r.MetricsGathered.Incr(1) GlobalMetricsGathered.Incr(1) return metric @@ -228,10 +247,11 @@ func (r *RunningInput) Gather(acc telegraf.Accumulator) error { } } - start := time.Now() + r.gatherStart = time.Now() err := r.Input.Gather(acc) - elapsed := time.Since(start) - r.GatherTime.Incr(elapsed.Nanoseconds()) + r.gatherEnd = time.Now() + + r.GatherTime.Incr(r.gatherEnd.Sub(r.gatherStart).Nanoseconds()) return err } diff --git a/models/running_input_test.go b/models/running_input_test.go index 877cc2bd39908..9bf7d6d9eb855 100644 --- a/models/running_input_test.go +++ b/models/running_input_test.go @@ -428,6 +428,65 @@ func TestMakeMetricWithAlwaysKeepingPluginTagsEnabled(t *testing.T) { require.Equal(t, expected, actual) } +func TestMakeMetricWithGatherMetricTimeSource(t *testing.T) { + ri := NewRunningInput(&testInput{}, &InputConfig{ + Name: "TestRunningInput", + Tags: make(map[string]string), + Filter: Filter{}, + AlwaysIncludeLocalTags: false, + AlwaysIncludeGlobalTags: false, + TimeSource: "metric", + }) + start := time.Now() + ri.gatherStart = start + ri.gatherEnd = start.Add(time.Second) + + expected := testutil.MockMetrics()[0] + + m := testutil.MockMetrics()[0] + actual := ri.MakeMetric(m) + + require.Equal(t, expected, actual) +} + +func TestMakeMetricWithGatherStartTimeSource(t *testing.T) { + start := time.Now() + ri := NewRunningInput(&testInput{}, &InputConfig{ + Name: "TestRunningInput", + Tags: make(map[string]string), + Filter: Filter{}, + AlwaysIncludeLocalTags: false, + AlwaysIncludeGlobalTags: false, + TimeSource: "collection_start", + }) + ri.gatherStart = start + + expected := testutil.MockMetrics()[0] + expected.SetTime(start) + + m := testutil.MockMetrics()[0] + actual := ri.MakeMetric(m) + + require.Equal(t, expected, actual) +} + +func TestMakeMetricWithGatherEndTimeSource(t *testing.T) { + end := time.Now() + ri := NewRunningInput(&testInput{}, &InputConfig{ + Name: "TestRunningInput", + TimeSource: "collection_end", + }) + ri.gatherEnd = end + + expected := testutil.MockMetrics()[0] + expected.SetTime(end) + + m := testutil.MockMetrics()[0] + actual := ri.MakeMetric(m) + + require.Equal(t, expected, actual) +} + type testInput struct{} func (t *testInput) Description() string { return "" } diff --git a/plugins/aggregators/basicstats/README.md b/plugins/aggregators/basicstats/README.md index 2f1621068e026..dc6b7d719e916 100644 --- a/plugins/aggregators/basicstats/README.md +++ b/plugins/aggregators/basicstats/README.md @@ -1,8 +1,8 @@ # BasicStats Aggregator Plugin The BasicStats aggregator plugin gives count, diff, max, min, mean, -non_negative_diff, sum, s2(variance), stdev for a set of values, emitting the -aggregate every `period` seconds. +non_negative_diff, sum, s2(variance), stdev for a set of values, last and +first, emitting the aggregate every `period` seconds. ## Global configuration options @@ -26,7 +26,7 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. # drop_original = false ## Configures which basic stats to push as fields - # stats = ["count","diff","rate","min","max","mean","non_negative_diff","non_negative_rate","percent_change","stdev","s2","sum","interval","last"] + # stats = ["count","min","max","mean","variance","stdev"] ``` - stats @@ -52,6 +52,7 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. - field1_stdev (standard deviation) - field1_interval (interval in nanoseconds) - field1_last (last aggregated value) + - field1_first (first aggregated value) ## Tags @@ -65,5 +66,5 @@ system,host=tars load1=1 1475583990000000000 system,host=tars load1_count=2,load1_diff=0,load1_rate=0,load1_max=1,load1_min=1,load1_mean=1,load1_sum=2,load1_s2=0,load1_stdev=0,load1_interval=10000000000i,load1_last=1 1475584010000000000 system,host=tars load1=1 1475584020000000000 system,host=tars load1=3 1475584030000000000 -system,host=tars load1_count=2,load1_diff=2,load1_rate=0.2,load1_max=3,load1_min=1,load1_mean=2,load1_sum=4,load1_s2=2,load1_stdev=1.414162,load1_interval=10000000000i,load1_last=3 1475584010000000000 +system,host=tars load1_count=2,load1_diff=2,load1_rate=0.2,load1_max=3,load1_min=1,load1_mean=2,load1_sum=4,load1_s2=2,load1_stdev=1.414162,load1_interval=10000000000i,load1_last=3,load1_first=3 1475584010000000000 ``` diff --git a/plugins/aggregators/basicstats/basicstats.go b/plugins/aggregators/basicstats/basicstats.go index ba131c7fca8b3..4259d00409ec7 100644 --- a/plugins/aggregators/basicstats/basicstats.go +++ b/plugins/aggregators/basicstats/basicstats.go @@ -36,6 +36,7 @@ type configuredStats struct { percentChange bool interval bool last bool + first bool } func NewBasicStats() *BasicStats { @@ -60,6 +61,7 @@ type basicstats struct { rate float64 interval time.Duration last float64 + first float64 M2 float64 // intermediate value for variance/stdev PREVIOUS float64 // intermediate value for diff TIME time.Time // intermediate value for rate @@ -89,6 +91,7 @@ func (b *BasicStats) Add(in telegraf.Metric) { diff: 0.0, rate: 0.0, last: fv, + first: fv, M2: 0.0, PREVIOUS: fv, TIME: in.Time(), @@ -111,6 +114,7 @@ func (b *BasicStats) Add(in telegraf.Metric) { rate: 0.0, interval: 0, last: fv, + first: fv, M2: 0.0, PREVIOUS: fv, TIME: in.Time(), @@ -181,6 +185,9 @@ func (b *BasicStats) Push(acc telegraf.Accumulator) { if b.statsConfig.last { fields[k+"_last"] = v.last } + if b.statsConfig.first { + fields[k+"_first"] = v.first + } // v.count always >=1 if v.count > 1 { @@ -254,6 +261,8 @@ func (b *BasicStats) parseStats() *configuredStats { parsed.interval = true case "last": parsed.last = true + case "first": + parsed.first = true default: b.Log.Warnf("Unrecognized basic stat %q, ignoring", name) } @@ -279,6 +288,7 @@ func (b *BasicStats) initConfiguredStats() { percentChange: false, interval: false, last: false, + first: false, } } else { b.statsConfig = b.parseStats() diff --git a/plugins/aggregators/basicstats/basicstats_test.go b/plugins/aggregators/basicstats/basicstats_test.go index 1aa81e050cf23..12a2b4233839f 100644 --- a/plugins/aggregators/basicstats/basicstats_test.go +++ b/plugins/aggregators/basicstats/basicstats_test.go @@ -111,7 +111,7 @@ func TestBasicStatsWithPeriod(t *testing.T) { func TestBasicStatsDifferentPeriods(t *testing.T) { acc := testutil.Accumulator{} minmax := NewBasicStats() - minmax.Stats = []string{"count", "max", "min", "mean", "last"} + minmax.Stats = []string{"count", "max", "min", "mean", "last", "first"} minmax.Log = testutil.Logger{} minmax.initConfiguredStats() @@ -123,26 +123,31 @@ func TestBasicStatsDifferentPeriods(t *testing.T) { "a_min": float64(1), "a_mean": float64(1), "a_last": float64(1), + "a_first": float64(1), "b_count": float64(1), // b "b_max": float64(1), "b_min": float64(1), "b_mean": float64(1), "b_last": float64(1), + "b_first": float64(1), "c_count": float64(1), // c "c_max": float64(2), "c_min": float64(2), "c_mean": float64(2), "c_last": float64(2), + "c_first": float64(2), "d_count": float64(1), // d "d_max": float64(2), "d_min": float64(2), "d_mean": float64(2), "d_last": float64(2), + "d_first": float64(2), "g_count": float64(1), // g "g_max": float64(3), "g_min": float64(3), "g_mean": float64(3), "g_last": float64(3), + "g_first": float64(3), } expectedTags := map[string]string{ "foo": "bar", @@ -159,36 +164,43 @@ func TestBasicStatsDifferentPeriods(t *testing.T) { "a_min": float64(1), "a_mean": float64(1), "a_last": float64(1), + "a_first": float64(1), "b_count": float64(1), // b "b_max": float64(3), "b_min": float64(3), "b_mean": float64(3), "b_last": float64(3), + "b_first": float64(3), "c_count": float64(1), // c "c_max": float64(4), "c_min": float64(4), "c_mean": float64(4), "c_last": float64(4), + "c_first": float64(4), "d_count": float64(1), // d "d_max": float64(6), "d_min": float64(6), "d_mean": float64(6), "d_last": float64(6), + "d_first": float64(6), "e_count": float64(1), // e "e_max": float64(200), "e_min": float64(200), "e_mean": float64(200), "e_last": float64(200), + "e_first": float64(200), "f_count": float64(1), // f "f_max": float64(200), "f_min": float64(200), "f_mean": float64(200), "f_last": float64(200), + "f_first": float64(200), "g_count": float64(1), // g "g_max": float64(1), "g_min": float64(1), "g_mean": float64(1), "g_last": float64(1), + "g_first": float64(1), } expectedTags = map[string]string{ "foo": "bar", @@ -629,7 +641,7 @@ func TestBasicStatsWithAllStats(t *testing.T) { acc := testutil.Accumulator{} minmax := NewBasicStats() minmax.Log = testutil.Logger{} - minmax.Stats = []string{"count", "min", "max", "mean", "stdev", "s2", "sum", "last"} + minmax.Stats = []string{"count", "min", "max", "mean", "stdev", "s2", "sum", "last", "first"} minmax.initConfiguredStats() minmax.Add(m1) @@ -645,6 +657,7 @@ func TestBasicStatsWithAllStats(t *testing.T) { "a_s2": float64(0), "a_sum": float64(2), "a_last": float64(1), + "a_first": float64(1), "b_count": float64(2), // b "b_max": float64(3), "b_min": float64(1), @@ -653,6 +666,7 @@ func TestBasicStatsWithAllStats(t *testing.T) { "b_sum": float64(4), "b_last": float64(3), "b_stdev": math.Sqrt(2), + "b_first": float64(1), "c_count": float64(2), // c "c_max": float64(4), "c_min": float64(2), @@ -661,6 +675,7 @@ func TestBasicStatsWithAllStats(t *testing.T) { "c_stdev": math.Sqrt(2), "c_sum": float64(6), "c_last": float64(4), + "c_first": float64(2), "d_count": float64(2), // d "d_max": float64(6), "d_min": float64(2), @@ -669,18 +684,21 @@ func TestBasicStatsWithAllStats(t *testing.T) { "d_stdev": math.Sqrt(8), "d_sum": float64(8), "d_last": float64(6), + "d_first": float64(2), "e_count": float64(1), // e "e_max": float64(200), "e_min": float64(200), "e_mean": float64(200), "e_sum": float64(200), "e_last": float64(200), + "e_first": float64(200), "f_count": float64(1), // f "f_max": float64(200), "f_min": float64(200), "f_mean": float64(200), "f_sum": float64(200), "f_last": float64(200), + "f_first": float64(200), "g_count": float64(2), // g "g_max": float64(3), "g_min": float64(1), @@ -689,6 +707,7 @@ func TestBasicStatsWithAllStats(t *testing.T) { "g_stdev": math.Sqrt(2), "g_sum": float64(4), "g_last": float64(1), + "g_first": float64(3), } expectedTags := map[string]string{ "foo": "bar", @@ -778,3 +797,30 @@ func TestBasicStatsWithOnlyLast(t *testing.T) { } acc.AssertContainsTaggedFields(t, "m1", expectedFields, expectedTags) } + +func TestBasicStatsWithOnlyFirst(t *testing.T) { + aggregator := NewBasicStats() + aggregator.Stats = []string{"first"} + aggregator.Log = testutil.Logger{} + aggregator.initConfiguredStats() + + aggregator.Add(m1) + aggregator.Add(m2) + + acc := testutil.Accumulator{} + aggregator.Push(&acc) + + expectedFields := map[string]interface{}{ + "a_first": float64(1), + "b_first": float64(1), + "c_first": float64(2), + "d_first": float64(2), + "e_first": float64(200), + "f_first": float64(200), + "g_first": float64(3), + } + expectedTags := map[string]string{ + "foo": "bar", + } + acc.AssertContainsTaggedFields(t, "m1", expectedFields, expectedTags) +} diff --git a/plugins/aggregators/basicstats/sample.conf b/plugins/aggregators/basicstats/sample.conf index 30d5e5836e863..dc5168cb6dca4 100644 --- a/plugins/aggregators/basicstats/sample.conf +++ b/plugins/aggregators/basicstats/sample.conf @@ -8,4 +8,4 @@ # drop_original = false ## Configures which basic stats to push as fields - # stats = ["count","diff","rate","min","max","mean","non_negative_diff","non_negative_rate","percent_change","stdev","s2","sum","interval","last"] + # stats = ["count","min","max","mean","variance","stdev"] diff --git a/plugins/common/proxy/socks5_test.go b/plugins/common/proxy/socks5_test.go index 3bd7488047aac..9d1013a91b340 100644 --- a/plugins/common/proxy/socks5_test.go +++ b/plugins/common/proxy/socks5_test.go @@ -32,7 +32,11 @@ func TestSocks5ProxyConfigIntegration(t *testing.T) { }) require.NoError(t, err) - go func() { require.NoError(t, server.ListenAndServe("tcp", proxyAddress)) }() + go func() { + if err := server.ListenAndServe("tcp", proxyAddress); err != nil { + t.Error(err) + } + }() conf := Socks5ProxyConfig{ Socks5ProxyEnabled: true, diff --git a/plugins/common/shim/goshim.go b/plugins/common/shim/goshim.go index 72af49ddaffbd..3d329cf04babb 100644 --- a/plugins/common/shim/goshim.go +++ b/plugins/common/shim/goshim.go @@ -79,17 +79,17 @@ func (s *Shim) Run(pollInterval time.Duration) error { if s.Input != nil { err := s.RunInput(pollInterval) if err != nil { - return fmt.Errorf("RunInput error: %w", err) + return fmt.Errorf("running input failed: %w", err) } } else if s.Processor != nil { err := s.RunProcessor() if err != nil { - return fmt.Errorf("RunProcessor error: %w", err) + return fmt.Errorf("running processor failed: %w", err) } } else if s.Output != nil { err := s.RunOutput() if err != nil { - return fmt.Errorf("RunOutput error: %w", err) + return fmt.Errorf("running output failed: %w", err) } } else { return errors.New("nothing to run") diff --git a/plugins/common/shim/goshim_test.go b/plugins/common/shim/goshim_test.go index b123cc5addbcb..9aa9f704ffa0c 100644 --- a/plugins/common/shim/goshim_test.go +++ b/plugins/common/shim/goshim_test.go @@ -31,9 +31,9 @@ func TestShimSetsUpLogger(t *testing.T) { require.NoError(t, err) } -func runErroringInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdout, stderr io.Writer) (metricProcessed chan bool, exited chan bool) { - metricProcessed = make(chan bool, 1) - exited = make(chan bool, 1) +func runErroringInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdout, stderr io.Writer) (chan bool, chan bool) { + metricProcessed := make(chan bool, 1) + exited := make(chan bool, 1) inp := &erroringInput{} shim := New() @@ -50,8 +50,9 @@ func runErroringInputPlugin(t *testing.T, interval time.Duration, stdin io.Reade err := shim.AddInput(inp) require.NoError(t, err) go func() { - err := shim.Run(interval) - require.NoError(t, err) + if err := shim.Run(interval); err != nil { + t.Error(err) + } exited <- true }() return metricProcessed, exited diff --git a/plugins/common/shim/input_test.go b/plugins/common/shim/input_test.go index 0233c7d8f896a..0e7084ac14d46 100644 --- a/plugins/common/shim/input_test.go +++ b/plugins/common/shim/input_test.go @@ -47,16 +47,17 @@ func TestInputShimStdinSignalingWorks(t *testing.T) { err = stdinWriter.Close() require.NoError(t, err) go func() { - _, err = io.ReadAll(r) - require.NoError(t, err) + if _, err = io.ReadAll(r); err != nil { + t.Error(err) + } }() // check that it exits cleanly <-exited } -func runInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdout, stderr io.Writer) (metricProcessed chan bool, exited chan bool) { - metricProcessed = make(chan bool, 1) - exited = make(chan bool, 1) +func runInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdout, stderr io.Writer) (chan bool, chan bool) { + metricProcessed := make(chan bool, 1) + exited := make(chan bool, 1) inp := &testInput{ metricProcessed: metricProcessed, } @@ -74,8 +75,9 @@ func runInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdou err := shim.AddInput(inp) require.NoError(t, err) go func() { - err := shim.Run(interval) - require.NoError(t, err) + if err := shim.Run(interval); err != nil { + t.Error(err) + } exited <- true }() return metricProcessed, exited diff --git a/plugins/common/shim/output_test.go b/plugins/common/shim/output_test.go index 4340ecf43e2b5..eaca4a7a7bfde 100644 --- a/plugins/common/shim/output_test.go +++ b/plugins/common/shim/output_test.go @@ -28,8 +28,9 @@ func TestOutputShim(t *testing.T) { wg.Add(1) go func() { - err := s.RunOutput() - require.NoError(t, err) + if err := s.RunOutput(); err != nil { + t.Error(err) + } wg.Done() }() diff --git a/plugins/common/shim/processor_test.go b/plugins/common/shim/processor_test.go index 195d725720b05..b8a476828c31e 100644 --- a/plugins/common/shim/processor_test.go +++ b/plugins/common/shim/processor_test.go @@ -47,8 +47,9 @@ func testSendAndReceive(t *testing.T, fieldKey string, fieldValue string) { wg.Add(1) go func() { - err := s.RunProcessor() - require.NoError(t, err) + if err := s.RunProcessor(); err != nil { + t.Error(err) + } wg.Done() }() @@ -88,8 +89,9 @@ func testSendAndReceive(t *testing.T, fieldKey string, fieldValue string) { require.True(t, ok) require.Equal(t, fieldValue, val2) go func() { - _, err = io.ReadAll(r) - require.NoError(t, err) + if _, err = io.ReadAll(r); err != nil { + t.Error(err) + } }() wg.Wait() } diff --git a/plugins/common/socket/stream.go b/plugins/common/socket/stream.go index 4896bbc873357..8b04c91951d07 100644 --- a/plugins/common/socket/stream.go +++ b/plugins/common/socket/stream.go @@ -100,7 +100,7 @@ func (l *streamListener) setupVsock(u *url.URL) error { // Check address string for containing two tokens if len(addrTuple) < 2 { - return errors.New("CID and/or port number missing") + return errors.New("port and/or CID number missing") } // Parse CID and port number from address string both being 32-bit // source: https://man7.org/linux/man-pages/man7/vsock.7.html @@ -109,7 +109,7 @@ func (l *streamListener) setupVsock(u *url.URL) error { return fmt.Errorf("failed to parse CID %s: %w", addrTuple[0], err) } if (cid >= uint64(math.Pow(2, 32))-1) && (cid <= 0) { - return fmt.Errorf("CID %d is out of range", cid) + return fmt.Errorf("value of CID %d is out of range", cid) } port, err := strconv.ParseUint(addrTuple[1], 10, 32) if err != nil { diff --git a/plugins/inputs/activemq/activemq.go b/plugins/inputs/activemq/activemq.go index 1d08b457172f5..1ed701e2b982e 100644 --- a/plugins/inputs/activemq/activemq.go +++ b/plugins/inputs/activemq/activemq.go @@ -87,22 +87,6 @@ type stats struct { DequeueCounter int `xml:"dequeueCounter,attr"` } -func (a *ActiveMQ) createHTTPClient() (*http.Client, error) { - tlsCfg, err := a.ClientConfig.TLSConfig() - if err != nil { - return nil, err - } - - client := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: tlsCfg, - }, - Timeout: time.Duration(a.ResponseTimeout), - } - - return client, nil -} - func (*ActiveMQ) SampleConfig() string { return sampleConfig } @@ -138,7 +122,61 @@ func (a *ActiveMQ) Init() error { return nil } -func (a *ActiveMQ) GetMetrics(u string) ([]byte, error) { +func (a *ActiveMQ) Gather(acc telegraf.Accumulator) error { + dataQueues, err := a.getMetrics(a.queuesURL()) + if err != nil { + return err + } + queues := queues{} + err = xml.Unmarshal(dataQueues, &queues) + if err != nil { + return fmt.Errorf("queues XML unmarshal error: %w", err) + } + + dataTopics, err := a.getMetrics(a.topicsURL()) + if err != nil { + return err + } + topics := topics{} + err = xml.Unmarshal(dataTopics, &topics) + if err != nil { + return fmt.Errorf("topics XML unmarshal error: %w", err) + } + + dataSubscribers, err := a.getMetrics(a.subscribersURL()) + if err != nil { + return err + } + subscribers := subscribers{} + err = xml.Unmarshal(dataSubscribers, &subscribers) + if err != nil { + return fmt.Errorf("subscribers XML unmarshal error: %w", err) + } + + a.gatherQueuesMetrics(acc, queues) + a.gatherTopicsMetrics(acc, topics) + a.gatherSubscribersMetrics(acc, subscribers) + + return nil +} + +func (a *ActiveMQ) createHTTPClient() (*http.Client, error) { + tlsCfg, err := a.ClientConfig.TLSConfig() + if err != nil { + return nil, err + } + + client := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: tlsCfg, + }, + Timeout: time.Duration(a.ResponseTimeout), + } + + return client, nil +} + +func (a *ActiveMQ) getMetrics(u string) ([]byte, error) { req, err := http.NewRequest("GET", u, nil) if err != nil { return nil, err @@ -155,13 +193,13 @@ func (a *ActiveMQ) GetMetrics(u string) ([]byte, error) { defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("GET %s returned status %q", u, resp.Status) + return nil, fmt.Errorf("%s returned HTTP status %s", u, resp.Status) } return io.ReadAll(resp.Body) } -func (a *ActiveMQ) GatherQueuesMetrics(acc telegraf.Accumulator, queues queues) { +func (a *ActiveMQ) gatherQueuesMetrics(acc telegraf.Accumulator, queues queues) { for _, queue := range queues.QueueItems { records := make(map[string]interface{}) tags := make(map[string]string) @@ -179,7 +217,7 @@ func (a *ActiveMQ) GatherQueuesMetrics(acc telegraf.Accumulator, queues queues) } } -func (a *ActiveMQ) GatherTopicsMetrics(acc telegraf.Accumulator, topics topics) { +func (a *ActiveMQ) gatherTopicsMetrics(acc telegraf.Accumulator, topics topics) { for _, topic := range topics.TopicItems { records := make(map[string]interface{}) tags := make(map[string]string) @@ -197,7 +235,7 @@ func (a *ActiveMQ) GatherTopicsMetrics(acc telegraf.Accumulator, topics topics) } } -func (a *ActiveMQ) GatherSubscribersMetrics(acc telegraf.Accumulator, subscribers subscribers) { +func (a *ActiveMQ) gatherSubscribersMetrics(acc telegraf.Accumulator, subscribers subscribers) { for _, subscriber := range subscribers.SubscriberItems { records := make(map[string]interface{}) tags := make(map[string]string) @@ -221,55 +259,17 @@ func (a *ActiveMQ) GatherSubscribersMetrics(acc telegraf.Accumulator, subscriber } } -func (a *ActiveMQ) Gather(acc telegraf.Accumulator) error { - dataQueues, err := a.GetMetrics(a.QueuesURL()) - if err != nil { - return err - } - queues := queues{} - err = xml.Unmarshal(dataQueues, &queues) - if err != nil { - return fmt.Errorf("queues XML unmarshal error: %w", err) - } - - dataTopics, err := a.GetMetrics(a.TopicsURL()) - if err != nil { - return err - } - topics := topics{} - err = xml.Unmarshal(dataTopics, &topics) - if err != nil { - return fmt.Errorf("topics XML unmarshal error: %w", err) - } - - dataSubscribers, err := a.GetMetrics(a.SubscribersURL()) - if err != nil { - return err - } - subscribers := subscribers{} - err = xml.Unmarshal(dataSubscribers, &subscribers) - if err != nil { - return fmt.Errorf("subscribers XML unmarshal error: %w", err) - } - - a.GatherQueuesMetrics(acc, queues) - a.GatherTopicsMetrics(acc, topics) - a.GatherSubscribersMetrics(acc, subscribers) - - return nil -} - -func (a *ActiveMQ) QueuesURL() string { +func (a *ActiveMQ) queuesURL() string { ref := url.URL{Path: path.Join("/", a.Webadmin, "/xml/queues.jsp")} return a.baseURL.ResolveReference(&ref).String() } -func (a *ActiveMQ) TopicsURL() string { +func (a *ActiveMQ) topicsURL() string { ref := url.URL{Path: path.Join("/", a.Webadmin, "/xml/topics.jsp")} return a.baseURL.ResolveReference(&ref).String() } -func (a *ActiveMQ) SubscribersURL() string { +func (a *ActiveMQ) subscribersURL() string { ref := url.URL{Path: path.Join("/", a.Webadmin, "/xml/subscribers.jsp")} return a.baseURL.ResolveReference(&ref).String() } diff --git a/plugins/inputs/activemq/activemq_test.go b/plugins/inputs/activemq/activemq_test.go index 8bf78de37d828..cfece824c54a6 100644 --- a/plugins/inputs/activemq/activemq_test.go +++ b/plugins/inputs/activemq/activemq_test.go @@ -52,7 +52,7 @@ func TestGatherQueuesMetrics(t *testing.T) { require.NoError(t, plugin.Init()) var acc testutil.Accumulator - plugin.GatherQueuesMetrics(&acc, queues) + plugin.gatherQueuesMetrics(&acc, queues) acc.AssertContainsTaggedFields(t, "activemq_queues", records, tags) } @@ -98,7 +98,7 @@ func TestGatherTopicsMetrics(t *testing.T) { require.NoError(t, plugin.Init()) var acc testutil.Accumulator - plugin.GatherTopicsMetrics(&acc, topics) + plugin.gatherTopicsMetrics(&acc, topics) acc.AssertContainsTaggedFields(t, "activemq_topics", records, tags) } @@ -137,7 +137,7 @@ func TestGatherSubscribersMetrics(t *testing.T) { require.NoError(t, plugin.Init()) var acc testutil.Accumulator - plugin.GatherSubscribersMetrics(&acc, subscribers) + plugin.gatherSubscribersMetrics(&acc, subscribers) acc.AssertContainsTaggedFields(t, "activemq_subscribers", records, tags) } diff --git a/plugins/inputs/aliyuncms/aliyuncms.go b/plugins/inputs/aliyuncms/aliyuncms.go index be2b3d112dfe4..c20464c0fc44b 100644 --- a/plugins/inputs/aliyuncms/aliyuncms.go +++ b/plugins/inputs/aliyuncms/aliyuncms.go @@ -27,7 +27,6 @@ import ( var sampleConfig string type ( - // AliyunCMS is aliyun cms config info. AliyunCMS struct { AccessKeyID string `toml:"access_key_id"` AccessKeySecret string `toml:"access_key_secret"` @@ -43,7 +42,7 @@ type ( Period config.Duration `toml:"period"` Delay config.Duration `toml:"delay"` Project string `toml:"project"` - Metrics []*Metric `toml:"metrics"` + Metrics []*metric `toml:"metrics"` RateLimit int `toml:"ratelimit"` Log telegraf.Logger `toml:"-"` @@ -57,8 +56,8 @@ type ( measurement string } - // Metric describes what metrics to get - Metric struct { + // metric describes what metrics to get + metric struct { ObjectsFilter string `toml:"objects_filter"` MetricNames []string `toml:"names"` Dimensions string `toml:"dimensions"` // String representation of JSON dimensions @@ -74,11 +73,6 @@ type ( } - // Dimension describe how to get metrics - Dimension struct { - Value string `toml:"value"` - } - aliyuncmsClient interface { DescribeMetricList(request *cms.DescribeMetricListRequest) (response *cms.DescribeMetricListResponse, err error) } @@ -113,7 +107,6 @@ func (*AliyunCMS) SampleConfig() string { return sampleConfig } -// Init perform checks of plugin inputs and initialize internals func (s *AliyunCMS) Init() error { if s.Project == "" { return errors.New("project is not set") @@ -216,7 +209,6 @@ func (s *AliyunCMS) Start(telegraf.Accumulator) error { return nil } -// Gather implements telegraf.Inputs interface func (s *AliyunCMS) Gather(acc telegraf.Accumulator) error { s.updateWindow(time.Now()) @@ -225,16 +217,16 @@ func (s *AliyunCMS) Gather(acc telegraf.Accumulator) error { defer lmtr.Stop() var wg sync.WaitGroup - for _, metric := range s.Metrics { + for _, m := range s.Metrics { // Prepare internal structure with data from discovery - s.prepareTagsAndDimensions(metric) - wg.Add(len(metric.MetricNames)) - for _, metricName := range metric.MetricNames { + s.prepareTagsAndDimensions(m) + wg.Add(len(m.MetricNames)) + for _, metricName := range m.MetricNames { <-lmtr.C - go func(metricName string, metric *Metric) { + go func(metricName string, m *metric) { defer wg.Done() - acc.AddError(s.gatherMetric(acc, metricName, metric)) - }(metricName, metric) + acc.AddError(s.gatherMetric(acc, metricName, m)) + }(metricName, m) } wg.Wait() } @@ -269,7 +261,7 @@ func (s *AliyunCMS) updateWindow(relativeTo time.Time) { } // Gather given metric and emit error -func (s *AliyunCMS) gatherMetric(acc telegraf.Accumulator, metricName string, metric *Metric) error { +func (s *AliyunCMS) gatherMetric(acc telegraf.Accumulator, metricName string, metric *metric) error { for _, region := range s.Regions { req := cms.CreateDescribeMetricListRequest() req.Period = strconv.FormatInt(int64(time.Duration(s.Period).Seconds()), 10) @@ -372,7 +364,7 @@ func parseTag(tagSpec string, data interface{}) (tagKey, tagValue string, err er return tagKey, tagValue, nil } -func (s *AliyunCMS) prepareTagsAndDimensions(metric *Metric) { +func (s *AliyunCMS) prepareTagsAndDimensions(metric *metric) { var ( newData bool defaultTags = []string{"RegionId:RegionId"} diff --git a/plugins/inputs/aliyuncms/aliyuncms_test.go b/plugins/inputs/aliyuncms/aliyuncms_test.go index 5b0e48f770b3c..ebd7c8bfb23e2 100644 --- a/plugins/inputs/aliyuncms/aliyuncms_test.go +++ b/plugins/inputs/aliyuncms/aliyuncms_test.go @@ -240,7 +240,7 @@ func TestPluginMetricsInitialize(t *testing.T) { expectedErrorString string regions []string discoveryRegions []string - metrics []*Metric + metrics []*metric }{ { name: "Valid project", @@ -248,7 +248,7 @@ func TestPluginMetricsInitialize(t *testing.T) { regions: []string{"cn-shanghai"}, accessKeyID: "dummy", accessKeySecret: "dummy", - metrics: []*Metric{ + metrics: []*metric{ { MetricNames: []string{}, Dimensions: `{"instanceId": "i-abcdefgh123456"}`, @@ -261,7 +261,7 @@ func TestPluginMetricsInitialize(t *testing.T) { regions: []string{"cn-shanghai"}, accessKeyID: "dummy", accessKeySecret: "dummy", - metrics: []*Metric{ + metrics: []*metric{ { MetricNames: []string{}, Dimensions: `[{"instanceId": "p-example"},{"instanceId": "q-example"}]`, @@ -275,7 +275,7 @@ func TestPluginMetricsInitialize(t *testing.T) { accessKeyID: "dummy", accessKeySecret: "dummy", expectedErrorString: `cannot parse dimensions (neither obj, nor array) "[": unexpected end of JSON input`, - metrics: []*Metric{ + metrics: []*metric{ { MetricNames: []string{}, Dimensions: `[`, @@ -343,7 +343,7 @@ func TestGatherMetric(t *testing.T) { Regions: []string{"cn-shanghai"}, } - metric := &Metric{ + metric := &metric{ MetricNames: []string{}, Dimensions: `"instanceId": "i-abcdefgh123456"`, } @@ -374,7 +374,7 @@ func TestGatherMetric(t *testing.T) { } func TestGather(t *testing.T) { - metric := &Metric{ + m := &metric{ MetricNames: []string{}, Dimensions: `{"instanceId": "i-abcdefgh123456"}`, } @@ -382,7 +382,7 @@ func TestGather(t *testing.T) { AccessKeyID: "my_access_key_id", AccessKeySecret: "my_access_key_secret", Project: "acs_slb_dashboard", - Metrics: []*Metric{metric}, + Metrics: []*metric{m}, RateLimit: 200, measurement: formatMeasurement("acs_slb_dashboard"), Regions: []string{"cn-shanghai"}, diff --git a/plugins/inputs/aliyuncms/discovery.go b/plugins/inputs/aliyuncms/discovery.go index 9a72106477ca0..574570e14636f 100644 --- a/plugins/inputs/aliyuncms/discovery.go +++ b/plugins/inputs/aliyuncms/discovery.go @@ -395,8 +395,7 @@ func (dt *discoveryTool) getDiscoveryDataAcrossRegions(lmtr chan bool) (map[stri return resultData, nil } -// start the discovery pooling -// In case smth. new found it will be reported back through `DataChan` +// start the discovery pooling; in case something new is found, it will be reported back through `dataChan` func (dt *discoveryTool) start() { var ( err error @@ -443,8 +442,7 @@ func (dt *discoveryTool) start() { }() } -// stop the discovery loop, making sure -// all data is read from 'dataChan' +// stop the discovery loop, making sure all data is read from 'dataChan' func (dt *discoveryTool) stop() { close(dt.done) diff --git a/plugins/inputs/amd_rocm_smi/amd_rocm_smi.go b/plugins/inputs/amd_rocm_smi/amd_rocm_smi.go index 922fc56c066c2..d30f13ba6a334 100644 --- a/plugins/inputs/amd_rocm_smi/amd_rocm_smi.go +++ b/plugins/inputs/amd_rocm_smi/amd_rocm_smi.go @@ -28,18 +28,86 @@ type ROCmSMI struct { Log telegraf.Logger `toml:"-"` } -func (*ROCmSMI) SampleConfig() string { - return sampleConfig +type gpu struct { + DeviceID string `json:"Device ID"` + GpuID string `json:"GPU ID"` + GpuUniqueID string `json:"Unique ID"` + GpuVBIOSVersion string `json:"VBIOS version"` + GpuTemperatureSensorEdge string `json:"Temperature (Sensor edge) (C)"` + GpuTemperatureSensorJunction string `json:"Temperature (Sensor junction) (C)"` + GpuTemperatureSensorMemory string `json:"Temperature (Sensor memory) (C)"` + GpuDcefClkClockSpeed string `json:"dcefclk clock speed:"` + GpuDcefClkClockLevel string `json:"dcefclk clock level:"` + GpuFclkClockSpeed string `json:"fclk clock speed:"` + GpuFclkClockLevel string `json:"fclk clock level:"` + GpuMclkClockSpeed string `json:"mclk clock speed:"` + GpuMclkClockLevel string `json:"mclk clock level:"` + GpuSclkClockSpeed string `json:"sclk clock speed:"` + GpuSclkClockLevel string `json:"sclk clock level:"` + GpuSocclkClockSpeed string `json:"socclk clock speed:"` + GpuSocclkClockLevel string `json:"socclk clock level:"` + GpuPcieClock string `json:"pcie clock level"` + GpuFanSpeedLevel string `json:"Fan speed (level)"` + GpuFanSpeedPercentage string `json:"Fan speed (%)"` + GpuFanRPM string `json:"Fan RPM"` + GpuPerformanceLevel string `json:"Performance Level"` + GpuOverdrive string `json:"GPU OverDrive value (%)"` + GpuMaxPower string `json:"Max Graphics Package Power (W)"` + GpuAveragePower string `json:"Average Graphics Package Power (W)"` + GpuUsePercentage string `json:"GPU use (%)"` + GpuMemoryAllocatedPercentage string `json:"GPU Memory Allocated (VRAM%)"` + GpuMemoryUsePercentage string `json:"GPU memory use (%)"` + GpuMemoryVendor string `json:"GPU memory vendor"` + GpuPCIeReplay string `json:"PCIe Replay Count"` + GpuSerialNumber string `json:"Serial Number"` + GpuVoltagemV string `json:"Voltage (mV)"` + GpuPCIBus string `json:"PCI Bus"` + GpuASDDirmware string `json:"ASD firmware version"` + GpuCEFirmware string `json:"CE firmware version"` + GpuDMCUFirmware string `json:"DMCU firmware version"` + GpuMCFirmware string `json:"MC firmware version"` + GpuMEFirmware string `json:"ME firmware version"` + GpuMECFirmware string `json:"MEC firmware version"` + GpuMEC2Firmware string `json:"MEC2 firmware version"` + GpuPFPFirmware string `json:"PFP firmware version"` + GpuRLCFirmware string `json:"RLC firmware version"` + GpuRLCSRLC string `json:"RLC SRLC firmware version"` + GpuRLCSRLG string `json:"RLC SRLG firmware version"` + GpuRLCSRLS string `json:"RLC SRLS firmware version"` + GpuSDMAFirmware string `json:"SDMA firmware version"` + GpuSDMA2Firmware string `json:"SDMA2 firmware version"` + GpuSMCFirmware string `json:"SMC firmware version"` + GpuSOSFirmware string `json:"SOS firmware version"` + GpuTARAS string `json:"TA RAS firmware version"` + GpuTAXGMI string `json:"TA XGMI firmware version"` + GpuUVDFirmware string `json:"UVD firmware version"` + GpuVCEFirmware string `json:"VCE firmware version"` + GpuVCNFirmware string `json:"VCN firmware version"` + GpuCardSeries string `json:"Card series"` + GpuCardModel string `json:"Card model"` + GpuCardVendor string `json:"Card vendor"` + GpuCardSKU string `json:"Card SKU"` + GpuNUMANode string `json:"(Topology) Numa Node"` + GpuNUMAAffinity string `json:"(Topology) Numa Affinity"` + GpuVisVRAMTotalMemory string `json:"VIS_VRAM Total Memory (B)"` + GpuVisVRAMTotalUsedMemory string `json:"VIS_VRAM Total Used Memory (B)"` + GpuVRAMTotalMemory string `json:"VRAM Total Memory (B)"` + GpuVRAMTotalUsedMemory string `json:"VRAM Total Used Memory (B)"` + GpuGTTTotalMemory string `json:"GTT Total Memory (B)"` + GpuGTTTotalUsedMemory string `json:"GTT Total Used Memory (B)"` } -// Gather implements the telegraf interface -func (rsmi *ROCmSMI) Gather(acc telegraf.Accumulator) error { - data, err := rsmi.pollROCmSMI() - if err != nil { - return fmt.Errorf("failed to execute command in pollROCmSMI: %w", err) - } +type sysInfo struct { + DriverVersion string `json:"Driver version"` +} - return gatherROCmSMI(data, acc) +type metric struct { + tags map[string]string + fields map[string]interface{} +} + +func (*ROCmSMI) SampleConfig() string { + return sampleConfig } func (rsmi *ROCmSMI) Start(telegraf.Accumulator) error { @@ -54,17 +122,17 @@ func (rsmi *ROCmSMI) Start(telegraf.Accumulator) error { return nil } -func (rsmi *ROCmSMI) Stop() {} +func (rsmi *ROCmSMI) Gather(acc telegraf.Accumulator) error { + data, err := rsmi.pollROCmSMI() + if err != nil { + return fmt.Errorf("failed to execute command in pollROCmSMI: %w", err) + } -func init() { - inputs.Add("amd_rocm_smi", func() telegraf.Input { - return &ROCmSMI{ - BinPath: "/opt/rocm/bin/rocm-smi", - Timeout: config.Duration(5 * time.Second), - } - }) + return gatherROCmSMI(data, acc) } +func (rsmi *ROCmSMI) Stop() {} + func (rsmi *ROCmSMI) pollROCmSMI() ([]byte, error) { // Construct and execute metrics query, there currently exist (ROCm v4.3.x) a "-a" option // that does not provide all the information, so each needed parameter is set manually @@ -111,34 +179,7 @@ func (rsmi *ROCmSMI) pollROCmSMI() ([]byte, error) { return internal.StdOutputTimeout(cmd, time.Duration(rsmi.Timeout)) } -func gatherROCmSMI(ret []byte, acc telegraf.Accumulator) error { - var gpus map[string]GPU - var sys map[string]sysInfo - - err1 := json.Unmarshal(ret, &gpus) - if err1 != nil { - return err1 - } - - err2 := json.Unmarshal(ret, &sys) - if err2 != nil { - return err2 - } - - metrics := genTagsFields(gpus, sys) - for _, metric := range metrics { - acc.AddFields(measurement, metric.fields, metric.tags) - } - - return nil -} - -type metric struct { - tags map[string]string - fields map[string]interface{} -} - -func genTagsFields(gpus map[string]GPU, system map[string]sysInfo) []metric { +func genTagsFields(gpus map[string]gpu, system map[string]sysInfo) []metric { metrics := []metric{} for cardID := range gpus { if strings.Contains(cardID, "card") { @@ -189,6 +230,28 @@ func genTagsFields(gpus map[string]GPU, system map[string]sysInfo) []metric { return metrics } +func gatherROCmSMI(ret []byte, acc telegraf.Accumulator) error { + var gpus map[string]gpu + var sys map[string]sysInfo + + err1 := json.Unmarshal(ret, &gpus) + if err1 != nil { + return err1 + } + + err2 := json.Unmarshal(ret, &sys) + if err2 != nil { + return err2 + } + + metrics := genTagsFields(gpus, sys) + for _, metric := range metrics { + acc.AddFields(measurement, metric.fields, metric.tags) + } + + return nil +} + func setTagIfUsed(m map[string]string, k, v string) { if v != "" { m[k] = v @@ -232,75 +295,11 @@ func setIfUsed(t string, m map[string]interface{}, k, v string) { } } -type sysInfo struct { - DriverVersion string `json:"Driver version"` -} - -type GPU struct { - DeviceID string `json:"Device ID"` - GpuID string `json:"GPU ID"` - GpuUniqueID string `json:"Unique ID"` - GpuVBIOSVersion string `json:"VBIOS version"` - GpuTemperatureSensorEdge string `json:"Temperature (Sensor edge) (C)"` - GpuTemperatureSensorJunction string `json:"Temperature (Sensor junction) (C)"` - GpuTemperatureSensorMemory string `json:"Temperature (Sensor memory) (C)"` - GpuDcefClkClockSpeed string `json:"dcefclk clock speed:"` - GpuDcefClkClockLevel string `json:"dcefclk clock level:"` - GpuFclkClockSpeed string `json:"fclk clock speed:"` - GpuFclkClockLevel string `json:"fclk clock level:"` - GpuMclkClockSpeed string `json:"mclk clock speed:"` - GpuMclkClockLevel string `json:"mclk clock level:"` - GpuSclkClockSpeed string `json:"sclk clock speed:"` - GpuSclkClockLevel string `json:"sclk clock level:"` - GpuSocclkClockSpeed string `json:"socclk clock speed:"` - GpuSocclkClockLevel string `json:"socclk clock level:"` - GpuPcieClock string `json:"pcie clock level"` - GpuFanSpeedLevel string `json:"Fan speed (level)"` - GpuFanSpeedPercentage string `json:"Fan speed (%)"` - GpuFanRPM string `json:"Fan RPM"` - GpuPerformanceLevel string `json:"Performance Level"` - GpuOverdrive string `json:"GPU OverDrive value (%)"` - GpuMaxPower string `json:"Max Graphics Package Power (W)"` - GpuAveragePower string `json:"Average Graphics Package Power (W)"` - GpuUsePercentage string `json:"GPU use (%)"` - GpuMemoryAllocatedPercentage string `json:"GPU Memory Allocated (VRAM%)"` - GpuMemoryUsePercentage string `json:"GPU memory use (%)"` - GpuMemoryVendor string `json:"GPU memory vendor"` - GpuPCIeReplay string `json:"PCIe Replay Count"` - GpuSerialNumber string `json:"Serial Number"` - GpuVoltagemV string `json:"Voltage (mV)"` - GpuPCIBus string `json:"PCI Bus"` - GpuASDDirmware string `json:"ASD firmware version"` - GpuCEFirmware string `json:"CE firmware version"` - GpuDMCUFirmware string `json:"DMCU firmware version"` - GpuMCFirmware string `json:"MC firmware version"` - GpuMEFirmware string `json:"ME firmware version"` - GpuMECFirmware string `json:"MEC firmware version"` - GpuMEC2Firmware string `json:"MEC2 firmware version"` - GpuPFPFirmware string `json:"PFP firmware version"` - GpuRLCFirmware string `json:"RLC firmware version"` - GpuRLCSRLC string `json:"RLC SRLC firmware version"` - GpuRLCSRLG string `json:"RLC SRLG firmware version"` - GpuRLCSRLS string `json:"RLC SRLS firmware version"` - GpuSDMAFirmware string `json:"SDMA firmware version"` - GpuSDMA2Firmware string `json:"SDMA2 firmware version"` - GpuSMCFirmware string `json:"SMC firmware version"` - GpuSOSFirmware string `json:"SOS firmware version"` - GpuTARAS string `json:"TA RAS firmware version"` - GpuTAXGMI string `json:"TA XGMI firmware version"` - GpuUVDFirmware string `json:"UVD firmware version"` - GpuVCEFirmware string `json:"VCE firmware version"` - GpuVCNFirmware string `json:"VCN firmware version"` - GpuCardSeries string `json:"Card series"` - GpuCardModel string `json:"Card model"` - GpuCardVendor string `json:"Card vendor"` - GpuCardSKU string `json:"Card SKU"` - GpuNUMANode string `json:"(Topology) Numa Node"` - GpuNUMAAffinity string `json:"(Topology) Numa Affinity"` - GpuVisVRAMTotalMemory string `json:"VIS_VRAM Total Memory (B)"` - GpuVisVRAMTotalUsedMemory string `json:"VIS_VRAM Total Used Memory (B)"` - GpuVRAMTotalMemory string `json:"VRAM Total Memory (B)"` - GpuVRAMTotalUsedMemory string `json:"VRAM Total Used Memory (B)"` - GpuGTTTotalMemory string `json:"GTT Total Memory (B)"` - GpuGTTTotalUsedMemory string `json:"GTT Total Used Memory (B)"` +func init() { + inputs.Add("amd_rocm_smi", func() telegraf.Input { + return &ROCmSMI{ + BinPath: "/opt/rocm/bin/rocm-smi", + Timeout: config.Duration(5 * time.Second), + } + }) } diff --git a/plugins/inputs/amqp_consumer/amqp_consumer.go b/plugins/inputs/amqp_consumer/amqp_consumer.go index f1e2fa8d0134f..dba902bce4eab 100644 --- a/plugins/inputs/amqp_consumer/amqp_consumer.go +++ b/plugins/inputs/amqp_consumer/amqp_consumer.go @@ -26,9 +26,10 @@ var sampleConfig string var once sync.Once type empty struct{} +type externalAuth struct{} + type semaphore chan empty -// AMQPConsumer is the top level struct for this plugin type AMQPConsumer struct { URL string `toml:"url" deprecated:"1.7.0;1.35.0;use 'brokers' instead"` Brokers []string `toml:"brokers"` @@ -62,11 +63,10 @@ type AMQPConsumer struct { decoder internal.ContentDecoder } -type externalAuth struct{} - func (a *externalAuth) Mechanism() string { return "EXTERNAL" } + func (a *externalAuth) Response() string { return "\000" } @@ -115,51 +115,6 @@ func (a *AMQPConsumer) SetParser(parser telegraf.Parser) { a.parser = parser } -// All gathering is done in the Start function -func (a *AMQPConsumer) Gather(_ telegraf.Accumulator) error { - return nil -} - -func (a *AMQPConsumer) createConfig() (*amqp.Config, error) { - // make new tls config - tlsCfg, err := a.ClientConfig.TLSConfig() - if err != nil { - return nil, err - } - - var auth []amqp.Authentication - - if strings.EqualFold(a.AuthMethod, "EXTERNAL") { - auth = []amqp.Authentication{&externalAuth{}} - } else if !a.Username.Empty() || !a.Password.Empty() { - username, err := a.Username.Get() - if err != nil { - return nil, fmt.Errorf("getting username failed: %w", err) - } - defer username.Destroy() - - password, err := a.Password.Get() - if err != nil { - return nil, fmt.Errorf("getting password failed: %w", err) - } - defer password.Destroy() - - auth = []amqp.Authentication{ - &amqp.PlainAuth{ - Username: username.String(), - Password: password.String(), - }, - } - } - amqpConfig := amqp.Config{ - TLSClientConfig: tlsCfg, - SASL: auth, // if nil, it will be PLAIN - Dial: amqp.DefaultDial(time.Duration(a.Timeout)), - } - return &amqpConfig, nil -} - -// Start satisfies the telegraf.ServiceInput interface func (a *AMQPConsumer) Start(acc telegraf.Accumulator) error { amqpConf, err := a.createConfig() if err != nil { @@ -219,6 +174,63 @@ func (a *AMQPConsumer) Start(acc telegraf.Accumulator) error { return nil } +func (a *AMQPConsumer) Gather(_ telegraf.Accumulator) error { + return nil +} + +func (a *AMQPConsumer) Stop() { + // We did not connect successfully so there is nothing to do here. + if a.conn == nil || a.conn.IsClosed() { + return + } + a.cancel() + a.wg.Wait() + err := a.conn.Close() + if err != nil && !errors.Is(err, amqp.ErrClosed) { + a.Log.Errorf("Error closing AMQP connection: %s", err) + return + } +} + +func (a *AMQPConsumer) createConfig() (*amqp.Config, error) { + // make new tls config + tlsCfg, err := a.ClientConfig.TLSConfig() + if err != nil { + return nil, err + } + + var auth []amqp.Authentication + + if strings.EqualFold(a.AuthMethod, "EXTERNAL") { + auth = []amqp.Authentication{&externalAuth{}} + } else if !a.Username.Empty() || !a.Password.Empty() { + username, err := a.Username.Get() + if err != nil { + return nil, fmt.Errorf("getting username failed: %w", err) + } + defer username.Destroy() + + password, err := a.Password.Get() + if err != nil { + return nil, fmt.Errorf("getting password failed: %w", err) + } + defer password.Destroy() + + auth = []amqp.Authentication{ + &amqp.PlainAuth{ + Username: username.String(), + Password: password.String(), + }, + } + } + amqpConfig := amqp.Config{ + TLSClientConfig: tlsCfg, + SASL: auth, // if nil, it will be PLAIN + Dial: amqp.DefaultDial(time.Duration(a.Timeout)), + } + return &amqpConfig, nil +} + func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, error) { brokers := a.Brokers @@ -477,20 +489,6 @@ func (a *AMQPConsumer) onDelivery(track telegraf.DeliveryInfo) bool { return true } -func (a *AMQPConsumer) Stop() { - // We did not connect successfully so there is nothing to do here. - if a.conn == nil || a.conn.IsClosed() { - return - } - a.cancel() - a.wg.Wait() - err := a.conn.Close() - if err != nil && !errors.Is(err, amqp.ErrClosed) { - a.Log.Errorf("Error closing AMQP connection: %s", err) - return - } -} - func init() { inputs.Add("amqp_consumer", func() telegraf.Input { return &AMQPConsumer{Timeout: config.Duration(30 * time.Second)} diff --git a/plugins/inputs/apcupsd/apcupsd_test.go b/plugins/inputs/apcupsd/apcupsd_test.go index 5ea9af55cd154..1ce26542d2419 100644 --- a/plugins/inputs/apcupsd/apcupsd_test.go +++ b/plugins/inputs/apcupsd/apcupsd_test.go @@ -1,6 +1,7 @@ package apcupsd import ( + "bytes" "context" "encoding/binary" "net" @@ -44,22 +45,34 @@ func listen(ctx context.Context, t *testing.T, out [][]byte) (string, error) { return } defer conn.Close() - require.NoError(t, conn.SetReadDeadline(time.Now().Add(time.Second))) + + if err = conn.SetReadDeadline(time.Now().Add(time.Second)); err != nil { + t.Error(err) + return + } in := make([]byte, 128) n, err := conn.Read(in) - require.NoError(t, err, "failed to read from connection") + if err != nil { + t.Errorf("Failed to read to connection: %v", err) + return + } status := []byte{0, 6, 's', 't', 'a', 't', 'u', 's'} want, got := status, in[:n] - require.Equal(t, want, got) + if !bytes.Equal(want, got) { + t.Errorf("expected %q, got %q", want, got) + return + } // Run against test function and append EOF to end of output bytes out = append(out, []byte{0, 0}) for _, o := range out { - _, err := conn.Write(o) - require.NoError(t, err, "failed to write to connection") + if _, err := conn.Write(o); err != nil { + t.Errorf("Failed to write to connection: %v", err) + return + } } }() } diff --git a/plugins/inputs/aurora/aurora.go b/plugins/inputs/aurora/aurora.go index a76ca835df4ed..e8b10c11a1699 100644 --- a/plugins/inputs/aurora/aurora.go +++ b/plugins/inputs/aurora/aurora.go @@ -21,19 +21,19 @@ import ( //go:embed sample.conf var sampleConfig string -type RoleType int +type roleType int const ( - Unknown RoleType = iota - Leader - Follower + unknown roleType = iota + leader + follower ) -func (r RoleType) String() string { +func (r roleType) String() string { switch r { - case Leader: + case leader: return "leader" - case Follower: + case follower: return "follower" default: return "unknown" @@ -45,7 +45,7 @@ var ( defaultRoles = []string{"leader", "follower"} ) -type Vars map[string]interface{} +type vars map[string]interface{} type Aurora struct { Schedulers []string `toml:"schedulers"` @@ -136,7 +136,7 @@ func (a *Aurora) initialize() error { return nil } -func (a *Aurora) roleEnabled(role RoleType) bool { +func (a *Aurora) roleEnabled(role roleType) bool { if len(a.Roles) == 0 { return true } @@ -149,12 +149,12 @@ func (a *Aurora) roleEnabled(role RoleType) bool { return false } -func (a *Aurora) gatherRole(ctx context.Context, origin *url.URL) (RoleType, error) { +func (a *Aurora) gatherRole(ctx context.Context, origin *url.URL) (roleType, error) { loc := *origin loc.Path = "leaderhealth" req, err := http.NewRequest("GET", loc.String(), nil) if err != nil { - return Unknown, err + return unknown, err } if a.Username != "" || a.Password != "" { @@ -164,26 +164,26 @@ func (a *Aurora) gatherRole(ctx context.Context, origin *url.URL) (RoleType, err resp, err := a.client.Do(req.WithContext(ctx)) if err != nil { - return Unknown, err + return unknown, err } if err := resp.Body.Close(); err != nil { - return Unknown, fmt.Errorf("closing body failed: %w", err) + return unknown, fmt.Errorf("closing body failed: %w", err) } switch resp.StatusCode { case http.StatusOK: - return Leader, nil + return leader, nil case http.StatusBadGateway: fallthrough case http.StatusServiceUnavailable: - return Follower, nil + return follower, nil default: - return Unknown, fmt.Errorf("%v", resp.Status) + return unknown, fmt.Errorf("%v", resp.Status) } } func (a *Aurora) gatherScheduler( - ctx context.Context, origin *url.URL, role RoleType, acc telegraf.Accumulator, + ctx context.Context, origin *url.URL, role roleType, acc telegraf.Accumulator, ) error { loc := *origin loc.Path = "vars.json" @@ -207,16 +207,16 @@ func (a *Aurora) gatherScheduler( return fmt.Errorf("%v", resp.Status) } - var vars Vars + var metrics vars decoder := json.NewDecoder(resp.Body) decoder.UseNumber() - err = decoder.Decode(&vars) + err = decoder.Decode(&metrics) if err != nil { return fmt.Errorf("decoding response: %w", err) } - var fields = make(map[string]interface{}, len(vars)) - for k, v := range vars { + var fields = make(map[string]interface{}, len(metrics)) + for k, v := range metrics { switch v := v.(type) { case json.Number: // Aurora encodes numbers as you would specify them as a literal, diff --git a/plugins/inputs/aurora/aurora_test.go b/plugins/inputs/aurora/aurora_test.go index 6eeaa93f4809e..b43949f25f897 100644 --- a/plugins/inputs/aurora/aurora_test.go +++ b/plugins/inputs/aurora/aurora_test.go @@ -12,8 +12,8 @@ import ( ) type ( - TestHandlerFunc func(t *testing.T, w http.ResponseWriter, r *http.Request) - CheckFunc func(t *testing.T, err error, acc *testutil.Accumulator) + testHandlerFunc func(t *testing.T, w http.ResponseWriter, r *http.Request) + checkFunc func(t *testing.T, err error, acc *testutil.Accumulator) ) func TestAurora(t *testing.T) { @@ -28,9 +28,9 @@ func TestAurora(t *testing.T) { plugin *Aurora schedulers []string roles []string - leaderhealth TestHandlerFunc - varsjson TestHandlerFunc - check CheckFunc + leaderhealth testHandlerFunc + varsjson testHandlerFunc + check checkFunc }{ { name: "minimal", diff --git a/plugins/inputs/azure_monitor/azure_monitor.go b/plugins/inputs/azure_monitor/azure_monitor.go index 610007a299f93..93b3627bf47d4 100644 --- a/plugins/inputs/azure_monitor/azure_monitor.go +++ b/plugins/inputs/azure_monitor/azure_monitor.go @@ -21,9 +21,9 @@ type AzureMonitor struct { ClientSecret string `toml:"client_secret"` TenantID string `toml:"tenant_id"` CloudOption string `toml:"cloud_option,omitempty"` - ResourceTargets []*ResourceTarget `toml:"resource_target"` - ResourceGroupTargets []*ResourceGroupTarget `toml:"resource_group_target"` - SubscriptionTargets []*Resource `toml:"subscription_target"` + ResourceTargets []*resourceTarget `toml:"resource_target"` + ResourceGroupTargets []*resourceGroupTarget `toml:"resource_group_target"` + SubscriptionTargets []*resource `toml:"subscription_target"` Log telegraf.Logger `toml:"-"` receiver *receiver.AzureMonitorMetricsReceiver @@ -31,18 +31,18 @@ type AzureMonitor struct { azureClients *receiver.AzureClients } -type ResourceTarget struct { +type resourceTarget struct { ResourceID string `toml:"resource_id"` Metrics []string `toml:"metrics"` Aggregations []string `toml:"aggregations"` } -type ResourceGroupTarget struct { +type resourceGroupTarget struct { ResourceGroup string `toml:"resource_group"` - Resources []*Resource `toml:"resource"` + Resources []*resource `toml:"resource"` } -type Resource struct { +type resource struct { ResourceType string `toml:"resource_type"` Metrics []string `toml:"metrics"` Aggregations []string `toml:"aggregations"` @@ -62,7 +62,6 @@ func (am *AzureMonitor) SampleConfig() string { return sampleConfig } -// Init is for setup, and validating config. func (am *AzureMonitor) Init() error { var clientOptions azcore.ClientOptions switch am.CloudOption { diff --git a/plugins/inputs/azure_storage_queue/azure_storage_queue.go b/plugins/inputs/azure_storage_queue/azure_storage_queue.go index d65a8fe7b329e..d8100e7a5f0de 100644 --- a/plugins/inputs/azure_storage_queue/azure_storage_queue.go +++ b/plugins/inputs/azure_storage_queue/azure_storage_queue.go @@ -42,45 +42,8 @@ func (a *AzureStorageQueue) Init() error { return nil } -func (a *AzureStorageQueue) GetServiceURL() (azqueue.ServiceURL, error) { - if a.serviceURL == nil { - _url, err := url.Parse("https://" + a.StorageAccountName + ".queue.core.windows.net") - if err != nil { - return azqueue.ServiceURL{}, err - } - - credential, err := azqueue.NewSharedKeyCredential(a.StorageAccountName, a.StorageAccountKey) - if err != nil { - return azqueue.ServiceURL{}, err - } - - pipeline := azqueue.NewPipeline(credential, azqueue.PipelineOptions{}) - - serviceURL := azqueue.NewServiceURL(*_url, pipeline) - a.serviceURL = &serviceURL - } - return *a.serviceURL, nil -} - -func (a *AzureStorageQueue) GatherQueueMetrics( - acc telegraf.Accumulator, - queueItem azqueue.QueueItem, - properties *azqueue.QueueGetPropertiesResponse, - peekedMessage *azqueue.PeekedMessage, -) { - fields := make(map[string]interface{}) - tags := make(map[string]string) - tags["queue"] = strings.TrimSpace(queueItem.Name) - tags["account"] = a.StorageAccountName - fields["size"] = properties.ApproximateMessagesCount() - if peekedMessage != nil { - fields["oldest_message_age_ns"] = time.Now().UnixNano() - peekedMessage.InsertionTime.UnixNano() - } - acc.AddFields("azure_storage_queues", fields, tags) -} - func (a *AzureStorageQueue) Gather(acc telegraf.Accumulator) error { - serviceURL, err := a.GetServiceURL() + serviceURL, err := a.getServiceURL() if err != nil { return err } @@ -117,12 +80,49 @@ func (a *AzureStorageQueue) Gather(acc telegraf.Accumulator) error { } } - a.GatherQueueMetrics(acc, queueItem, properties, peekedMessage) + a.gatherQueueMetrics(acc, queueItem, properties, peekedMessage) } } return nil } +func (a *AzureStorageQueue) getServiceURL() (azqueue.ServiceURL, error) { + if a.serviceURL == nil { + _url, err := url.Parse("https://" + a.StorageAccountName + ".queue.core.windows.net") + if err != nil { + return azqueue.ServiceURL{}, err + } + + credential, err := azqueue.NewSharedKeyCredential(a.StorageAccountName, a.StorageAccountKey) + if err != nil { + return azqueue.ServiceURL{}, err + } + + pipeline := azqueue.NewPipeline(credential, azqueue.PipelineOptions{}) + + serviceURL := azqueue.NewServiceURL(*_url, pipeline) + a.serviceURL = &serviceURL + } + return *a.serviceURL, nil +} + +func (a *AzureStorageQueue) gatherQueueMetrics( + acc telegraf.Accumulator, + queueItem azqueue.QueueItem, + properties *azqueue.QueueGetPropertiesResponse, + peekedMessage *azqueue.PeekedMessage, +) { + fields := make(map[string]interface{}) + tags := make(map[string]string) + tags["queue"] = strings.TrimSpace(queueItem.Name) + tags["account"] = a.StorageAccountName + fields["size"] = properties.ApproximateMessagesCount() + if peekedMessage != nil { + fields["oldest_message_age_ns"] = time.Now().UnixNano() - peekedMessage.InsertionTime.UnixNano() + } + acc.AddFields("azure_storage_queues", fields, tags) +} + func init() { inputs.Add("azure_storage_queue", func() telegraf.Input { return &AzureStorageQueue{PeekOldestMessageAge: true} diff --git a/plugins/inputs/bcache/bcache.go b/plugins/inputs/bcache/bcache.go index 2157fad55a8a1..37114a2d921a1 100644 --- a/plugins/inputs/bcache/bcache.go +++ b/plugins/inputs/bcache/bcache.go @@ -20,8 +20,44 @@ import ( var sampleConfig string type Bcache struct { - BcachePath string - BcacheDevs []string + BcachePath string `toml:"bcachePath"` + BcacheDevs []string `toml:"bcacheDevs"` +} + +func (*Bcache) SampleConfig() string { + return sampleConfig +} + +func (b *Bcache) Gather(acc telegraf.Accumulator) error { + bcacheDevsChecked := make(map[string]bool) + var restrictDevs bool + if len(b.BcacheDevs) != 0 { + restrictDevs = true + for _, bcacheDev := range b.BcacheDevs { + bcacheDevsChecked[bcacheDev] = true + } + } + + bcachePath := b.BcachePath + if len(bcachePath) == 0 { + bcachePath = "/sys/fs/bcache" + } + bdevs, err := filepath.Glob(bcachePath + "/*/bdev*") + if len(bdevs) < 1 || err != nil { + return errors.New("can't find any bcache device") + } + for _, bdev := range bdevs { + if restrictDevs { + bcacheDev := getTags(bdev)["bcache_dev"] + if !bcacheDevsChecked[bcacheDev] { + continue + } + } + if err := b.gatherBcache(bdev, acc); err != nil { + return fmt.Errorf("gathering bcache failed: %w", err) + } + } + return nil } func getTags(bdev string) map[string]string { @@ -102,42 +138,6 @@ func (b *Bcache) gatherBcache(bdev string, acc telegraf.Accumulator) error { return nil } -func (*Bcache) SampleConfig() string { - return sampleConfig -} - -func (b *Bcache) Gather(acc telegraf.Accumulator) error { - bcacheDevsChecked := make(map[string]bool) - var restrictDevs bool - if len(b.BcacheDevs) != 0 { - restrictDevs = true - for _, bcacheDev := range b.BcacheDevs { - bcacheDevsChecked[bcacheDev] = true - } - } - - bcachePath := b.BcachePath - if len(bcachePath) == 0 { - bcachePath = "/sys/fs/bcache" - } - bdevs, err := filepath.Glob(bcachePath + "/*/bdev*") - if len(bdevs) < 1 || err != nil { - return errors.New("can't find any bcache device") - } - for _, bdev := range bdevs { - if restrictDevs { - bcacheDev := getTags(bdev)["bcache_dev"] - if !bcacheDevsChecked[bcacheDev] { - continue - } - } - if err := b.gatherBcache(bdev, acc); err != nil { - return fmt.Errorf("gathering bcache failed: %w", err) - } - } - return nil -} - func init() { inputs.Add("bcache", func() telegraf.Input { return &Bcache{} diff --git a/plugins/inputs/beat/beat.go b/plugins/inputs/beat/beat.go index 3296f95ccfc21..e4b121ada19f0 100644 --- a/plugins/inputs/beat/beat.go +++ b/plugins/inputs/beat/beat.go @@ -20,23 +20,10 @@ import ( //go:embed sample.conf var sampleConfig string -const suffixInfo = "/" -const suffixStats = "/stats" - -type Info struct { - Beat string `json:"beat"` - Hostname string `json:"hostname"` - Name string `json:"name"` - UUID string `json:"uuid"` - Version string `json:"version"` -} - -type Stats struct { - Beat map[string]interface{} `json:"beat"` - FileBeat interface{} `json:"filebeat"` - Libbeat interface{} `json:"libbeat"` - System interface{} `json:"system"` -} +const ( + suffixInfo = "/" + suffixStats = "/stats" +) type Beat struct { URL string `toml:"url"` @@ -54,14 +41,19 @@ type Beat struct { client *http.Client } -func NewBeat() *Beat { - return &Beat{ - URL: "http://127.0.0.1:5066", - Includes: []string{"beat", "libbeat", "filebeat"}, - Method: "GET", - Headers: make(map[string]string), - Timeout: config.Duration(time.Second * 5), - } +type info struct { + Beat string `json:"beat"` + Hostname string `json:"hostname"` + Name string `json:"name"` + UUID string `json:"uuid"` + Version string `json:"version"` +} + +type stats struct { + Beat map[string]interface{} `json:"beat"` + FileBeat interface{} `json:"filebeat"` + LibBeat interface{} `json:"libbeat"` + System interface{} `json:"system"` } func (*Beat) SampleConfig() string { @@ -86,53 +78,9 @@ func (beat *Beat) Init() error { return nil } -// createHTTPClient create a clients to access API -func (beat *Beat) createHTTPClient() (*http.Client, error) { - tlsConfig, err := beat.ClientConfig.TLSConfig() - if err != nil { - return nil, err - } - - client := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: tlsConfig, - }, - Timeout: time.Duration(beat.Timeout), - } - - return client, nil -} - -// gatherJSONData query the data source and parse the response JSON -func (beat *Beat) gatherJSONData(address string, value interface{}) error { - request, err := http.NewRequest(beat.Method, address, nil) - if err != nil { - return err - } - - if beat.Username != "" { - request.SetBasicAuth(beat.Username, beat.Password) - } - for k, v := range beat.Headers { - request.Header.Add(k, v) - } - if beat.HostHeader != "" { - request.Host = beat.HostHeader - } - - response, err := beat.client.Do(request) - if err != nil { - return err - } - - defer response.Body.Close() - - return json.NewDecoder(response.Body).Decode(value) -} - func (beat *Beat) Gather(accumulator telegraf.Accumulator) error { - beatStats := &Stats{} - beatInfo := &Info{} + beatStats := &stats{} + beatInfo := &info{} infoURL, err := url.Parse(beat.URL + suffixInfo) if err != nil { @@ -175,7 +123,7 @@ func (beat *Beat) Gather(accumulator telegraf.Accumulator) error { stats = beatStats.System metric = "beat_system" case "libbeat": - stats = beatStats.Libbeat + stats = beatStats.LibBeat metric = "beat_libbeat" default: return fmt.Errorf("unknown stats-type %q", name) @@ -191,8 +139,62 @@ func (beat *Beat) Gather(accumulator telegraf.Accumulator) error { return nil } +// createHTTPClient create a clients to access API +func (beat *Beat) createHTTPClient() (*http.Client, error) { + tlsConfig, err := beat.ClientConfig.TLSConfig() + if err != nil { + return nil, err + } + + client := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: tlsConfig, + }, + Timeout: time.Duration(beat.Timeout), + } + + return client, nil +} + +// gatherJSONData query the data source and parse the response JSON +func (beat *Beat) gatherJSONData(address string, value interface{}) error { + request, err := http.NewRequest(beat.Method, address, nil) + if err != nil { + return err + } + + if beat.Username != "" { + request.SetBasicAuth(beat.Username, beat.Password) + } + for k, v := range beat.Headers { + request.Header.Add(k, v) + } + if beat.HostHeader != "" { + request.Host = beat.HostHeader + } + + response, err := beat.client.Do(request) + if err != nil { + return err + } + + defer response.Body.Close() + + return json.NewDecoder(response.Body).Decode(value) +} + +func newBeat() *Beat { + return &Beat{ + URL: "http://127.0.0.1:5066", + Includes: []string{"beat", "libbeat", "filebeat"}, + Method: "GET", + Headers: make(map[string]string), + Timeout: config.Duration(time.Second * 5), + } +} + func init() { inputs.Add("beat", func() telegraf.Input { - return NewBeat() + return newBeat() }) } diff --git a/plugins/inputs/beat/beat_test.go b/plugins/inputs/beat/beat_test.go index fae8818f49f3d..c9b9d6071a626 100644 --- a/plugins/inputs/beat/beat_test.go +++ b/plugins/inputs/beat/beat_test.go @@ -16,7 +16,7 @@ import ( func Test_BeatStats(t *testing.T) { var beat6StatsAccumulator testutil.Accumulator - var beatTest = NewBeat() + var beatTest = newBeat() // System stats are disabled by default beatTest.Includes = []string{"beat", "libbeat", "system", "filebeat"} require.NoError(t, beatTest.Init()) @@ -160,7 +160,7 @@ func Test_BeatStats(t *testing.T) { func Test_BeatRequest(t *testing.T) { var beat6StatsAccumulator testutil.Accumulator - beatTest := NewBeat() + beatTest := newBeat() // System stats are disabled by default beatTest.Includes = []string{"beat", "libbeat", "system", "filebeat"} require.NoError(t, beatTest.Init()) diff --git a/plugins/inputs/bond/bond.go b/plugins/inputs/bond/bond.go index 929d469510fe3..fb5bded85492e 100644 --- a/plugins/inputs/bond/bond.go +++ b/plugins/inputs/bond/bond.go @@ -17,13 +17,12 @@ import ( //go:embed sample.conf var sampleConfig string -// default host proc path -const defaultHostProc = "/proc" -const defaultHostSys = "/sys" - -// env host proc variable name -const envProc = "HOST_PROC" -const envSys = "HOST_SYS" +const ( + defaultHostProc = "/proc" + defaultHostSys = "/sys" + envProc = "HOST_PROC" + envSys = "HOST_SYS" +) type Bond struct { HostProc string `toml:"host_proc"` @@ -137,7 +136,7 @@ func (bond *Bond) gatherBondPart(bondName, rawFile string, acc telegraf.Accumula if err := scanner.Err(); err != nil { return err } - return fmt.Errorf("Couldn't find status info for %q", bondName) + return fmt.Errorf("couldn't find status info for %q", bondName) } func (bond *Bond) readSysFiles(bondDir string) (sysFiles, error) { diff --git a/plugins/inputs/burrow/burrow.go b/plugins/inputs/burrow/burrow.go index c58f2f24b9264..0cdf8a00bf8b9 100644 --- a/plugins/inputs/burrow/burrow.go +++ b/plugins/inputs/burrow/burrow.go @@ -31,7 +31,7 @@ const ( ) type ( - burrow struct { + Burrow struct { tls.ClientConfig Servers []string @@ -91,17 +91,11 @@ type ( } ) -func init() { - inputs.Add("burrow", func() telegraf.Input { - return &burrow{} - }) -} - -func (*burrow) SampleConfig() string { +func (*Burrow) SampleConfig() string { return sampleConfig } -func (b *burrow) Gather(acc telegraf.Accumulator) error { +func (b *Burrow) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup if len(b.Servers) == 0 { @@ -141,7 +135,7 @@ func (b *burrow) Gather(acc telegraf.Accumulator) error { return nil } -func (b *burrow) setDefaults() { +func (b *Burrow) setDefaults() { if b.APIPrefix == "" { b.APIPrefix = defaultBurrowPrefix } @@ -153,7 +147,7 @@ func (b *burrow) setDefaults() { } } -func (b *burrow) compileGlobs() error { +func (b *Burrow) compileGlobs() error { var err error // compile glob patterns @@ -172,7 +166,7 @@ func (b *burrow) compileGlobs() error { return nil } -func (b *burrow) createClient() (*http.Client, error) { +func (b *Burrow) createClient() (*http.Client, error) { tlsCfg, err := b.ClientConfig.TLSConfig() if err != nil { return nil, err @@ -199,7 +193,7 @@ func (b *burrow) createClient() (*http.Client, error) { return client, nil } -func (b *burrow) getResponse(u *url.URL) (*apiResponse, error) { +func (b *Burrow) getResponse(u *url.URL) (*apiResponse, error) { req, err := http.NewRequest(http.MethodGet, u.String(), nil) if err != nil { return nil, err @@ -224,7 +218,7 @@ func (b *burrow) getResponse(u *url.URL) (*apiResponse, error) { return ares, dec.Decode(ares) } -func (b *burrow) gatherServer(src *url.URL, acc telegraf.Accumulator) error { +func (b *Burrow) gatherServer(src *url.URL, acc telegraf.Accumulator) error { var wg sync.WaitGroup r, err := b.getResponse(src) @@ -263,7 +257,7 @@ func (b *burrow) gatherServer(src *url.URL, acc telegraf.Accumulator) error { return nil } -func (b *burrow) gatherTopics(guard chan struct{}, src *url.URL, cluster string, acc telegraf.Accumulator) { +func (b *Burrow) gatherTopics(guard chan struct{}, src *url.URL, cluster string, acc telegraf.Accumulator) { var wg sync.WaitGroup r, err := b.getResponse(src) @@ -302,7 +296,7 @@ func (b *burrow) gatherTopics(guard chan struct{}, src *url.URL, cluster string, wg.Wait() } -func (b *burrow) genTopicMetrics(r *apiResponse, cluster, topic string, acc telegraf.Accumulator) { +func (b *Burrow) genTopicMetrics(r *apiResponse, cluster, topic string, acc telegraf.Accumulator) { for i, offset := range r.Offsets { tags := map[string]string{ "cluster": cluster, @@ -320,7 +314,7 @@ func (b *burrow) genTopicMetrics(r *apiResponse, cluster, topic string, acc tele } } -func (b *burrow) gatherGroups(guard chan struct{}, src *url.URL, cluster string, acc telegraf.Accumulator) { +func (b *Burrow) gatherGroups(guard chan struct{}, src *url.URL, cluster string, acc telegraf.Accumulator) { var wg sync.WaitGroup r, err := b.getResponse(src) @@ -360,7 +354,7 @@ func (b *burrow) gatherGroups(guard chan struct{}, src *url.URL, cluster string, wg.Wait() } -func (b *burrow) genGroupStatusMetrics(r *apiResponse, cluster, group string, acc telegraf.Accumulator) { +func (b *Burrow) genGroupStatusMetrics(r *apiResponse, cluster, group string, acc telegraf.Accumulator) { partitionCount := r.Status.PartitionCount if partitionCount == 0 { partitionCount = len(r.Status.Partitions) @@ -399,7 +393,7 @@ func (b *burrow) genGroupStatusMetrics(r *apiResponse, cluster, group string, ac ) } -func (b *burrow) genGroupLagMetrics(r *apiResponse, cluster, group string, acc telegraf.Accumulator) { +func (b *Burrow) genGroupLagMetrics(r *apiResponse, cluster, group string, acc telegraf.Accumulator) { for _, partition := range r.Status.Partitions { if !b.filterTopics.Match(partition.Topic) { continue @@ -455,3 +449,9 @@ func mapStatusToCode(src string) int { return 0 } } + +func init() { + inputs.Add("burrow", func() telegraf.Input { + return &Burrow{} + }) +} diff --git a/plugins/inputs/burrow/burrow_test.go b/plugins/inputs/burrow/burrow_test.go index 358af7447a465..aefa78202518c 100644 --- a/plugins/inputs/burrow/burrow_test.go +++ b/plugins/inputs/burrow/burrow_test.go @@ -73,7 +73,7 @@ func TestBurrowTopic(t *testing.T) { s := getHTTPServer() defer s.Close() - plugin := &burrow{Servers: []string{s.URL}} + plugin := &Burrow{Servers: []string{s.URL}} acc := &testutil.Accumulator{} require.NoError(t, plugin.Gather(acc)) @@ -102,7 +102,7 @@ func TestBurrowPartition(t *testing.T) { s := getHTTPServer() defer s.Close() - plugin := &burrow{ + plugin := &Burrow{ Servers: []string{s.URL}, } acc := &testutil.Accumulator{} @@ -150,7 +150,7 @@ func TestBurrowGroup(t *testing.T) { s := getHTTPServer() defer s.Close() - plugin := &burrow{ + plugin := &Burrow{ Servers: []string{s.URL}, } acc := &testutil.Accumulator{} @@ -188,7 +188,7 @@ func TestMultipleServers(t *testing.T) { s2 := getHTTPServer() defer s2.Close() - plugin := &burrow{ + plugin := &Burrow{ Servers: []string{s1.URL, s2.URL}, } acc := &testutil.Accumulator{} @@ -203,7 +203,7 @@ func TestMultipleRuns(t *testing.T) { s := getHTTPServer() defer s.Close() - plugin := &burrow{ + plugin := &Burrow{ Servers: []string{s.URL}, } for i := 0; i < 4; i++ { @@ -220,7 +220,7 @@ func TestBasicAuthConfig(t *testing.T) { s := getHTTPServerBasicAuth() defer s.Close() - plugin := &burrow{ + plugin := &Burrow{ Servers: []string{s.URL}, Username: "test", Password: "test", @@ -238,7 +238,7 @@ func TestFilterClusters(t *testing.T) { s := getHTTPServer() defer s.Close() - plugin := &burrow{ + plugin := &Burrow{ Servers: []string{s.URL}, ClustersInclude: []string{"wrongname*"}, // clustername1 -> no match } @@ -256,7 +256,7 @@ func TestFilterGroups(t *testing.T) { s := getHTTPServer() defer s.Close() - plugin := &burrow{ + plugin := &Burrow{ Servers: []string{s.URL}, GroupsInclude: []string{"group?"}, // group1 -> match TopicsExclude: []string{"*"}, // exclude all @@ -274,7 +274,7 @@ func TestFilterTopics(t *testing.T) { s := getHTTPServer() defer s.Close() - plugin := &burrow{ + plugin := &Burrow{ Servers: []string{s.URL}, TopicsInclude: []string{"topic?"}, // topicA -> match GroupsExclude: []string{"*"}, // exclude all diff --git a/plugins/inputs/chrony/chrony_test.go b/plugins/inputs/chrony/chrony_test.go index e016c5cafe0f8..2e48312ab9e16 100644 --- a/plugins/inputs/chrony/chrony_test.go +++ b/plugins/inputs/chrony/chrony_test.go @@ -762,7 +762,7 @@ func (s *Server) serve(t *testing.T) { var header fbchrony.RequestHead data := bytes.NewBuffer(buf) if err := binary.Read(data, binary.BigEndian, &header); err != nil { - t.Logf("mock server: reading request header failed: %v", err) + t.Errorf("mock server: reading request header failed: %v", err) return } seqno := header.Sequence + 1 @@ -772,58 +772,79 @@ func (s *Server) serve(t *testing.T) { case 14: // sources _, err := s.conn.WriteTo(s.encodeSourcesReply(seqno), addr) if err != nil { - t.Logf("mock server [sources]: writing reply failed: %v", err) + t.Errorf("mock server [sources]: writing reply failed: %v", err) } else { t.Log("mock server [sources]: successfully wrote reply") } case 15: // source data var idx int32 - require.NoError(t, binary.Read(data, binary.BigEndian, &idx)) + if err = binary.Read(data, binary.BigEndian, &idx); err != nil { + t.Error(err) + return + } _, err = s.conn.WriteTo(s.encodeSourceDataReply(seqno, idx), addr) if err != nil { - t.Logf("mock server [source data]: writing reply failed: %v", err) + t.Errorf("mock server [source data]: writing reply failed: %v", err) } else { t.Log("mock server [source data]: successfully wrote reply") } case 33: // tracking _, err := s.conn.WriteTo(s.encodeTrackingReply(seqno), addr) if err != nil { - t.Logf("mock server [tracking]: writing reply failed: %v", err) + t.Errorf("mock server [tracking]: writing reply failed: %v", err) } else { t.Log("mock server [tracking]: successfully wrote reply") } case 34: // source stats var idx int32 - require.NoError(t, binary.Read(data, binary.BigEndian, &idx)) + if err = binary.Read(data, binary.BigEndian, &idx); err != nil { + t.Error(err) + return + } _, err = s.conn.WriteTo(s.encodeSourceStatsReply(seqno, idx), addr) if err != nil { - t.Logf("mock server [source stats]: writing reply failed: %v", err) + t.Errorf("mock server [source stats]: writing reply failed: %v", err) } else { t.Log("mock server [source stats]: successfully wrote reply") } case 44: // activity - _, err := s.conn.WriteTo(s.encodeActivityReply(seqno, t), addr) + payload, err := s.encodeActivityReply(seqno) if err != nil { - t.Logf("mock server [activity]: writing reply failed: %v", err) + t.Error(err) + return + } + + _, err = s.conn.WriteTo(payload, addr) + if err != nil { + t.Errorf("mock server [activity]: writing reply failed: %v", err) } else { t.Log("mock server [activity]: successfully wrote reply") } case 54: // server stats - _, err := s.conn.WriteTo(s.encodeServerStatsReply(seqno, t), addr) + payload, err := s.encodeServerStatsReply(seqno) + if err != nil { + t.Error(err) + return + } + + _, err = s.conn.WriteTo(payload, addr) if err != nil { - t.Logf("mock server [serverstats]: writing reply failed: %v", err) + t.Errorf("mock server [serverstats]: writing reply failed: %v", err) } else { t.Log("mock server [serverstats]: successfully wrote reply") } case 65: // source name buf := make([]byte, 20) _, err := data.Read(buf) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } ip := decodeIP(buf) t.Logf("mock server [source name]: resolving %v", ip) _, err = s.conn.WriteTo(s.encodeSourceNameReply(seqno, ip), addr) if err != nil { - t.Logf("mock server [source name]: writing reply failed: %v", err) + t.Errorf("mock server [source name]: writing reply failed: %v", err) } else { t.Log("mock server [source name]: successfully wrote reply") } @@ -833,15 +854,17 @@ func (s *Server) serve(t *testing.T) { } } -func (s *Server) encodeActivityReply(sequence uint32, t *testing.T) []byte { +func (s *Server) encodeActivityReply(sequence uint32) ([]byte, error) { // Encode the header buf := encodeHeader(44, 12, 0, sequence) // activity request // Encode data b := bytes.NewBuffer(buf) - require.NoError(t, binary.Write(b, binary.BigEndian, s.ActivityInfo)) + if err := binary.Write(b, binary.BigEndian, s.ActivityInfo); err != nil { + return nil, err + } - return b.Bytes() + return b.Bytes(), nil } func (s *Server) encodeTrackingReply(sequence uint32) []byte { @@ -873,8 +896,10 @@ func (s *Server) encodeTrackingReply(sequence uint32) []byte { return buf } -func (s *Server) encodeServerStatsReply(sequence uint32, t *testing.T) []byte { +func (s *Server) encodeServerStatsReply(sequence uint32) ([]byte, error) { var b *bytes.Buffer + var err error + switch info := s.ServerStatInfo.(type) { case *fbchrony.ServerStats: // Encode the header @@ -882,24 +907,27 @@ func (s *Server) encodeServerStatsReply(sequence uint32, t *testing.T) []byte { // Encode data b = bytes.NewBuffer(buf) - require.NoError(t, binary.Write(b, binary.BigEndian, info)) + err = binary.Write(b, binary.BigEndian, info) case *fbchrony.ServerStats2: // Encode the header buf := encodeHeader(54, 22, 0, sequence) // activity request // Encode data b = bytes.NewBuffer(buf) - require.NoError(t, binary.Write(b, binary.BigEndian, info)) + err = binary.Write(b, binary.BigEndian, info) case *fbchrony.ServerStats3: // Encode the header buf := encodeHeader(54, 24, 0, sequence) // activity request // Encode data b = bytes.NewBuffer(buf) - require.NoError(t, binary.Write(b, binary.BigEndian, info)) + err = binary.Write(b, binary.BigEndian, info) } - return b.Bytes() + if err != nil { + return nil, err + } + return b.Bytes(), nil } func (s *Server) encodeSourcesReply(sequence uint32) []byte { diff --git a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go index b37e3287b5c4f..89e3ca76d6b5a 100644 --- a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go +++ b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go @@ -304,7 +304,7 @@ func (c *CiscoTelemetryMDT) handleTCPClient(conn net.Conn) error { if err != nil { return err } - return errors.New("TCP dialout premature EOF") + return errors.New("premature EOF during TCP dialout") } c.handleTelemetry(payload.Bytes()) @@ -324,13 +324,13 @@ func (c *CiscoTelemetryMDT) MdtDialout(stream mdtdialout.GRPCMdtDialout_MdtDialo packet, err := stream.Recv() if err != nil { if !errors.Is(err, io.EOF) { - c.acc.AddError(fmt.Errorf("GRPC dialout receive error: %w", err)) + c.acc.AddError(fmt.Errorf("receive error during GRPC dialout: %w", err)) } break } if len(packet.Data) == 0 && len(packet.Errors) != 0 { - c.acc.AddError(fmt.Errorf("GRPC dialout error: %s", packet.Errors)) + c.acc.AddError(fmt.Errorf("error during GRPC dialout: %s", packet.Errors)) break } @@ -763,7 +763,7 @@ func (c *CiscoTelemetryMDT) parseContentField( if len(rn) > 0 { tags[prefix] = rn } else if !dn { // Check for distinguished name being present - c.acc.AddError(errors.New("NX-OS decoding failed: missing dn field")) + c.acc.AddError(errors.New("failed while decoding NX-OS: missing 'dn' field")) return } diff --git a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go index 68d51d2aecece..d9102c1522f3c 100644 --- a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go +++ b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go @@ -1201,7 +1201,7 @@ func TestGRPCDialoutError(t *testing.T) { require.True(t, err == nil || errors.Is(err, io.EOF)) c.Stop() - require.Equal(t, []error{errors.New("GRPC dialout error: foobar")}, acc.Errors) + require.Equal(t, []error{errors.New("error during GRPC dialout: foobar")}, acc.Errors) } func TestGRPCDialoutMultiple(t *testing.T) { @@ -1262,7 +1262,7 @@ func TestGRPCDialoutMultiple(t *testing.T) { c.Stop() require.NoError(t, conn.Close()) - require.Equal(t, []error{errors.New("GRPC dialout error: testclose"), errors.New("GRPC dialout error: testclose")}, acc.Errors) + require.Equal(t, []error{errors.New("error during GRPC dialout: testclose"), errors.New("error during GRPC dialout: testclose")}, acc.Errors) tags := map[string]string{ "path": "type:model/some/path", diff --git a/plugins/inputs/dovecot/dovecot_test.go b/plugins/inputs/dovecot/dovecot_test.go index 9adf84ae1520e..19d98f65fa609 100644 --- a/plugins/inputs/dovecot/dovecot_test.go +++ b/plugins/inputs/dovecot/dovecot_test.go @@ -59,25 +59,38 @@ func TestDovecotIntegration(t *testing.T) { defer close(waitCh) la, err := net.ResolveUnixAddr("unix", addr) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } l, err := net.ListenUnix("unix", la) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } defer l.Close() defer os.Remove(addr) waitCh <- 0 conn, err := l.Accept() - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } defer conn.Close() readertp := textproto.NewReader(bufio.NewReader(conn)) - _, err = readertp.ReadLine() - require.NoError(t, err) + if _, err = readertp.ReadLine(); err != nil { + t.Error(err) + return + } buf := bytes.NewBufferString(sampleGlobal) - _, err = io.Copy(conn, buf) - require.NoError(t, err) + if _, err = io.Copy(conn, buf); err != nil { + t.Error(err) + return + } }() // Wait for server to start diff --git a/plugins/inputs/dpdk/dpdk_test.go b/plugins/inputs/dpdk/dpdk_test.go index 40d1d93f45289..60d65bd7d944d 100644 --- a/plugins/inputs/dpdk/dpdk_test.go +++ b/plugins/inputs/dpdk/dpdk_test.go @@ -907,13 +907,21 @@ func createMultipleSocketsForTest(t *testing.T, numSockets int, dirPath string) func simulateSocketResponse(socket net.Listener, t *testing.T) { conn, err := socket.Accept() - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } initMessage, err := json.Marshal(initMessage{MaxOutputLen: 1}) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } - _, err = conn.Write(initMessage) - require.NoError(t, err) + if _, err = conn.Write(initMessage); err != nil { + t.Error(err) + return + } } func prepareGlob(path string) (*globpath.GlobPath, error) { diff --git a/plugins/inputs/execd/shim/shim_posix_test.go b/plugins/inputs/execd/shim/shim_posix_test.go index 310d50dc47782..0b25f1240ba8d 100644 --- a/plugins/inputs/execd/shim/shim_posix_test.go +++ b/plugins/inputs/execd/shim/shim_posix_test.go @@ -37,7 +37,11 @@ func TestShimUSR1SignalingWorks(t *testing.T) { return // test is done default: // test isn't done, keep going. - require.NoError(t, process.Signal(syscall.SIGUSR1)) + if err := process.Signal(syscall.SIGUSR1); err != nil { + t.Error(err) + metricProcessed <- false + return + } time.Sleep(200 * time.Millisecond) } } diff --git a/plugins/inputs/execd/shim/shim_test.go b/plugins/inputs/execd/shim/shim_test.go index 33aa87f6ec4ea..63e073e5498fc 100644 --- a/plugins/inputs/execd/shim/shim_test.go +++ b/plugins/inputs/execd/shim/shim_test.go @@ -53,9 +53,9 @@ func TestShimStdinSignalingWorks(t *testing.T) { <-exited } -func runInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdout, stderr io.Writer) (metricProcessed, exited chan bool) { - metricProcessed = make(chan bool) - exited = make(chan bool) +func runInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdout, stderr io.Writer) (chan bool, chan bool) { + metricProcessed := make(chan bool) + exited := make(chan bool) inp := &testInput{ metricProcessed: metricProcessed, } @@ -73,8 +73,9 @@ func runInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdou require.NoError(t, shim.AddInput(inp)) go func() { - err := shim.Run(interval) - require.NoError(t, err) + if err := shim.Run(interval); err != nil { + t.Error(err) + } exited <- true }() return metricProcessed, exited diff --git a/plugins/inputs/gnmi/gnmi_test.go b/plugins/inputs/gnmi/gnmi_test.go index 49b3d38999b64..3d32d9f679b0a 100644 --- a/plugins/inputs/gnmi/gnmi_test.go +++ b/plugins/inputs/gnmi/gnmi_test.go @@ -95,8 +95,9 @@ func TestWaitError(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() acc.WaitError(1) @@ -154,8 +155,9 @@ func TestUsernamePassword(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() acc.WaitError(1) @@ -1011,8 +1013,9 @@ func TestNotification(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() acc.Wait(len(tt.expected)) @@ -1063,8 +1066,9 @@ func TestRedial(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() var acc testutil.Accumulator @@ -1095,8 +1099,9 @@ func TestRedial(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() acc.Wait(4) @@ -1199,8 +1204,9 @@ func TestCases(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() var acc testutil.Accumulator diff --git a/plugins/inputs/google_cloud_storage/google_cloud_storage.go b/plugins/inputs/google_cloud_storage/google_cloud_storage.go index 2090715c095c7..c97ad20616d2d 100644 --- a/plugins/inputs/google_cloud_storage/google_cloud_storage.go +++ b/plugins/inputs/google_cloud_storage/google_cloud_storage.go @@ -97,7 +97,7 @@ func (gcs *GCS) Gather(acc telegraf.Accumulator) error { if !gcs.shouldIgnore(name) { if err := gcs.processMeasurementsInObject(name, bucket, acc); err != nil { gcs.Log.Errorf("Could not process object %q in bucket %q: %v", name, bucketName, err) - acc.AddError(fmt.Errorf("COULD NOT PROCESS OBJECT %q IN BUCKET %q: %w", name, bucketName, err)) + acc.AddError(fmt.Errorf("could not process object %q in bucket %q: %w", name, bucketName, err)) } } @@ -238,7 +238,7 @@ func (gcs *GCS) setUpDefaultClient() error { func (gcs *GCS) setOffset() error { if gcs.client == nil { - return errors.New("CANNOT SET OFFSET IF CLIENT IS NOT SET") + return errors.New("cannot set offset if client is not set") } if gcs.OffsetKey != "" { diff --git a/plugins/inputs/hddtemp/go-hddtemp/hddtemp_test.go b/plugins/inputs/hddtemp/go-hddtemp/hddtemp_test.go index 41d513e4011e3..870a3df453421 100644 --- a/plugins/inputs/hddtemp/go-hddtemp/hddtemp_test.go +++ b/plugins/inputs/hddtemp/go-hddtemp/hddtemp_test.go @@ -80,11 +80,19 @@ func serve(t *testing.T, data []byte) net.Listener { go func(t *testing.T) { conn, err := l.Accept() - require.NoError(t, err) - - _, err = conn.Write(data) - require.NoError(t, err) - require.NoError(t, conn.Close()) + if err != nil { + t.Error(err) + return + } + + if _, err = conn.Write(data); err != nil { + t.Error(err) + return + } + if err = conn.Close(); err != nil { + t.Error(err) + return + } }(t) return l diff --git a/plugins/inputs/influxdb_listener/influxdb_listener.go b/plugins/inputs/influxdb_listener/influxdb_listener.go index 2c54088b34fce..fd4b1d1cae882 100644 --- a/plugins/inputs/influxdb_listener/influxdb_listener.go +++ b/plugins/inputs/influxdb_listener/influxdb_listener.go @@ -9,6 +9,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "net" "net/http" "time" @@ -449,7 +450,7 @@ func (h *InfluxDBListener) handleWriteUpstreamParser(res http.ResponseWriter, re h.acc.AddMetric(m) } - if !errors.Is(err, influx_upstream.ErrEOF) { + if !errors.Is(err, io.EOF) { h.Log.Debugf("Error parsing the request body: %v", err.Error()) if err := badRequest(res, err.Error()); err != nil { h.Log.Debugf("error in bad-request: %v", err) diff --git a/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go b/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go index 612521f97b4bc..44263966918b0 100644 --- a/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go +++ b/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go @@ -38,8 +38,6 @@ const ( defaultWriteTimeout = 10 * time.Second ) -var ErrEOF = errors.New("EOF") - // The BadRequestCode constants keep standard error messages // see: https://v2.docs.influxdata.com/v2.0/api/#operation/PostWrite type BadRequestCode string @@ -166,12 +164,12 @@ func (h *InfluxDBV2Listener) Start(acc telegraf.Accumulator) error { case <-h.ctx.Done(): return case info := <-h.trackingAcc.Delivered(): + h.countLock.Lock() if count, ok := h.trackingMetricCount[info.ID()]; ok { - h.countLock.Lock() h.totalUndeliveredMetrics.Add(-count) delete(h.trackingMetricCount, info.ID()) - h.countLock.Unlock() } + h.countLock.Unlock() } } }() @@ -309,7 +307,7 @@ func (h *InfluxDBV2Listener) handleWrite() http.HandlerFunc { if h.ParserType == "upstream" { parser := influx_upstream.Parser{} err = parser.Init() - if !errors.Is(err, ErrEOF) && err != nil { + if !errors.Is(err, io.EOF) && err != nil { h.Log.Debugf("Error initializing parser: %v", err.Error()) return } @@ -327,7 +325,7 @@ func (h *InfluxDBV2Listener) handleWrite() http.HandlerFunc { } else { parser := influx.Parser{} err = parser.Init() - if !errors.Is(err, ErrEOF) && err != nil { + if !errors.Is(err, io.EOF) && err != nil { h.Log.Debugf("Error initializing parser: %v", err.Error()) return } @@ -341,7 +339,7 @@ func (h *InfluxDBV2Listener) handleWrite() http.HandlerFunc { metrics, err = parser.Parse(bytes) } - if !errors.Is(err, ErrEOF) && err != nil { + if !errors.Is(err, io.EOF) && err != nil { h.Log.Debugf("Error parsing the request body: %v", err.Error()) if err := badRequest(res, Invalid, err.Error()); err != nil { h.Log.Debugf("error in bad-request: %v", err) diff --git a/plugins/inputs/intel_dlb/intel_dlb_test.go b/plugins/inputs/intel_dlb/intel_dlb_test.go index 0b31bab3eb12f..a5bef4af72dac 100644 --- a/plugins/inputs/intel_dlb/intel_dlb_test.go +++ b/plugins/inputs/intel_dlb/intel_dlb_test.go @@ -935,7 +935,10 @@ func simulateResponse(mockConn *mocks.Conn, response string, readErr error) { func simulateSocketResponseForGather(socket net.Listener, t *testing.T) { conn, err := socket.Accept() - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } type initMessage struct { Version string `json:"version"` @@ -947,14 +950,21 @@ func simulateSocketResponseForGather(socket net.Listener, t *testing.T) { Pid: 1, MaxOutputLen: 1024, }) - require.NoError(t, err) - _, err = conn.Write(initMsg) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + + if _, err = conn.Write(initMsg); err != nil { + t.Error(err) + return + } - require.NoError(t, err) eventdevListWithSecondIndex := []string{"/eventdev/port_list", "/eventdev/queue_list"} - _, err = fmt.Fprintf(conn, `{%q: [0, 1]}`, eventdevListWithSecondIndex[0]) - require.NoError(t, err) + if _, err = fmt.Fprintf(conn, `{%q: [0, 1]}`, eventdevListWithSecondIndex[0]); err != nil { + t.Error(err) + return + } } func createSocketForTest(t *testing.T) (string, net.Listener) { diff --git a/plugins/inputs/intel_pmt/xml_parser.go b/plugins/inputs/intel_pmt/xml_parser.go index 159e84e448a03..2d0d071439256 100644 --- a/plugins/inputs/intel_pmt/xml_parser.go +++ b/plugins/inputs/intel_pmt/xml_parser.go @@ -176,11 +176,8 @@ func (p *IntelPMT) readXMLs() error { p.Log.Warnf("Configured sample metric %q has not been found", sm) } } - err := p.verifyNoEmpty() - if err != nil { - return fmt.Errorf("XMLs empty: %w", err) - } - return nil + + return p.verifyNoEmpty() } // getAllXMLData retrieves two XMLs for given GUID. @@ -254,7 +251,7 @@ func computeMask(msb, lsb uint64) uint64 { func parseXML(source string, sr sourceReader, v interface{}) error { if sr == nil { - return errors.New("XML reader failed to initialize") + return errors.New("xml reader has not been initialized") } reader, err := sr.getReadCloser(source) if err != nil { diff --git a/plugins/inputs/iptables/iptables.go b/plugins/inputs/iptables/iptables.go index e352fbe4d90aa..648b3a8b9e4cc 100644 --- a/plugins/inputs/iptables/iptables.go +++ b/plugins/inputs/iptables/iptables.go @@ -82,10 +82,12 @@ func (ipt *Iptables) chainList(table, chain string) (string, error) { const measurement = "iptables" -var errParse = errors.New("Cannot parse iptables list information") -var chainNameRe = regexp.MustCompile(`^Chain\s+(\S+)`) -var fieldsHeaderRe = regexp.MustCompile(`^\s*pkts\s+bytes\s+target`) -var valuesRe = regexp.MustCompile(`^\s*(\d+)\s+(\d+)\s+(\w+).*?/\*\s*(.+?)\s*\*/\s*`) +var ( + errParse = errors.New("cannot parse iptables list information") + chainNameRe = regexp.MustCompile(`^Chain\s+(\S+)`) + fieldsHeaderRe = regexp.MustCompile(`^\s*pkts\s+bytes\s+target`) + valuesRe = regexp.MustCompile(`^\s*(\d+)\s+(\d+)\s+(\w+).*?/\*\s*(.+?)\s*\*/\s*`) +) func (ipt *Iptables) parseAndGather(data string, acc telegraf.Accumulator) error { lines := strings.Split(data, "\n") diff --git a/plugins/inputs/kafka_consumer/kafka_consumer.go b/plugins/inputs/kafka_consumer/kafka_consumer.go index 9f11c6143bb4d..9d262b7346931 100644 --- a/plugins/inputs/kafka_consumer/kafka_consumer.go +++ b/plugins/inputs/kafka_consumer/kafka_consumer.go @@ -132,7 +132,7 @@ func (k *KafkaConsumer) Init() error { } if err := k.SetConfig(cfg, k.Log); err != nil { - return fmt.Errorf("SetConfig: %w", err) + return fmt.Errorf("setting config failed: %w", err) } switch strings.ToLower(k.Offset) { diff --git a/plugins/inputs/kafka_consumer/kafka_consumer_test.go b/plugins/inputs/kafka_consumer/kafka_consumer_test.go index bbfc6ff38c8ac..76c9c5104f434 100644 --- a/plugins/inputs/kafka_consumer/kafka_consumer_test.go +++ b/plugins/inputs/kafka_consumer/kafka_consumer_test.go @@ -355,8 +355,14 @@ func TestConsumerGroupHandlerConsumeClaim(t *testing.T) { go func() { err := cg.ConsumeClaim(session, claim) - require.Error(t, err) - require.EqualValues(t, "context canceled", err.Error()) + if err == nil { + t.Error("An error was expected.") + return + } + if err.Error() != "context canceled" { + t.Errorf("Expected 'context canceled' error, got: %v", err) + return + } }() acc.Wait(1) diff --git a/plugins/inputs/linux_cpu/linux_cpu.go b/plugins/inputs/linux_cpu/linux_cpu.go index f35b31e6e9160..df2870545d867 100644 --- a/plugins/inputs/linux_cpu/linux_cpu.go +++ b/plugins/inputs/linux_cpu/linux_cpu.go @@ -182,11 +182,9 @@ func init() { func validatePath(propPath string) error { f, err := os.Open(propPath) - if os.IsNotExist(err) { - return fmt.Errorf("CPU property does not exist: [%s]", propPath) + return fmt.Errorf("file with CPU property does not exist: %q", propPath) } - if err != nil { return fmt.Errorf("cannot get system information for CPU property %q: %w", propPath, err) } diff --git a/plugins/inputs/mock/README.md b/plugins/inputs/mock/README.md index f7bad4f45c52e..cc420cdcabf85 100644 --- a/plugins/inputs/mock/README.md +++ b/plugins/inputs/mock/README.md @@ -40,6 +40,7 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. # name = "wave" # amplitude = 1.0 # period = 0.5 + # phase = 20.0 # base_line = 0.0 # [[inputs.mock.step]] # name = "plus_one" diff --git a/plugins/inputs/mock/mock.go b/plugins/inputs/mock/mock.go index 0c4f9ec6af125..94e94175272ad 100644 --- a/plugins/inputs/mock/mock.go +++ b/plugins/inputs/mock/mock.go @@ -43,6 +43,7 @@ type sineWave struct { Name string `toml:"name"` Amplitude float64 `toml:"amplitude"` Period float64 `toml:"period"` + Phase float64 `toml:"phase"` BaseLine float64 `toml:"base_line"` } @@ -118,7 +119,7 @@ func (m *Mock) generateRandomFloat64(fields map[string]interface{}) { // Create sine waves func (m *Mock) generateSineWave(fields map[string]interface{}) { for _, field := range m.SineWave { - fields[field.Name] = math.Sin(float64(m.counter)*field.Period*math.Pi)*field.Amplitude + field.BaseLine + fields[field.Name] = math.Sin((float64(m.counter)+field.Phase)*field.Period*math.Pi)*field.Amplitude + field.BaseLine } } diff --git a/plugins/inputs/mock/sample.conf b/plugins/inputs/mock/sample.conf index da06a5b6efcd4..b08cbc507452f 100644 --- a/plugins/inputs/mock/sample.conf +++ b/plugins/inputs/mock/sample.conf @@ -19,6 +19,7 @@ # name = "wave" # amplitude = 1.0 # period = 0.5 + # phase = 20.0 # base_line = 0.0 # [[inputs.mock.step]] # name = "plus_one" diff --git a/plugins/inputs/net_response/net_response_test.go b/plugins/inputs/net_response/net_response_test.go index b70ebd4f3bfe4..bfb6c2ce803c5 100644 --- a/plugins/inputs/net_response/net_response_test.go +++ b/plugins/inputs/net_response/net_response_test.go @@ -267,32 +267,75 @@ func TestUDPOK1(t *testing.T) { func UDPServer(t *testing.T, wg *sync.WaitGroup) { defer wg.Done() udpAddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:2004") - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + conn, err := net.ListenUDP("udp", udpAddr) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + wg.Done() buf := make([]byte, 1024) _, remoteaddr, err := conn.ReadFromUDP(buf) - require.NoError(t, err) - _, err = conn.WriteToUDP(buf, remoteaddr) - require.NoError(t, err) - require.NoError(t, conn.Close()) + if err != nil { + t.Error(err) + return + } + + if _, err = conn.WriteToUDP(buf, remoteaddr); err != nil { + t.Error(err) + return + } + + if err = conn.Close(); err != nil { + t.Error(err) + return + } } func TCPServer(t *testing.T, wg *sync.WaitGroup) { defer wg.Done() tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:2004") - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + tcpServer, err := net.ListenTCP("tcp", tcpAddr) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + wg.Done() conn, err := tcpServer.AcceptTCP() - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + buf := make([]byte, 1024) - _, err = conn.Read(buf) - require.NoError(t, err) - _, err = conn.Write(buf) - require.NoError(t, err) - require.NoError(t, conn.CloseWrite()) - require.NoError(t, tcpServer.Close()) + if _, err = conn.Read(buf); err != nil { + t.Error(err) + return + } + + if _, err = conn.Write(buf); err != nil { + t.Error(err) + return + } + + if err = conn.CloseWrite(); err != nil { + t.Error(err) + return + } + + if err = tcpServer.Close(); err != nil { + t.Error(err) + return + } } diff --git a/plugins/inputs/nginx_plus_api/nginx_plus_api.go b/plugins/inputs/nginx_plus_api/nginx_plus_api.go index 2586722fba1f0..acf3be64a57f4 100644 --- a/plugins/inputs/nginx_plus_api/nginx_plus_api.go +++ b/plugins/inputs/nginx_plus_api/nginx_plus_api.go @@ -74,7 +74,7 @@ func (n *NginxPlusAPI) Gather(acc telegraf.Accumulator) error { for _, u := range n.Urls { addr, err := url.Parse(u) if err != nil { - acc.AddError(fmt.Errorf("Unable to parse address %q: %w", u, err)) + acc.AddError(fmt.Errorf("unable to parse address %q: %w", u, err)) continue } diff --git a/plugins/inputs/opcua/read_client.go b/plugins/inputs/opcua/read_client.go index b765ff72d1c13..9aaf0570c1420 100644 --- a/plugins/inputs/opcua/read_client.go +++ b/plugins/inputs/opcua/read_client.go @@ -139,7 +139,7 @@ func (o *ReadClient) read() error { resp, err := o.Client.Read(o.ctx, req) if err != nil { o.ReadError.Incr(1) - return fmt.Errorf("RegisterNodes Read failed: %w", err) + return fmt.Errorf("reading registered nodes failed: %w", err) } o.ReadSuccess.Incr(1) for i, d := range resp.Results { diff --git a/plugins/inputs/ping/ping_windows_test.go b/plugins/inputs/ping/ping_windows_test.go index 9c11f2c3cff8b..4517bf8f33736 100644 --- a/plugins/inputs/ping/ping_windows_test.go +++ b/plugins/inputs/ping/ping_windows_test.go @@ -104,7 +104,7 @@ Statystyka badania ping dla 195.187.242.157: ` func mockErrorHostPinger(string, float64, ...string) (string, error) { - return errorPingOutput, errors.New("No packets received") + return errorPingOutput, errors.New("no packets received") } // Test that Gather works on a ping with no transmitted packets, even though the @@ -228,7 +228,7 @@ Options: ` func mockFatalHostPinger(string, float64, ...string) (string, error) { - return fatalPingOutput, errors.New("So very bad") + return fatalPingOutput, errors.New("so very bad") } // Test that a fatal ping command does not gather any statistics. @@ -273,7 +273,7 @@ Ping statistics for 8.8.8.8: ` func mockUnreachableHostPinger(string, float64, ...string) (string, error) { - return UnreachablePingOutput, errors.New("So very bad") + return UnreachablePingOutput, errors.New("so very bad") } // Reply from 185.28.251.217: TTL expired in transit. @@ -324,7 +324,7 @@ Ping statistics for 8.8.8.8: ` func mockTTLExpiredPinger(string, float64, ...string) (string, error) { - return TTLExpiredPingOutput, errors.New("So very bad") + return TTLExpiredPingOutput, errors.New("so very bad") } // in case 'Destination net unreachable' ping app return receive packet which is not what we need diff --git a/plugins/inputs/postgresql/postgresql_test.go b/plugins/inputs/postgresql/postgresql_test.go index 24df5870426e1..124ddbe149f28 100644 --- a/plugins/inputs/postgresql/postgresql_test.go +++ b/plugins/inputs/postgresql/postgresql_test.go @@ -79,15 +79,14 @@ func TestPostgresqlGeneratesMetricsIntegration(t *testing.T) { "temp_bytes", "deadlocks", "buffers_alloc", - "buffers_backend", - "buffers_backend_fsync", - "buffers_checkpoint", "buffers_clean", - "checkpoints_req", - "checkpoints_timed", "maxwritten_clean", "datid", "numbackends", + "sessions", + "sessions_killed", + "sessions_fatal", + "sessions_abandoned", } int32Metrics := []string{} @@ -95,8 +94,9 @@ func TestPostgresqlGeneratesMetricsIntegration(t *testing.T) { floatMetrics := []string{ "blk_read_time", "blk_write_time", - "checkpoint_write_time", - "checkpoint_sync_time", + "active_time", + "idle_in_transaction_time", + "session_time", } stringMetrics := []string{ @@ -106,22 +106,22 @@ func TestPostgresqlGeneratesMetricsIntegration(t *testing.T) { metricsCounted := 0 for _, metric := range intMetrics { - require.True(t, acc.HasInt64Field("postgresql", metric)) + require.True(t, acc.HasInt64Field("postgresql", metric), "%q not found in int metrics", metric) metricsCounted++ } for _, metric := range int32Metrics { - require.True(t, acc.HasInt32Field("postgresql", metric)) + require.True(t, acc.HasInt32Field("postgresql", metric), "%q not found in int32 metrics", metric) metricsCounted++ } for _, metric := range floatMetrics { - require.True(t, acc.HasFloatField("postgresql", metric)) + require.True(t, acc.HasFloatField("postgresql", metric), "%q not found in float metrics", metric) metricsCounted++ } for _, metric := range stringMetrics { - require.True(t, acc.HasStringField("postgresql", metric)) + require.True(t, acc.HasStringField("postgresql", metric), "%q not found in string metrics", metric) metricsCounted++ } diff --git a/plugins/inputs/radius/radius_test.go b/plugins/inputs/radius/radius_test.go index 0eb02ea267a63..d9d3418868067 100644 --- a/plugins/inputs/radius/radius_test.go +++ b/plugins/inputs/radius/radius_test.go @@ -50,7 +50,8 @@ func TestRadiusLocal(t *testing.T) { go func() { if err := server.Serve(conn); err != nil { if !errors.Is(err, radius.ErrServerShutdown) { - require.NoError(t, err, "local radius server failed") + t.Errorf("Local radius server failed: %v", err) + return } } }() @@ -118,7 +119,8 @@ func TestRadiusNASIP(t *testing.T) { go func() { if err := server.Serve(conn); err != nil { if !errors.Is(err, radius.ErrServerShutdown) { - require.NoError(t, err, "local radius server failed") + t.Errorf("Local radius server failed: %v", err) + return } } }() diff --git a/plugins/inputs/sflow/packetdecoder.go b/plugins/inputs/sflow/packetdecoder.go index b01dee2892241..d5cc0b493fa17 100644 --- a/plugins/inputs/sflow/packetdecoder.go +++ b/plugins/inputs/sflow/packetdecoder.go @@ -60,7 +60,7 @@ func (d *packetDecoder) DecodeOnePacket(r io.Reader) (*v5Format, error) { return nil, err } if p.Version != 5 { - return nil, fmt.Errorf("Version %d not supported, only version 5", p.Version) + return nil, fmt.Errorf("version %d not supported, only version 5", p.Version) } var addressIPType AddressType if err := read(r, &addressIPType, "address ip type"); err != nil { @@ -74,7 +74,7 @@ func (d *packetDecoder) DecodeOnePacket(r io.Reader) (*v5Format, error) { case AddressTypeIPV6: p.AgentAddress.IP = make([]byte, 16) default: - return nil, fmt.Errorf("Unknown address IP type %d", addressIPType) + return nil, fmt.Errorf("unknown address IP type %d", addressIPType) } if err := read(r, &p.AgentAddress.IP, "Agent Address IP"); err != nil { return nil, err @@ -389,7 +389,7 @@ func (d *packetDecoder) decodeIPv6Header(r io.Reader) (h ipV6Header, err error) } version := fourByteBlock >> 28 if version != 0x6 { - return h, fmt.Errorf("Unexpected IPv6 header version 0x%x", version) + return h, fmt.Errorf("unexpected IPv6 header version 0x%x", version) } h.DSCP = uint8((fourByteBlock & 0xFC00000) >> 22) h.ECN = uint8((fourByteBlock & 0x300000) >> 20) diff --git a/plugins/inputs/smartctl/smartctl.go b/plugins/inputs/smartctl/smartctl.go index 7c82ac78d544b..b4f34ca2f58f8 100644 --- a/plugins/inputs/smartctl/smartctl.go +++ b/plugins/inputs/smartctl/smartctl.go @@ -70,12 +70,12 @@ func (s *Smartctl) Init() error { func (s *Smartctl) Gather(acc telegraf.Accumulator) error { devices, err := s.scan() if err != nil { - return fmt.Errorf("Error scanning system: %w", err) + return fmt.Errorf("error while scanning system: %w", err) } for _, device := range devices { if err := s.scanDevice(acc, device.Name, device.Type); err != nil { - return fmt.Errorf("Error getting device %s: %w", device, err) + return fmt.Errorf("error while getting device %s: %w", device, err) } } diff --git a/plugins/inputs/statsd/statsd_test.go b/plugins/inputs/statsd/statsd_test.go index f76a8ded1fb9c..9ba0ccc96c4b3 100644 --- a/plugins/inputs/statsd/statsd_test.go +++ b/plugins/inputs/statsd/statsd_test.go @@ -202,8 +202,10 @@ func BenchmarkUDPThreads4(b *testing.B) { go func() { defer wg.Done() for i := 0; i < 1000; i++ { - _, err := conn.Write([]byte(testMsg)) - require.NoError(b, err) + if _, err := conn.Write([]byte(testMsg)); err != nil { + b.Error(err) + return + } } }() } @@ -239,8 +241,10 @@ func BenchmarkUDPThreads8(b *testing.B) { go func() { defer wg.Done() for i := 0; i < 1000; i++ { - _, err := conn.Write([]byte(testMsg)) - require.NoError(b, err) + if _, err := conn.Write([]byte(testMsg)); err != nil { + b.Error(err) + return + } } }() } @@ -276,8 +280,10 @@ func BenchmarkUDPThreads16(b *testing.B) { go func() { defer wg.Done() for i := 0; i < 1000; i++ { - _, err := conn.Write([]byte(testMsg)) - require.NoError(b, err) + if _, err := conn.Write([]byte(testMsg)); err != nil { + b.Error(err) + return + } } }() } diff --git a/plugins/inputs/supervisor/supervisor.go b/plugins/inputs/supervisor/supervisor.go index d21dd15df983a..65341832d5a3f 100644 --- a/plugins/inputs/supervisor/supervisor.go +++ b/plugins/inputs/supervisor/supervisor.go @@ -144,7 +144,7 @@ func (s *Supervisor) Init() error { // Initializing XML-RPC client s.rpcClient, err = xmlrpc.NewClient(s.Server, nil) if err != nil { - return fmt.Errorf("XML-RPC client initialization failed: %w", err) + return fmt.Errorf("failed to initialize XML-RPC client: %w", err) } // Setting filter for additional metrics s.fieldFilter, err = filter.NewIncludeExcludeFilter(s.MetricsInc, s.MetricsExc) diff --git a/plugins/inputs/systemd_units/systemd_units_test.go b/plugins/inputs/systemd_units/systemd_units_test.go index a9594cbafe984..7add99775d661 100644 --- a/plugins/inputs/systemd_units/systemd_units_test.go +++ b/plugins/inputs/systemd_units/systemd_units_test.go @@ -969,7 +969,7 @@ func (c *fakeClient) GetUnitTypePropertiesContext(_ context.Context, unit, unitT return nil, nil } if u.utype != unitType { - return nil, fmt.Errorf("Unknown interface 'org.freedesktop.systemd1.%s", unitType) + return nil, fmt.Errorf("unknown interface 'org.freedesktop.systemd1.%s", unitType) } return u.properties, nil } diff --git a/plugins/inputs/teamspeak/teamspeak_test.go b/plugins/inputs/teamspeak/teamspeak_test.go index 4d56f5834282c..4612f3cc80940 100644 --- a/plugins/inputs/teamspeak/teamspeak_test.go +++ b/plugins/inputs/teamspeak/teamspeak_test.go @@ -89,34 +89,51 @@ func TestGather(t *testing.T) { func handleRequest(l net.Listener, t *testing.T) { c, err := l.Accept() - require.NoError(t, err, "Error accepting test connection") - _, err = c.Write([]byte("TS3\n\r" + welcome + "\n\r")) - require.NoError(t, err) + if err != nil { + t.Errorf("Error accepting test connection: %v", err) + return + } + + if _, err = c.Write([]byte("TS3\n\r" + welcome + "\n\r")); err != nil { + t.Error(err) + return + } + for { msg, _, err := bufio.NewReader(c).ReadLine() if err != nil { + t.Error(err) return } - r, exists := cmd[strings.Split(string(msg), " ")[0]] + r, exists := cmd[strings.Split(string(msg), " ")[0]] if exists { switch r { case "": - _, err = c.Write([]byte(ok + "\n\r")) - require.NoError(t, err) + if _, err = c.Write([]byte(ok + "\n\r")); err != nil { + t.Error(err) + return + } case "quit": - _, err = c.Write([]byte(ok + "\n\r")) - require.NoError(t, err) - err = c.Close() - require.NoError(t, err) + if _, err = c.Write([]byte(ok + "\n\r")); err != nil { + t.Error(err) + return + } + if err = c.Close(); err != nil { + t.Error(err) + } return default: - _, err = c.Write([]byte(r + "\n\r" + ok + "\n\r")) - require.NoError(t, err) + if _, err = c.Write([]byte(r + "\n\r" + ok + "\n\r")); err != nil { + t.Error(err) + return + } } } else { - _, err = c.Write([]byte(errorMsg + "\n\r")) - require.NoError(t, err) + if _, err = c.Write([]byte(errorMsg + "\n\r")); err != nil { + t.Error(err) + return + } } } } diff --git a/plugins/inputs/tengine/tengine.go b/plugins/inputs/tengine/tengine.go index f68a219679f43..8ec3b4fa722b6 100644 --- a/plugins/inputs/tengine/tengine.go +++ b/plugins/inputs/tengine/tengine.go @@ -52,7 +52,7 @@ func (n *Tengine) Gather(acc telegraf.Accumulator) error { for _, u := range n.Urls { addr, err := url.Parse(u) if err != nil { - acc.AddError(fmt.Errorf("Unable to parse address %q: %w", u, err)) + acc.AddError(fmt.Errorf("unable to parse address %q: %w", u, err)) continue } diff --git a/plugins/inputs/unbound/unbound.go b/plugins/inputs/unbound/unbound.go index 197fb55d4e6b7..e3b5d8edb6290 100644 --- a/plugins/inputs/unbound/unbound.go +++ b/plugins/inputs/unbound/unbound.go @@ -133,8 +133,7 @@ func (s *Unbound) Gather(acc telegraf.Accumulator) error { fieldValue, err := strconv.ParseFloat(value, 64) if err != nil { - acc.AddError(fmt.Errorf("Expected a numerical value for %s = %v", - stat, value)) + acc.AddError(fmt.Errorf("expected a numerical value for %s = %v", stat, value)) continue } diff --git a/plugins/inputs/x509_cert/x509_cert_test.go b/plugins/inputs/x509_cert/x509_cert_test.go index fbe35dfc94dcb..bb4f72cc14d07 100644 --- a/plugins/inputs/x509_cert/x509_cert_test.go +++ b/plugins/inputs/x509_cert/x509_cert_test.go @@ -89,18 +89,25 @@ func TestGatherRemoteIntegration(t *testing.T) { go func() { sconn, err := ln.Accept() - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + if test.close { sconn.Close() } serverConfig := cfg.Clone() - srv := tls.Server(sconn, serverConfig) if test.noshake { srv.Close() } - require.NoError(t, srv.Handshake()) + + if err = srv.Handshake(); err != nil { + t.Error(err) + return + } }() if test.server == "" { @@ -318,8 +325,9 @@ func TestGatherUDPCertIntegration(t *testing.T) { defer listener.Close() go func() { - _, err := listener.Accept() - require.NoError(t, err) + if _, err := listener.Accept(); err != nil { + t.Error(err) + } }() m := &X509Cert{ diff --git a/plugins/inputs/zipkin/codec/jsonV1/jsonV1.go b/plugins/inputs/zipkin/codec/jsonV1/jsonV1.go index 1fd08138bc0c3..e265540ff5cc7 100644 --- a/plugins/inputs/zipkin/codec/jsonV1/jsonV1.go +++ b/plugins/inputs/zipkin/codec/jsonV1/jsonV1.go @@ -220,7 +220,7 @@ func TraceIDFromString(s string) (string, error) { var hi, lo uint64 var err error if len(s) > 32 { - return "", fmt.Errorf("TraceID cannot be longer than 32 hex characters: %s", s) + return "", fmt.Errorf("length of TraceID cannot be greater than 32 hex characters: %s", s) } else if len(s) > 16 { hiLen := len(s) - 16 if hi, err = strconv.ParseUint(s[0:hiLen], 16, 64); err != nil { @@ -243,7 +243,7 @@ func TraceIDFromString(s string) (string, error) { // IDFromString validates the ID and returns it in hexadecimal format. func IDFromString(s string) (string, error) { if len(s) > 16 { - return "", fmt.Errorf("ID cannot be longer than 16 hex characters: %s", s) + return "", fmt.Errorf("length of ID cannot be greater than 16 hex characters: %s", s) } id, err := strconv.ParseUint(s, 16, 64) if err != nil { diff --git a/plugins/inputs/zipkin/handler.go b/plugins/inputs/zipkin/handler.go index 811018a310a41..50e6a53c4a14e 100644 --- a/plugins/inputs/zipkin/handler.go +++ b/plugins/inputs/zipkin/handler.go @@ -118,7 +118,7 @@ func (s *SpanHandler) Spans(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) } -// ContentDecoer returns a Decoder that is able to produce Traces from bytes. +// ContentDecoder returns a Decoder that is able to produce Traces from bytes. // Failure should yield an HTTP 415 (`http.StatusUnsupportedMediaType`) // If a Content-Type is not set, zipkin assumes application/json func ContentDecoder(r *http.Request) (codec.Decoder, error) { @@ -138,5 +138,5 @@ func ContentDecoder(r *http.Request) (codec.Decoder, error) { return &thrift.Thrift{}, nil } } - return nil, fmt.Errorf("Unknown Content-Type: %s", contentType) + return nil, fmt.Errorf("unknown Content-Type: %s", contentType) } diff --git a/plugins/inputs/zipkin/zipkin_test.go b/plugins/inputs/zipkin/zipkin_test.go index 99334bd2f6d57..9eb5f34ccf59e 100644 --- a/plugins/inputs/zipkin/zipkin_test.go +++ b/plugins/inputs/zipkin/zipkin_test.go @@ -2,7 +2,6 @@ package zipkin import ( "bytes" - "errors" "fmt" "net/http" "os" @@ -646,18 +645,18 @@ func postThriftData(datafile, address, contentType string) error { return fmt.Errorf("could not read from data file %s", datafile) } - req, err := http.NewRequest("POST", fmt.Sprintf("http://%s/api/v1/spans", address), bytes.NewReader(dat)) + endpoint := fmt.Sprintf("http://%s/api/v1/spans", address) + req, err := http.NewRequest("POST", endpoint, bytes.NewReader(dat)) if err != nil { - return errors.New("HTTP request creation failed") + return fmt.Errorf("unable to create new POST request for %q: %w", endpoint, err) } req.Header.Set("Content-Type", contentType) client := &http.Client{} resp, err := client.Do(req) if err != nil { - return fmt.Errorf("HTTP POST request to zipkin endpoint %q failed: %w", address, err) + return fmt.Errorf("error while making HTTP POST request to zipkin endpoint %q: %w", endpoint, err) } - defer resp.Body.Close() return nil diff --git a/plugins/outputs/bigquery/bigquery_test.go b/plugins/outputs/bigquery/bigquery_test.go index 01e449b759e7d..10ac6bc9a1c3a 100644 --- a/plugins/outputs/bigquery/bigquery_test.go +++ b/plugins/outputs/bigquery/bigquery_test.go @@ -11,6 +11,7 @@ import ( "cloud.google.com/go/bigquery" "github.com/stretchr/testify/require" "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" "github.com/influxdata/telegraf/testutil" ) @@ -252,10 +253,11 @@ func (b *BigQuery) setUpTestClientWithJSON(endpointURL string, credentialsJSON [ noAuth := option.WithoutAuthentication() endpoint := option.WithEndpoint(endpointURL) credentials := option.WithCredentialsJSON(credentialsJSON) + skipValidate := internaloption.SkipDialSettingsValidation() ctx := context.Background() - c, err := bigquery.NewClient(ctx, b.Project, credentials, noAuth, endpoint) + c, err := bigquery.NewClient(ctx, b.Project, credentials, noAuth, endpoint, skipValidate) b.client = c return err diff --git a/plugins/outputs/file/file_test.go b/plugins/outputs/file/file_test.go index 66249a21a633f..640b9e76de195 100644 --- a/plugins/outputs/file/file_test.go +++ b/plugins/outputs/file/file_test.go @@ -234,6 +234,11 @@ func TestFileBoth(t *testing.T) { require.NoError(t, err) } +type erroredString struct { + str string + err error +} + func TestFileStdout(t *testing.T) { // keep backup of the real stdout old := os.Stdout @@ -261,13 +266,17 @@ func TestFileStdout(t *testing.T) { err = f.Close() require.NoError(t, err) - outC := make(chan string) + outC := make(chan erroredString) // copy the output in a separate goroutine so printing can't block indefinitely go func() { var buf bytes.Buffer _, err := io.Copy(&buf, r) - require.NoError(t, err) - outC <- buf.String() + if err != nil { + outC <- erroredString{err: err} + return + } + + outC <- erroredString{str: buf.String()} }() // back to normal state @@ -278,7 +287,8 @@ func TestFileStdout(t *testing.T) { os.Stdout = old out := <-outC - require.Equal(t, expNewFile, out) + require.NoError(t, out.err) + require.Equal(t, expNewFile, out.str) } func createFile(t *testing.T) *os.File { diff --git a/plugins/outputs/graphite/graphite_test.go b/plugins/outputs/graphite/graphite_test.go index edbcad25d87fd..93ea93bd9ed27 100644 --- a/plugins/outputs/graphite/graphite_test.go +++ b/plugins/outputs/graphite/graphite_test.go @@ -77,18 +77,7 @@ func TestGraphiteReconnect(t *testing.T) { t.Log("Writing metric after server came up, we expect automatic reconnect on write without calling Connect() again") require.NoError(t, g.Write([]telegraf.Metric{m})) - go func() { - defer wg.Done() - conn, err := (tcpServer).Accept() - require.NoError(t, err) - reader := bufio.NewReader(conn) - tp := textproto.NewReader(reader) - data1, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "192_168_0_1.|us-west-2|.mymeasurement.myfield 0.123 1289430000", data1) - require.NoError(t, conn.Close()) - require.NoError(t, tcpServer.Close()) - }() + simulateTCPServer(t, &wg, tcpServer, "192_168_0_1.|us-west-2|.mymeasurement.myfield 0.123 1289430000") wg.Wait() require.NoError(t, g.Close()) @@ -99,7 +88,7 @@ func TestGraphiteOK(t *testing.T) { // Start TCP server wg.Add(1) t.Log("Starting server") - TCPServer1(t, &wg) + tcpServer1(t, &wg) // Init plugin g := Graphite{ @@ -145,7 +134,7 @@ func TestGraphiteOK(t *testing.T) { var wg2 sync.WaitGroup // Start TCP server wg2.Add(1) - TCPServer2(t, &wg2) + tcpServer2(t, &wg2) // Write but expect an error, but reconnect err3 := g.Write(metrics2) t.Log("Finished writing second data, it should have reconnected automatically") @@ -163,18 +152,8 @@ func TestGraphiteStrictRegex(t *testing.T) { t.Log("Starting server") tcpServer, err := net.Listen("tcp", "127.0.0.1:12042") require.NoError(t, err) - go func() { - defer wg.Done() - conn, err := (tcpServer).Accept() - require.NoError(t, err) - reader := bufio.NewReader(conn) - tp := textproto.NewReader(reader) - data1, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "192_168_0_1.|us-west-2|.mymeasurement.myfield 0.123 1289430000", data1) - require.NoError(t, conn.Close()) - require.NoError(t, tcpServer.Close()) - }() + + simulateTCPServer(t, &wg, tcpServer, "192_168_0_1.|us-west-2|.mymeasurement.myfield 0.123 1289430000") m := metric.New( "mymeasurement", @@ -204,7 +183,7 @@ func TestGraphiteOkWithSeparatorDot(t *testing.T) { // Start TCP server wg.Add(1) t.Log("Starting server") - TCPServer1(t, &wg) + tcpServer1(t, &wg) // Init plugin g := Graphite{ @@ -251,7 +230,7 @@ func TestGraphiteOkWithSeparatorDot(t *testing.T) { var wg2 sync.WaitGroup // Start TCP server wg2.Add(1) - TCPServer2(t, &wg2) + tcpServer2(t, &wg2) // Write but expect an error, but reconnect err3 := g.Write(metrics2) t.Log("Finished writing second data, it should have reconnected automatically") @@ -268,7 +247,7 @@ func TestGraphiteOkWithSeparatorUnderscore(t *testing.T) { // Start TCP server wg.Add(1) t.Log("Starting server") - TCPServer1(t, &wg) + tcpServer1(t, &wg) // Init plugin g := Graphite{ @@ -315,7 +294,7 @@ func TestGraphiteOkWithSeparatorUnderscore(t *testing.T) { var wg2 sync.WaitGroup // Start TCP server wg2.Add(1) - TCPServer2(t, &wg2) + tcpServer2(t, &wg2) // Write but expect an error, but reconnect err3 := g.Write(metrics2) t.Log("Finished writing second data, it should have reconnected automatically") @@ -332,7 +311,7 @@ func TestGraphiteOKWithMultipleTemplates(t *testing.T) { // Start TCP server wg.Add(1) t.Log("Starting server") - TCPServer1WithMultipleTemplates(t, &wg) + tcpServer1WithMultipleTemplates(t, &wg) // Init plugin g := Graphite{ @@ -383,7 +362,7 @@ func TestGraphiteOKWithMultipleTemplates(t *testing.T) { var wg2 sync.WaitGroup // Start TCP server wg2.Add(1) - TCPServer2WithMultipleTemplates(t, &wg2) + tcpServer2WithMultipleTemplates(t, &wg2) // Write but expect an error, but reconnect err3 := g.Write(metrics2) t.Log("Finished writing second data, it should have reconnected automatically") @@ -400,7 +379,7 @@ func TestGraphiteOkWithTags(t *testing.T) { // Start TCP server wg.Add(1) t.Log("Starting server") - TCPServer1WithTags(t, &wg) + tcpServer1WithTags(t, &wg) // Init plugin g := Graphite{ @@ -447,7 +426,7 @@ func TestGraphiteOkWithTags(t *testing.T) { var wg2 sync.WaitGroup // Start TCP server wg2.Add(1) - TCPServer2WithTags(t, &wg2) + tcpServer2WithTags(t, &wg2) // Write but expect an error, but reconnect err3 := g.Write(metrics2) t.Log("Finished writing second data, it should have reconnected automatically") @@ -464,7 +443,7 @@ func TestGraphiteOkWithTagsAndSeparatorDot(t *testing.T) { // Start TCP server wg.Add(1) t.Log("Starting server") - TCPServer1WithTags(t, &wg) + tcpServer1WithTags(t, &wg) // Init plugin g := Graphite{ @@ -512,7 +491,7 @@ func TestGraphiteOkWithTagsAndSeparatorDot(t *testing.T) { var wg2 sync.WaitGroup // Start TCP server wg2.Add(1) - TCPServer2WithTags(t, &wg2) + tcpServer2WithTags(t, &wg2) // Write but expect an error, but reconnect err3 := g.Write(metrics2) t.Log("Finished writing second data, it should have reconnected automatically") @@ -529,7 +508,7 @@ func TestGraphiteOkWithTagsAndSeparatorUnderscore(t *testing.T) { // Start TCP server wg.Add(1) t.Log("Starting server") - TCPServer1WithTagsSeparatorUnderscore(t, &wg) + tcpServer1WithTagsSeparatorUnderscore(t, &wg) // Init plugin g := Graphite{ @@ -577,7 +556,7 @@ func TestGraphiteOkWithTagsAndSeparatorUnderscore(t *testing.T) { var wg2 sync.WaitGroup // Start TCP server wg2.Add(1) - TCPServer2WithTagsSeparatorUnderscore(t, &wg2) + tcpServer2WithTagsSeparatorUnderscore(t, &wg2) // Write but expect an error, but reconnect err3 := g.Write(metrics2) t.Log("Finished writing second data, it should have reconnected automatically") @@ -695,150 +674,97 @@ func query(url string, data interface{}) error { return json.Unmarshal(raw, &data) } -func TCPServer1(t *testing.T, wg *sync.WaitGroup) { - tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") - require.NoError(t, err) +func simulateTCPServer(t *testing.T, wg *sync.WaitGroup, tcpServer net.Listener, lines ...string) { go func() { defer wg.Done() - conn, err := (tcpServer).Accept() - require.NoError(t, err) + conn, err := tcpServer.Accept() + if err != nil { + t.Error(err) + return + } + defer func() { + if err := conn.Close(); err != nil { + t.Error(err) + } + if err := tcpServer.Close(); err != nil { + t.Error(err) + } + }() + reader := bufio.NewReader(conn) tp := textproto.NewReader(reader) - data1, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my.prefix.192_168_0_1.mymeasurement.myfield 3.14 1289430000", data1) - require.NoError(t, conn.Close()) - require.NoError(t, tcpServer.Close()) + + for _, line := range lines { + readLine, err := tp.ReadLine() + if err != nil { + t.Error(err) + return + } + + if line != readLine { + t.Error(err) + return + } + } }() } -func TCPServer2(t *testing.T, wg *sync.WaitGroup) { +func tcpServer1(t *testing.T, wg *sync.WaitGroup) { tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") require.NoError(t, err) - go func() { - defer wg.Done() - conn2, err := (tcpServer).Accept() - require.NoError(t, err) - reader := bufio.NewReader(conn2) - tp := textproto.NewReader(reader) - data2, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my.prefix.192_168_0_1.mymeasurement 3.14 1289430000", data2) - data3, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my.prefix.192_168_0_1.my_measurement 3.14 1289430000", data3) - require.NoError(t, conn2.Close()) - require.NoError(t, tcpServer.Close()) - }() + + simulateTCPServer(t, wg, tcpServer, "my.prefix.192_168_0_1.mymeasurement.myfield 3.14 1289430000") } -func TCPServer1WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { +func tcpServer2(t *testing.T, wg *sync.WaitGroup) { tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") require.NoError(t, err) - go func() { - defer wg.Done() - conn, err := (tcpServer).Accept() - require.NoError(t, err) - reader := bufio.NewReader(conn) - tp := textproto.NewReader(reader) - data1, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my.prefix.mymeasurement.valuetag.192_168_0_1.myfield 3.14 1289430000", data1) - require.NoError(t, conn.Close()) - require.NoError(t, tcpServer.Close()) - }() + + simulateTCPServer(t, wg, tcpServer, + "my.prefix.192_168_0_1.mymeasurement 3.14 1289430000", "my.prefix.192_168_0_1.my_measurement 3.14 1289430000") } -func TCPServer2WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { +func tcpServer1WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") require.NoError(t, err) - go func() { - defer wg.Done() - conn2, err := (tcpServer).Accept() - require.NoError(t, err) - reader := bufio.NewReader(conn2) - tp := textproto.NewReader(reader) - data2, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my.prefix.mymeasurement.valuetag.192_168_0_1 3.14 1289430000", data2) - data3, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my.prefix.192_168_0_1.my_measurement.valuetag 3.14 1289430000", data3) - require.NoError(t, conn2.Close()) - require.NoError(t, tcpServer.Close()) - }() + + simulateTCPServer(t, wg, tcpServer, "my.prefix.mymeasurement.valuetag.192_168_0_1.myfield 3.14 1289430000") } -func TCPServer1WithTags(t *testing.T, wg *sync.WaitGroup) { +func tcpServer2WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") require.NoError(t, err) - go func() { - defer wg.Done() - conn, err := (tcpServer).Accept() - require.NoError(t, err) - reader := bufio.NewReader(conn) - tp := textproto.NewReader(reader) - data1, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my.prefix.mymeasurement.myfield;host=192.168.0.1 3.14 1289430000", data1) - require.NoError(t, conn.Close()) - require.NoError(t, tcpServer.Close()) - }() + + simulateTCPServer(t, wg, tcpServer, + "my.prefix.mymeasurement.valuetag.192_168_0_1 3.14 1289430000", "my.prefix.192_168_0_1.my_measurement.valuetag 3.14 1289430000") } -func TCPServer2WithTags(t *testing.T, wg *sync.WaitGroup) { +func tcpServer1WithTags(t *testing.T, wg *sync.WaitGroup) { tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") require.NoError(t, err) - go func() { - defer wg.Done() - conn2, err := (tcpServer).Accept() - require.NoError(t, err) - reader := bufio.NewReader(conn2) - tp := textproto.NewReader(reader) - data2, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my.prefix.mymeasurement;host=192.168.0.1 3.14 1289430000", data2) - data3, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my.prefix.my_measurement;host=192.168.0.1 3.14 1289430000", data3) - require.NoError(t, conn2.Close()) - require.NoError(t, tcpServer.Close()) - }() + + simulateTCPServer(t, wg, tcpServer, "my.prefix.mymeasurement.myfield;host=192.168.0.1 3.14 1289430000") } -func TCPServer1WithTagsSeparatorUnderscore(t *testing.T, wg *sync.WaitGroup) { +func tcpServer2WithTags(t *testing.T, wg *sync.WaitGroup) { tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") require.NoError(t, err) - go func() { - defer wg.Done() - conn, err := (tcpServer).Accept() - require.NoError(t, err) - reader := bufio.NewReader(conn) - tp := textproto.NewReader(reader) - data1, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my_prefix_mymeasurement_myfield;host=192.168.0.1 3.14 1289430000", data1) - require.NoError(t, conn.Close()) - require.NoError(t, tcpServer.Close()) - }() + + simulateTCPServer(t, wg, tcpServer, + "my.prefix.mymeasurement;host=192.168.0.1 3.14 1289430000", "my.prefix.my_measurement;host=192.168.0.1 3.14 1289430000") } -func TCPServer2WithTagsSeparatorUnderscore(t *testing.T, wg *sync.WaitGroup) { +func tcpServer1WithTagsSeparatorUnderscore(t *testing.T, wg *sync.WaitGroup) { tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") require.NoError(t, err) - go func() { - defer wg.Done() - conn2, err := (tcpServer).Accept() - require.NoError(t, err) - reader := bufio.NewReader(conn2) - tp := textproto.NewReader(reader) - data2, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my_prefix_mymeasurement;host=192.168.0.1 3.14 1289430000", data2) - data3, err := tp.ReadLine() - require.NoError(t, err) - require.Equal(t, "my_prefix_my_measurement;host=192.168.0.1 3.14 1289430000", data3) - require.NoError(t, conn2.Close()) - require.NoError(t, tcpServer.Close()) - }() + + simulateTCPServer(t, wg, tcpServer, "my_prefix_mymeasurement_myfield;host=192.168.0.1 3.14 1289430000") +} + +func tcpServer2WithTagsSeparatorUnderscore(t *testing.T, wg *sync.WaitGroup) { + tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") + require.NoError(t, err) + + simulateTCPServer(t, wg, tcpServer, + "my_prefix_mymeasurement;host=192.168.0.1 3.14 1289430000", "my_prefix_my_measurement;host=192.168.0.1 3.14 1289430000") } diff --git a/plugins/outputs/graylog/graylog_test_linux.go b/plugins/outputs/graylog/graylog_test_linux.go index fd55491025d60..5bb733c719249 100644 --- a/plugins/outputs/graylog/graylog_test_linux.go +++ b/plugins/outputs/graylog/graylog_test_linux.go @@ -191,10 +191,25 @@ func UDPServer(t *testing.T, wg *sync.WaitGroup, namefieldnoprefix bool) string defer wg.Done() // in UDP scenario all 4 messages are received - require.NoError(t, recv()) - require.NoError(t, recv()) - require.NoError(t, recv()) - require.NoError(t, recv()) + err := recv() + if err != nil { + t.Error(err) + } + + err = recv() + if err != nil { + t.Error(err) + } + + err = recv() + if err != nil { + t.Error(err) + } + + err = recv() + if err != nil { + t.Error(err) + } }() return address } diff --git a/plugins/outputs/groundwork/groundwork.go b/plugins/outputs/groundwork/groundwork.go index bf61c56dbf878..5c770a7c97008 100644 --- a/plugins/outputs/groundwork/groundwork.go +++ b/plugins/outputs/groundwork/groundwork.go @@ -2,7 +2,6 @@ package groundwork import ( - "bytes" "context" _ "embed" "encoding/json" @@ -12,7 +11,7 @@ import ( "strings" "github.com/gwos/tcg/sdk/clients" - "github.com/gwos/tcg/sdk/logper" + "github.com/gwos/tcg/sdk/log" "github.com/gwos/tcg/sdk/transit" "github.com/hashicorp/go-uuid" @@ -95,28 +94,16 @@ func (g *Groundwork) Init() error { username.Destroy() password.Destroy() - logper.SetLogger( - func(fields interface{}, format string, a ...interface{}) { - g.Log.Error(adaptLog(fields, format, a...)) - }, - func(fields interface{}, format string, a ...interface{}) { - g.Log.Warn(adaptLog(fields, format, a...)) - }, - func(fields interface{}, format string, a ...interface{}) { - g.Log.Info(adaptLog(fields, format, a...)) - }, - func(fields interface{}, format string, a ...interface{}) { - g.Log.Debug(adaptLog(fields, format, a...)) - }, - func() bool { return g.Log.Level() >= telegraf.Debug }, - ) + /* adapt SDK logger */ + log.Logger = newLogger(g.Log).WithGroup("tcg.sdk") + return nil } func (g *Groundwork) Connect() error { err := g.client.Connect() if err != nil { - return fmt.Errorf("could not log in: %w", err) + return fmt.Errorf("could not login: %w", err) } return nil } @@ -124,7 +111,7 @@ func (g *Groundwork) Connect() error { func (g *Groundwork) Close() error { err := g.client.Disconnect() if err != nil { - return fmt.Errorf("could not log out: %w", err) + return fmt.Errorf("could not logout: %w", err) } return nil } @@ -346,15 +333,15 @@ func (g *Groundwork) parseMetric(metric telegraf.Metric) (metricMeta, *transit.M } if m, ok := metric.GetTag("message"); ok { - serviceObject.LastPluginOutput = m + serviceObject.LastPluginOutput = strings.ToValidUTF8(m, "?") } else if m, ok := metric.GetField("message"); ok { switch m := m.(type) { case string: - serviceObject.LastPluginOutput = m + serviceObject.LastPluginOutput = strings.ToValidUTF8(m, "?") case []byte: - serviceObject.LastPluginOutput = string(m) + serviceObject.LastPluginOutput = strings.ToValidUTF8(string(m), "?") default: - serviceObject.LastPluginOutput = fmt.Sprintf("%v", m) + serviceObject.LastPluginOutput = strings.ToValidUTF8(fmt.Sprintf("%v", m), "?") } } @@ -395,46 +382,3 @@ func validStatus(status string) bool { } return false } - -func adaptLog(fields interface{}, format string, a ...interface{}) string { - buf := &bytes.Buffer{} - if format != "" { - fmt.Fprintf(buf, format, a...) - } - fmtField := func(k string, v interface{}) { - format := " %s:" - if len(k) == 0 { - format = " " - } - if _, ok := v.(int); ok { - format += "%d" - } else { - format += "%q" - } - fmt.Fprintf(buf, format, k, v) - } - if ff, ok := fields.(interface { - LogFields() (map[string]interface{}, map[string][]byte) - }); ok { - m1, m2 := ff.LogFields() - for k, v := range m1 { - fmtField(k, v) - } - for k, v := range m2 { - fmtField(k, v) - } - } else if ff, ok := fields.(map[string]interface{}); ok { - for k, v := range ff { - fmtField(k, v) - } - } else if ff, ok := fields.([]interface{}); ok { - for _, v := range ff { - fmtField("", v) - } - } - out := buf.Bytes() - if len(out) > 1 { - out = append(bytes.ToUpper(out[0:1]), out[1:]...) - } - return string(out) -} diff --git a/plugins/outputs/groundwork/groundwork_test.go b/plugins/outputs/groundwork/groundwork_test.go index a1b8b18fc19cf..de073f7b6d86b 100644 --- a/plugins/outputs/groundwork/groundwork_test.go +++ b/plugins/outputs/groundwork/groundwork_test.go @@ -1,6 +1,7 @@ package groundwork import ( + "bytes" "encoding/json" "fmt" "io" @@ -13,6 +14,8 @@ import ( "github.com/stretchr/testify/require" "github.com/influxdata/telegraf" + "github.com/influxdata/telegraf/config" + "github.com/influxdata/telegraf/logger" "github.com/influxdata/telegraf/testutil" ) @@ -23,6 +26,57 @@ const ( customAppType = "SYSLOG" ) +func TestWriteWithDebug(t *testing.T) { + // Generate test metric with default name to test Write logic + intMetric := testutil.TestMetric(42, "IntMetric") + srvTok := "88fcf0de5bf7-530b-ee84-d385-cc6761ce" + + // Simulate Groundwork server that should receive custom metrics + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + body, err := io.ReadAll(r.Body) + require.NoError(t, err) + + // Decode body to use in assertions below + var obj transit.ResourcesWithServicesRequest + err = json.Unmarshal(body, &obj) + require.NoError(t, err) + + // Check if server gets proper data + require.Equal(t, "IntMetric", obj.Resources[0].Services[0].Name) + require.Equal(t, int64(42), *obj.Resources[0].Services[0].Metrics[0].Value.IntegerValue) + + // Send back details + ans := "Content-type: application/json\n\n" + `{"message":"` + srvTok + `"}` + _, err = fmt.Fprintln(w, ans) + require.NoError(t, err) + })) + + i := Groundwork{ + Server: server.URL, + AgentID: defaultTestAgentID, + Username: config.NewSecret([]byte(`tu ser`)), + Password: config.NewSecret([]byte(`pu ser`)), + DefaultAppType: defaultAppType, + DefaultHost: defaultHost, + DefaultServiceState: string(transit.ServiceOk), + ResourceTag: "host", + Log: testutil.Logger{}, + } + + buf := new(bytes.Buffer) + require.NoError(t, logger.SetupLogging(&logger.Config{Debug: true})) + logger.RedirectLogging(buf) + + require.NoError(t, i.Init()) + require.NoError(t, i.Write([]telegraf.Metric{intMetric})) + + require.NoError(t, logger.CloseLogging()) + require.Contains(t, buf.String(), defaultTestAgentID) + require.Contains(t, buf.String(), srvTok) + + server.Close() +} + func TestWriteWithDefaults(t *testing.T) { // Generate test metric with default name to test Write logic intMetric := testutil.TestMetric(42, "IntMetric") diff --git a/plugins/outputs/groundwork/log_adapter.go b/plugins/outputs/groundwork/log_adapter.go new file mode 100644 index 0000000000000..4b4f9902e2bf9 --- /dev/null +++ b/plugins/outputs/groundwork/log_adapter.go @@ -0,0 +1,87 @@ +package groundwork + +import ( + "context" + "encoding/json" + "log/slog" //nolint:depguard // Required for wrapping internal logging facility + "strings" + + "github.com/influxdata/telegraf" +) + +// newLogger creates telegraf.Logger adapter for slog.Logger +func newLogger(l telegraf.Logger) *slog.Logger { + return slog.New(&tlgHandler{Log: l}) +} + +// tlgHandler translates slog.Record into telegraf.Logger call +// inspired by https://github.com/golang/example/blob/master/slog-handler-guide/README.md +type tlgHandler struct { + attrs []slog.Attr + groups []string + + Log telegraf.Logger +} + +// Enabled implements slog.Handler interface +// It interprets errors as errors and everything else as debug. +func (h *tlgHandler) Enabled(_ context.Context, level slog.Level) bool { + if level == slog.LevelError { + return h.Log.Level() >= telegraf.Error + } + return h.Log.Level() >= telegraf.Debug +} + +// Handle implements slog.Handler interface +// It interprets errors as errors and everything else as debug. +func (h *tlgHandler) Handle(_ context.Context, r slog.Record) error { + attrs := make([]slog.Attr, 0, 2+len(h.attrs)+r.NumAttrs()) + attrs = append(attrs, + slog.String("logger", strings.Join(h.groups, ",")), + slog.String("message", r.Message), + ) + attrs = append(attrs, h.attrs...) + + r.Attrs(func(attr slog.Attr) bool { + if v, ok := attr.Value.Any().(json.RawMessage); ok { + attrs = append(attrs, slog.String(attr.Key, string(v))) + return true + } + attrs = append(attrs, attr) + return true + }) + + if r.Level == slog.LevelError { + h.Log.Error(attrs) + } else { + h.Log.Debug(attrs) + } + + return nil +} + +// WithAttrs implements slog.Handler interface +func (h *tlgHandler) WithAttrs(attrs []slog.Attr) slog.Handler { + nested := &tlgHandler{Log: h.Log} + nested.attrs = append(nested.attrs, h.attrs...) + nested.groups = append(nested.groups, h.groups...) + + for _, attr := range attrs { + if v, ok := attr.Value.Any().(json.RawMessage); ok { + nested.attrs = append(nested.attrs, slog.String(attr.Key, string(v))) + continue + } + nested.attrs = append(nested.attrs, attr) + } + + return nested +} + +// WithGroup implements slog.Handler interface +func (h *tlgHandler) WithGroup(name string) slog.Handler { + nested := &tlgHandler{Log: h.Log} + nested.attrs = append(nested.attrs, h.attrs...) + nested.groups = append(nested.groups, h.groups...) + nested.groups = append(nested.groups, name) + return nested +} diff --git a/plugins/outputs/mongodb/mongodb.go b/plugins/outputs/mongodb/mongodb.go index 67160b2b99651..6394494e17cfe 100644 --- a/plugins/outputs/mongodb/mongodb.go +++ b/plugins/outputs/mongodb/mongodb.go @@ -97,10 +97,10 @@ func (s *MongoDB) Init() error { switch s.AuthenticationType { case "SCRAM": if s.Username.Empty() { - return errors.New("SCRAM authentication must specify a username") + return errors.New("authentication for SCRAM must specify a username") } if s.Password.Empty() { - return errors.New("SCRAM authentication must specify a password") + return errors.New("authentication for SCRAM must specify a password") } username, err := s.Username.Get() if err != nil { diff --git a/plugins/outputs/nats/nats.go b/plugins/outputs/nats/nats.go index b2ee4daf3ac63..ace7901fd6766 100644 --- a/plugins/outputs/nats/nats.go +++ b/plugins/outputs/nats/nats.go @@ -268,7 +268,7 @@ func (n *NATS) Write(metrics []telegraf.Metric) error { // use the same Publish API for nats core and jetstream err = n.conn.Publish(n.Subject, buf) if err != nil { - return fmt.Errorf("FAILED to send NATS message: %w", err) + return fmt.Errorf("failed to send NATS message: %w", err) } } return nil diff --git a/plugins/outputs/newrelic/newrelic.go b/plugins/outputs/newrelic/newrelic.go index fecec5a2e366f..bceca05daa6b4 100644 --- a/plugins/outputs/newrelic/newrelic.go +++ b/plugins/outputs/newrelic/newrelic.go @@ -43,7 +43,7 @@ func (*NewRelic) SampleConfig() string { // Connect to the Output func (nr *NewRelic) Connect() error { if nr.InsightsKey == "" { - return errors.New("InsightKey is a required for newrelic") + return errors.New("'insights_key' is a required for newrelic") } err := nr.initClient() if err != nil { diff --git a/plugins/outputs/opentelemetry/opentelemetry_test.go b/plugins/outputs/opentelemetry/opentelemetry_test.go index 31de473599735..6ccbf6553222c 100644 --- a/plugins/outputs/opentelemetry/opentelemetry_test.go +++ b/plugins/outputs/opentelemetry/opentelemetry_test.go @@ -105,7 +105,11 @@ func newMockOtelService(t *testing.T) *mockOtelService { } pmetricotlp.RegisterGRPCServer(grpcServer, mockOtelService) - go func() { require.NoError(t, grpcServer.Serve(listener)) }() + go func() { + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } + }() grpcClient, err := grpc.NewClient(listener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) diff --git a/plugins/outputs/opentsdb/opentsdb.go b/plugins/outputs/opentsdb/opentsdb.go index 9396ae9987d38..620107363a5e1 100644 --- a/plugins/outputs/opentsdb/opentsdb.go +++ b/plugins/outputs/opentsdb/opentsdb.go @@ -74,11 +74,11 @@ func (o *OpenTSDB) Connect() error { uri := fmt.Sprintf("%s:%d", u.Host, o.Port) tcpAddr, err := net.ResolveTCPAddr("tcp", uri) if err != nil { - return fmt.Errorf("OpenTSDB TCP address cannot be resolved: %w", err) + return fmt.Errorf("failed to resolve TCP address: %w", err) } connection, err := net.DialTCP("tcp", nil, tcpAddr) if err != nil { - return fmt.Errorf("OpenTSDB Telnet connect fail: %w", err) + return fmt.Errorf("failed to connect to OpenTSDB: %w", err) } defer connection.Close() return nil @@ -154,11 +154,11 @@ func (o *OpenTSDB) WriteTelnet(metrics []telegraf.Metric, u *url.URL) error { uri := fmt.Sprintf("%s:%d", u.Host, o.Port) tcpAddr, err := net.ResolveTCPAddr("tcp", uri) if err != nil { - return fmt.Errorf("OpenTSDB: Telnet connect fail: %w", err) + return fmt.Errorf("failed to resolve TCP address: %w", err) } connection, err := net.DialTCP("tcp", nil, tcpAddr) if err != nil { - return errors.New("OpenTSDB: Telnet connect fail") + return fmt.Errorf("failed to connect to OpenTSDB: %w", err) } defer connection.Close() diff --git a/plugins/outputs/postgresql/postgresql_bench_test.go b/plugins/outputs/postgresql/postgresql_bench_test.go index 2d7832474cd35..0e9a5255f960d 100644 --- a/plugins/outputs/postgresql/postgresql_bench_test.go +++ b/plugins/outputs/postgresql/postgresql_bench_test.go @@ -24,7 +24,8 @@ func BenchmarkPostgresql_concurrent(b *testing.B) { } func benchmarkPostgresql(b *testing.B, gen <-chan []telegraf.Metric, concurrency int, foreignTags bool) { - p := newPostgresqlTest(b) + p, err := newPostgresqlTest(b) + require.NoError(b, err) connection, err := p.Connection.Get() require.NoError(b, err) diff --git a/plugins/outputs/postgresql/postgresql_test.go b/plugins/outputs/postgresql/postgresql_test.go index 38dffff801522..846f5c27ff5d5 100644 --- a/plugins/outputs/postgresql/postgresql_test.go +++ b/plugins/outputs/postgresql/postgresql_test.go @@ -230,7 +230,7 @@ type PostgresqlTest struct { Logger *LogAccumulator } -func newPostgresqlTest(tb testing.TB) *PostgresqlTest { +func newPostgresqlTest(tb testing.TB) (*PostgresqlTest, error) { if testing.Short() { tb.Skip("Skipping integration test in short mode") } @@ -257,8 +257,9 @@ func newPostgresqlTest(tb testing.TB) *PostgresqlTest { } tb.Cleanup(container.Terminate) - err := container.Start() - require.NoError(tb, err, "failed to start container") + if err := container.Start(); err != nil { + return nil, fmt.Errorf("failed to start container: %w", err) + } p := newPostgresql() connection := fmt.Sprintf( @@ -273,12 +274,15 @@ func newPostgresqlTest(tb testing.TB) *PostgresqlTest { logger := NewLogAccumulator(tb) p.Logger = logger p.LogLevel = "debug" - require.NoError(tb, p.Init()) + + if err := p.Init(); err != nil { + return nil, fmt.Errorf("failed to init plugin: %w", err) + } pt := &PostgresqlTest{Postgresql: p} pt.Logger = logger - return pt + return pt, nil } func TestPostgresqlConnectIntegration(t *testing.T) { @@ -286,11 +290,13 @@ func TestPostgresqlConnectIntegration(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) require.NoError(t, p.Connect()) require.EqualValues(t, 1, p.db.Stat().MaxConns()) - p = newPostgresqlTest(t) + p, err = newPostgresqlTest(t) + require.NoError(t, err) connection, err := p.Connection.Get() require.NoError(t, err) p.Connection = config.NewSecret([]byte(connection.String() + " pool_max_conns=2")) @@ -411,7 +417,8 @@ func TestWriteIntegration_sequential(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) require.NoError(t, p.Connect()) metrics := []telegraf.Metric{ @@ -448,7 +455,8 @@ func TestWriteIntegration_concurrent(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.dbConfig.MaxConns = 3 require.NoError(t, p.Connect()) @@ -507,7 +515,8 @@ func TestWriteIntegration_sequentialPermError(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) require.NoError(t, p.Connect()) metrics := []telegraf.Metric{ @@ -543,7 +552,8 @@ func TestWriteIntegration_sequentialSinglePermError(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) require.NoError(t, p.Connect()) metrics := []telegraf.Metric{ @@ -563,7 +573,8 @@ func TestWriteIntegration_concurrentPermError(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.dbConfig.MaxConns = 2 require.NoError(t, p.Connect()) @@ -595,7 +606,8 @@ func TestWriteIntegration_sequentialTempError(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) require.NoError(t, p.Connect()) // To avoid a race condition, we need to know when our goroutine has started listening to the log. @@ -620,10 +632,13 @@ func TestWriteIntegration_sequentialTempError(t *testing.T) { conf.Logger = nil c, err := pgx.ConnectConfig(context.Background(), conf) if err != nil { + t.Error(err) return true } _, err = c.Exec(context.Background(), "SELECT pg_terminate_backend($1)", pid) - require.NoError(t, err) + if err != nil { + t.Error(err) + } return true }, false) }() @@ -643,7 +658,8 @@ func TestWriteIntegration_concurrentTempError(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.dbConfig.MaxConns = 2 require.NoError(t, p.Connect()) @@ -669,10 +685,13 @@ func TestWriteIntegration_concurrentTempError(t *testing.T) { conf.Logger = nil c, err := pgx.ConnectConfig(context.Background(), conf) if err != nil { + t.Error(err) return true } _, err = c.Exec(context.Background(), "SELECT pg_terminate_backend($1)", pid) - require.NoError(t, err) + if err != nil { + t.Error(err) + } return true }, false) }() @@ -703,7 +722,8 @@ func TestTimestampColumnNameIntegration(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TimestampColumnName = "timestamp" require.NoError(t, p.Init()) require.NoError(t, p.Connect()) @@ -736,7 +756,8 @@ func TestWriteTagTableIntegration(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true require.NoError(t, p.Connect()) @@ -772,7 +793,8 @@ func TestWriteIntegration_tagError(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true require.NoError(t, p.Connect()) @@ -782,7 +804,7 @@ func TestWriteIntegration_tagError(t *testing.T) { require.NoError(t, p.Write(metrics)) // It'll have the table cached, so won't know we dropped it, will try insert, and get error. - _, err := p.db.Exec(ctx, "DROP TABLE \""+t.Name()+"_tag\"") + _, err = p.db.Exec(ctx, "DROP TABLE \""+t.Name()+"_tag\"") require.NoError(t, err) metrics = []telegraf.Metric{ @@ -802,7 +824,8 @@ func TestWriteIntegration_tagError_foreignConstraint(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true p.ForeignTagConstraint = true require.NoError(t, p.Connect()) @@ -813,7 +836,7 @@ func TestWriteIntegration_tagError_foreignConstraint(t *testing.T) { require.NoError(t, p.Write(metrics)) // It'll have the table cached, so won't know we dropped it, will try insert, and get error. - _, err := p.db.Exec(ctx, "DROP TABLE \""+t.Name()+"_tag\"") + _, err = p.db.Exec(ctx, "DROP TABLE \""+t.Name()+"_tag\"") require.NoError(t, err) metrics = []telegraf.Metric{ @@ -839,7 +862,8 @@ func TestWriteIntegration_utf8(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true require.NoError(t, p.Connect()) @@ -866,7 +890,8 @@ func TestWriteIntegration_UnsignedIntegers(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.Uint64Type = PgUint8 require.NoError(t, p.Init()) if err := p.Connect(); err != nil { @@ -902,7 +927,8 @@ func TestStressConcurrencyIntegration(t *testing.T) { concurrency := 4 loops := 100 - pctl := newPostgresqlTest(t) + pctl, err := newPostgresqlTest(t) + require.NoError(t, err) pctl.Logger.emitLevel = pgx.LogLevelWarn require.NoError(t, pctl.Connect()) @@ -916,18 +942,30 @@ func TestStressConcurrencyIntegration(t *testing.T) { copy(mShuf, metrics) rand.Shuffle(len(mShuf), func(a, b int) { mShuf[a], mShuf[b] = mShuf[b], mShuf[a] }) - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + if err != nil { + t.Error(err) + } + p.TagsAsForeignKeys = true p.Logger.emitLevel = pgx.LogLevelWarn p.dbConfig.MaxConns = int32(rand.Intn(3) + 1) - require.NoError(t, p.Connect()) + if err := p.Connect(); err != nil { + t.Error(err) + } wgStart.Done() wgStart.Wait() - err := p.Write(mShuf) - require.NoError(t, err) - require.NoError(t, p.Close()) - require.False(t, p.Logger.HasLevel(pgx.LogLevelWarn)) + if err := p.Write(mShuf); err != nil { + t.Error(err) + } + if err := p.Close(); err != nil { + t.Error(err) + } + if p.Logger.HasLevel(pgx.LogLevelWarn) { + t.Errorf("logger mustn't have a warning level") + } + wgDone.Done() }() } diff --git a/plugins/outputs/postgresql/table_manager_test.go b/plugins/outputs/postgresql/table_manager_test.go index 2f7b82f71e7f0..520419fb3dca0 100644 --- a/plugins/outputs/postgresql/table_manager_test.go +++ b/plugins/outputs/postgresql/table_manager_test.go @@ -16,7 +16,8 @@ func TestTableManagerIntegration_EnsureStructure(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) require.NoError(t, p.Connect()) cols := []utils.Column{ @@ -46,14 +47,15 @@ func TestTableManagerIntegration_EnsureStructure_alter(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) require.NoError(t, p.Connect()) cols := []utils.Column{ p.columnFromTag("foo", ""), p.columnFromField("bar", 0), } - _, err := p.tableManager.EnsureStructure( + _, err = p.tableManager.EnsureStructure( ctx, p.db, p.tableManager.table(t.Name()), @@ -90,14 +92,15 @@ func TestTableManagerIntegration_EnsureStructure_overflowTableName(t *testing.T) t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) require.NoError(t, p.Connect()) tbl := p.tableManager.table("ăăăăăăăăăăăăăăăăăăăăăăăăăăăăăăăă") // 32 2-byte unicode characters = 64 bytes cols := []utils.Column{ p.columnFromField("foo", 0), } - _, err := p.tableManager.EnsureStructure( + _, err = p.tableManager.EnsureStructure( ctx, p.db, tbl, @@ -117,7 +120,8 @@ func TestTableManagerIntegration_EnsureStructure_overflowTagName(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) require.NoError(t, p.Connect()) tbl := p.tableManager.table(t.Name()) @@ -125,7 +129,7 @@ func TestTableManagerIntegration_EnsureStructure_overflowTagName(t *testing.T) { p.columnFromTag("ăăăăăăăăăăăăăăăăăăăăăăăăăăăăăăăă", "a"), // 32 2-byte unicode characters = 64 bytes p.columnFromField("foo", 0), } - _, err := p.tableManager.EnsureStructure( + _, err = p.tableManager.EnsureStructure( ctx, p.db, tbl, @@ -144,7 +148,8 @@ func TestTableManagerIntegration_EnsureStructure_overflowFieldName(t *testing.T) t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) require.NoError(t, p.Connect()) tbl := p.tableManager.table(t.Name()) @@ -172,14 +177,15 @@ func TestTableManagerIntegration_getColumns(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) require.NoError(t, p.Connect()) cols := []utils.Column{ p.columnFromTag("foo", ""), p.columnFromField("baz", 0), } - _, err := p.tableManager.EnsureStructure( + _, err = p.tableManager.EnsureStructure( ctx, p.db, p.tableManager.table(t.Name()), @@ -206,7 +212,8 @@ func TestTableManagerIntegration_MatchSource(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true require.NoError(t, p.Connect()) @@ -225,7 +232,8 @@ func TestTableManagerIntegration_MatchSource_UnsignedIntegers(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.Uint64Type = PgUint8 require.NoError(t, p.Init()) if err := p.Connect(); err != nil { @@ -250,7 +258,8 @@ func TestTableManagerIntegration_noCreateTable(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.CreateTemplates = nil require.NoError(t, p.Connect()) @@ -267,7 +276,8 @@ func TestTableManagerIntegration_noCreateTagTable(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagTableCreateTemplates = nil p.TagsAsForeignKeys = true require.NoError(t, p.Connect()) @@ -286,7 +296,8 @@ func TestTableManagerIntegration_cache(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true require.NoError(t, p.Connect()) @@ -304,7 +315,8 @@ func TestTableManagerIntegration_noAlterMissingTag(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.AddColumnTemplates = []*sqltemplate.Template{} require.NoError(t, p.Connect()) @@ -330,7 +342,8 @@ func TestTableManagerIntegration_noAlterMissingTagTableTag(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true p.TagTableAddColumnTemplates = []*sqltemplate.Template{} require.NoError(t, p.Connect()) @@ -358,7 +371,8 @@ func TestTableManagerIntegration_badAlterTagTable(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true tmpl := &sqltemplate.Template{} require.NoError(t, tmpl.UnmarshalText([]byte("bad"))) @@ -387,7 +401,8 @@ func TestTableManagerIntegration_noAlterMissingField(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.AddColumnTemplates = []*sqltemplate.Template{} require.NoError(t, p.Connect()) @@ -412,7 +427,8 @@ func TestTableManagerIntegration_badAlterField(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) tmpl := &sqltemplate.Template{} require.NoError(t, tmpl.UnmarshalText([]byte("bad"))) p.AddColumnTemplates = []*sqltemplate.Template{tmpl} @@ -434,7 +450,8 @@ func TestTableManagerIntegration_badAlterField(t *testing.T) { } func TestTableManager_addColumnTemplates(t *testing.T) { - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true require.NoError(t, p.Connect()) @@ -444,7 +461,8 @@ func TestTableManager_addColumnTemplates(t *testing.T) { tsrc := NewTableSources(p.Postgresql, metrics)[t.Name()] require.NoError(t, p.tableManager.MatchSource(ctx, p.db, tsrc)) - p = newPostgresqlTest(t) + p, err = newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true tmpl := &sqltemplate.Template{} require.NoError(t, tmpl.UnmarshalText([]byte(`-- addColumnTemplate: {{ . }}`))) @@ -471,7 +489,8 @@ func TestTableManager_addColumnTemplates(t *testing.T) { } func TestTableManager_TimeWithTimezone(t *testing.T) { - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true p.TimestampColumnType = "timestamp with time zone" require.NoError(t, p.Init()) diff --git a/plugins/outputs/postgresql/table_source_test.go b/plugins/outputs/postgresql/table_source_test.go index ab24eebf8890f..6ea957daed056 100644 --- a/plugins/outputs/postgresql/table_source_test.go +++ b/plugins/outputs/postgresql/table_source_test.go @@ -41,7 +41,8 @@ func TestTableSourceIntegration_tagJSONB(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsJsonb = true metrics := []telegraf.Metric{ @@ -64,7 +65,8 @@ func TestTableSourceIntegration_tagTable(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true p.tagsCache = freecache.NewCache(5 * 1024 * 1024) @@ -87,7 +89,8 @@ func TestTableSourceIntegration_tagTableJSONB(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true p.TagsAsJsonb = true p.tagsCache = freecache.NewCache(5 * 1024 * 1024) @@ -109,7 +112,8 @@ func TestTableSourceIntegration_fieldsJSONB(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.FieldsAsJsonb = true metrics := []telegraf.Metric{ @@ -131,7 +135,8 @@ func TestTableSourceIntegration_DropColumn_tag(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) metrics := []telegraf.Metric{ newMetric(t, "", MSS{"a": "one", "b": "two"}, MSI{"v": 1}), @@ -162,7 +167,8 @@ func TestTableSourceIntegration_DropColumn_tag_fkTrue_fcTrue(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true p.ForeignTagConstraint = true p.tagsCache = freecache.NewCache(5 * 1024 * 1024) @@ -200,7 +206,8 @@ func TestTableSourceIntegration_DropColumn_tag_fkTrue_fcFalse(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true p.ForeignTagConstraint = false p.tagsCache = freecache.NewCache(5 * 1024 * 1024) @@ -238,7 +245,8 @@ func TestTableSourceIntegration_DropColumn_field(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) metrics := []telegraf.Metric{ newMetric(t, "", MSS{"tag": "foo"}, MSI{"a": 1}), @@ -267,7 +275,8 @@ func TestTableSourceIntegration_InconsistentTags(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) metrics := []telegraf.Metric{ newMetric(t, "", MSS{"a": "1"}, MSI{"b": 2}), @@ -289,7 +298,8 @@ func TestTagTableSourceIntegration_InconsistentTags(t *testing.T) { t.Skip("Skipping integration test in short mode") } - p := newPostgresqlTest(t) + p, err := newPostgresqlTest(t) + require.NoError(t, err) p.TagsAsForeignKeys = true p.tagsCache = freecache.NewCache(5 * 1024 * 1024) diff --git a/plugins/outputs/socket_writer/socket_writer.go b/plugins/outputs/socket_writer/socket_writer.go index a12e926593954..b2aec04b97bc6 100644 --- a/plugins/outputs/socket_writer/socket_writer.go +++ b/plugins/outputs/socket_writer/socket_writer.go @@ -65,7 +65,7 @@ func (sw *SocketWriter) Connect() error { // Check address string for containing two if len(addrTuple) < 2 { - return errors.New("CID and/or port number missing") + return errors.New("port and/or CID number missing") } // Parse CID and port number from address string both being 32-bit @@ -75,7 +75,7 @@ func (sw *SocketWriter) Connect() error { return fmt.Errorf("failed to parse CID %s: %w", addrTuple[0], err) } if (cid >= uint64(math.Pow(2, 32))-1) && (cid <= 0) { - return fmt.Errorf("CID %d is out of range", cid) + return fmt.Errorf("value of CID %d is out of range", cid) } port, err := strconv.ParseUint(addrTuple[1], 10, 32) if err != nil { diff --git a/plugins/outputs/stackdriver/stackdriver_test.go b/plugins/outputs/stackdriver/stackdriver_test.go index 2c9d362e3e7bb..dc9408beacf04 100644 --- a/plugins/outputs/stackdriver/stackdriver_test.go +++ b/plugins/outputs/stackdriver/stackdriver_test.go @@ -62,7 +62,7 @@ func (s *mockMetricServer) CreateTimeSeries(ctx context.Context, req *monitoring if s.err != nil { var statusResp *status.Status switch s.err.Error() { - case "InvalidArgument": + case "invalid argument": statusResp = status.New(codes.InvalidArgument, s.err.Error()) default: statusResp = status.New(codes.Unknown, s.err.Error()) @@ -616,12 +616,12 @@ func TestWriteIgnoredErrors(t *testing.T) { }{ { name: "other errors reported", - err: errors.New("Unknown"), + err: errors.New("unknown"), expectedErr: true, }, { name: "invalid argument", - err: errors.New("InvalidArgument"), + err: errors.New("invalid argument"), expectedErr: false, }, } diff --git a/plugins/outputs/timestream/timestream.go b/plugins/outputs/timestream/timestream.go index 04d8322e9896b..2daa05cb2e51d 100644 --- a/plugins/outputs/timestream/timestream.go +++ b/plugins/outputs/timestream/timestream.go @@ -114,11 +114,11 @@ func (*Timestream) SampleConfig() string { func (t *Timestream) Connect() error { if t.DatabaseName == "" { - return errors.New("DatabaseName key is required") + return errors.New("'database_name' key is required") } if t.MappingMode == "" { - return errors.New("MappingMode key is required") + return errors.New("'mapping_mode' key is required") } if t.MappingMode != MappingModeSingleTable && t.MappingMode != MappingModeMultiTable { diff --git a/plugins/outputs/timestream/timestream_test.go b/plugins/outputs/timestream/timestream_test.go index c6842231647e1..4d0f11d942fb8 100644 --- a/plugins/outputs/timestream/timestream_test.go +++ b/plugins/outputs/timestream/timestream_test.go @@ -74,13 +74,13 @@ func TestConnectValidatesConfigParameters(t *testing.T) { } // checking base arguments noDatabaseName := Timestream{Log: testutil.Logger{}} - require.Contains(t, noDatabaseName.Connect().Error(), "DatabaseName") + require.ErrorContains(t, noDatabaseName.Connect(), "'database_name' key is required") noMappingMode := Timestream{ DatabaseName: tsDbName, Log: testutil.Logger{}, } - require.Contains(t, noMappingMode.Connect().Error(), "MappingMode") + require.ErrorContains(t, noMappingMode.Connect(), "'mapping_mode' key is required") incorrectMappingMode := Timestream{ DatabaseName: tsDbName, diff --git a/plugins/parsers/dropwizard/parser.go b/plugins/parsers/dropwizard/parser.go index 31e2db4eddb30..39c738bf612fd 100644 --- a/plugins/parsers/dropwizard/parser.go +++ b/plugins/parsers/dropwizard/parser.go @@ -2,6 +2,7 @@ package dropwizard import ( "encoding/json" + "errors" "fmt" "time" @@ -97,8 +98,8 @@ func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) { } // ParseLine is not supported by the dropwizard format -func (p *Parser) ParseLine(line string) (telegraf.Metric, error) { - return nil, fmt.Errorf("ParseLine not supported: %s, for data format: dropwizard", line) +func (p *Parser) ParseLine(_ string) (telegraf.Metric, error) { + return nil, errors.New("parsing line is not supported by the dropwizard format") } // SetDefaultTags sets the default tags diff --git a/plugins/parsers/influx/influx_upstream/parser.go b/plugins/parsers/influx/influx_upstream/parser.go index 6f2131ab3e4d4..9a21458c30de8 100644 --- a/plugins/parsers/influx/influx_upstream/parser.go +++ b/plugins/parsers/influx/influx_upstream/parser.go @@ -21,7 +21,6 @@ const ( var ( ErrNoMetric = errors.New("no metric in line") - ErrEOF = errors.New("EOF") ) type TimeFunc func() time.Time @@ -259,7 +258,7 @@ func (sp *StreamParser) Next() (telegraf.Metric, error) { return nil, err } - return nil, ErrEOF + return nil, io.EOF } m, err := nextMetric(sp.decoder, sp.precision, sp.defaultTime, false) diff --git a/plugins/parsers/influx/influx_upstream/parser_test.go b/plugins/parsers/influx/influx_upstream/parser_test.go index b5f6497bd2f76..04ccc2b04581a 100644 --- a/plugins/parsers/influx/influx_upstream/parser_test.go +++ b/plugins/parsers/influx/influx_upstream/parser_test.go @@ -660,7 +660,7 @@ func TestStreamParser(t *testing.T) { for { m, err := parser.Next() if err != nil { - if errors.Is(err, ErrEOF) { + if errors.Is(err, io.EOF) { break } require.Equal(t, tt.err.Error(), err.Error()) @@ -955,7 +955,7 @@ func TestStreamParserErrorString(t *testing.T) { var errs []error for i := 0; i < 20; i++ { _, err := parser.Next() - if errors.Is(err, ErrEOF) { + if errors.Is(err, io.EOF) { break } @@ -994,7 +994,7 @@ func TestStreamParserReaderError(t *testing.T) { require.Equal(t, err, readerErr) _, err = parser.Next() - require.Equal(t, err, ErrEOF) + require.Equal(t, err, io.EOF) } func TestStreamParserProducesAllAvailableMetrics(t *testing.T) { diff --git a/plugins/parsers/json/json_flattener.go b/plugins/parsers/json/json_flattener.go index ee201b90edfeb..f003039f09ed6 100644 --- a/plugins/parsers/json/json_flattener.go +++ b/plugins/parsers/json/json_flattener.go @@ -64,8 +64,7 @@ func (f *JSONFlattener) FullFlattenJSON(fieldName string, v interface{}, convert case nil: return nil default: - return fmt.Errorf("JSON Flattener: got unexpected type %T with value %v (%s)", - t, t, fieldName) + return fmt.Errorf("json flattener: got unexpected type %T with value %v (%s)", t, t, fieldName) } return nil } diff --git a/plugins/parsers/json/parser.go b/plugins/parsers/json/parser.go index 4f6bc687a09f7..d6c9137320430 100644 --- a/plugins/parsers/json/parser.go +++ b/plugins/parsers/json/parser.go @@ -92,7 +92,7 @@ func (p *Parser) parseObject(data map[string]interface{}, timestamp time.Time) ( } if f.Fields[p.TimeKey] == nil { - err := errors.New("JSON time key could not be found") + err := errors.New("'json_time_key' could not be found") return nil, err } diff --git a/plugins/parsers/json/parser_test.go b/plugins/parsers/json/parser_test.go index cb8ee4aaa81ad..56694ba9fb7db 100644 --- a/plugins/parsers/json/parser_test.go +++ b/plugins/parsers/json/parser_test.go @@ -839,7 +839,7 @@ func TestTimeErrors(t *testing.T) { actual, err = parser.Parse([]byte(testString2)) require.Error(t, err) require.Empty(t, actual) - require.Equal(t, errors.New("JSON time key could not be found"), err) + require.Equal(t, errors.New("'json_time_key' could not be found"), err) } func TestShareTimestamp(t *testing.T) { diff --git a/plugins/parsers/json_v2/parser.go b/plugins/parsers/json_v2/parser.go index 0381a2a142588..f4def6f34e688 100644 --- a/plugins/parsers/json_v2/parser.go +++ b/plugins/parsers/json_v2/parser.go @@ -230,7 +230,7 @@ func (p *Parser) processMetric(input []byte, data []DataSet, tag bool, timestamp metrics := make([][]telegraf.Metric, 0, len(data)) for _, c := range data { if c.Path == "" { - return nil, errors.New("GJSON path is required") + return nil, errors.New("the GJSON path is required") } result := gjson.GetBytes(input, c.Path) if err := p.checkResult(result, c.Path); err != nil { @@ -477,7 +477,7 @@ func (p *Parser) processObjects(input []byte, objects []Object, timestamp time.T p.objectConfig = c if c.Path == "" { - return nil, errors.New("GJSON path is required") + return nil, errors.New("the GJSON path is required") } result := gjson.GetBytes(input, c.Path) @@ -649,7 +649,7 @@ func (p *Parser) isExcluded(key string) bool { } func (p *Parser) ParseLine(_ string) (telegraf.Metric, error) { - return nil, errors.New("ParseLine is designed for parsing influx line protocol, therefore not implemented for parsing JSON") + return nil, errors.New("parsing line is not supported by JSON format") } func (p *Parser) SetDefaultTags(tags map[string]string) { diff --git a/plugins/parsers/nagios/parser_test.go b/plugins/parsers/nagios/parser_test.go index 663567ac3a219..4aef29bce2fb2 100644 --- a/plugins/parsers/nagios/parser_test.go +++ b/plugins/parsers/nagios/parser_test.go @@ -30,10 +30,10 @@ func TestGetExitCode(t *testing.T) { { name: "unexpected error type", errF: func() error { - return errors.New("I am not *exec.ExitError") + return errors.New("not *exec.ExitError") }, expCode: 3, - expErr: errors.New("I am not *exec.ExitError"), + expErr: errors.New("not *exec.ExitError"), }, } diff --git a/plugins/parsers/wavefront/element.go b/plugins/parsers/wavefront/element.go index a456d1595dbf7..1b78b44495225 100644 --- a/plugins/parsers/wavefront/element.go +++ b/plugins/parsers/wavefront/element.go @@ -3,12 +3,12 @@ package wavefront import ( "errors" "fmt" + "io" "strconv" "time" ) var ( - errEOF = errors.New("EOF") errInvalidTimestamp = errors.New("invalid timestamp") ) @@ -130,7 +130,7 @@ func (ep *loopedParser) parse(p *PointParser, pt *Point) error { return err } err = ep.wsParser.parse(p, pt) - if errors.Is(err, errEOF) { + if errors.Is(err, io.EOF) { break } } @@ -170,7 +170,7 @@ func (ep *whiteSpaceParser) parse(p *PointParser, _ *Point) error { if tok == EOF { if !ep.nextOptional { - return errEOF + return io.EOF } return nil } diff --git a/plugins/processors/aws_ec2/ec2.go b/plugins/processors/aws_ec2/ec2.go index d6ec50fae7a6b..4979b8aecc521 100644 --- a/plugins/processors/aws_ec2/ec2.go +++ b/plugins/processors/aws_ec2/ec2.go @@ -163,7 +163,10 @@ func (r *AwsEc2Processor) Stop() { if r.parallel != nil { r.parallel.Stop() } - r.cancelCleanupWorker() + if r.cancelCleanupWorker != nil { + r.cancelCleanupWorker() + r.cancelCleanupWorker = nil + } } func (r *AwsEc2Processor) logCacheStatistics(ctx context.Context) { @@ -268,7 +271,7 @@ func (r *AwsEc2Processor) lookupMetadata(metric telegraf.Metric) telegraf.Metric key = strings.ReplaceAll(key, "/", "_") } else { if idx := strings.LastIndex(key, "/"); idx > 0 { - key = key[idx:] + key = key[idx+1:] } } diff --git a/plugins/processors/snmp_lookup/lookup_test.go b/plugins/processors/snmp_lookup/lookup_test.go index b4ab67e33b917..68ae011b015eb 100644 --- a/plugins/processors/snmp_lookup/lookup_test.go +++ b/plugins/processors/snmp_lookup/lookup_test.go @@ -27,13 +27,13 @@ func (tsc *testSNMPConnection) Host() string { } func (tsc *testSNMPConnection) Get(_ []string) (*gosnmp.SnmpPacket, error) { - return &gosnmp.SnmpPacket{}, errors.New("Not implemented") + return &gosnmp.SnmpPacket{}, errors.New("not implemented") } func (tsc *testSNMPConnection) Walk(oid string, wf gosnmp.WalkFunc) error { tsc.calls.Add(1) if len(tsc.values) == 0 { - return errors.New("No values") + return errors.New("no values") } for void, v := range tsc.values { if void == oid || (len(void) > len(oid) && void[:len(oid)+1] == oid+".") { @@ -49,7 +49,7 @@ func (tsc *testSNMPConnection) Walk(oid string, wf gosnmp.WalkFunc) error { } func (tsc *testSNMPConnection) Reconnect() error { - return errors.New("Not implemented") + return errors.New("not implemented") } func TestRegistry(t *testing.T) { @@ -242,7 +242,7 @@ func TestUpdateAgent(t *testing.T) { t.Run("connection fail", func(t *testing.T) { p.getConnectionFunc = func(string) (snmp.Connection, error) { - return nil, errors.New("Random connection error") + return nil, errors.New("random connection error") } start := time.Now() diff --git a/scripts/ci.docker b/scripts/ci.docker index 2e26ffe4c1ef5..d87ea8c5b4dfc 100644 --- a/scripts/ci.docker +++ b/scripts/ci.docker @@ -1,4 +1,4 @@ -FROM golang:1.23.1 +FROM golang:1.23.2 RUN chmod -R 755 "$GOPATH" diff --git a/scripts/installgo_linux.sh b/scripts/installgo_linux.sh index 5f83110513f5d..46bf5eb34900e 100644 --- a/scripts/installgo_linux.sh +++ b/scripts/installgo_linux.sh @@ -2,10 +2,10 @@ set -eux -GO_VERSION="1.23.1" +GO_VERSION="1.23.2" GO_ARCH="linux-amd64" -# from https://golang.org/dl -GO_VERSION_SHA="49bbb517cfa9eee677e1e7897f7cf9cfdbcf49e05f61984a2789136de359f9bd" +# from https://go.dev/dl +GO_VERSION_SHA="542d3c1705f1c6a1c5a80d5dc62e2e45171af291e755d591c5e6531ef63b454e" # Download Go and verify Go tarball setup_go () { diff --git a/scripts/installgo_mac.sh b/scripts/installgo_mac.sh index 79ba17be1d3fe..fe37a5571f223 100644 --- a/scripts/installgo_mac.sh +++ b/scripts/installgo_mac.sh @@ -3,9 +3,9 @@ set -eux ARCH=$(uname -m) -GO_VERSION="1.23.1" -GO_VERSION_SHA_arm64="e223795ca340e285a760a6446ce57a74500b30e57469a4109961d36184d3c05a" # from https://golang.org/dl -GO_VERSION_SHA_amd64="488d9e4ca3e3ed513ee4edd91bef3a2360c65fa6d6be59cf79640bf840130a58" # from https://golang.org/dl +GO_VERSION="1.23.2" +GO_VERSION_SHA_arm64="d87031194fe3e01abdcaf3c7302148ade97a7add6eac3fec26765bcb3207b80f" # from https://go.dev/dl +GO_VERSION_SHA_amd64="445c0ef19d8692283f4c3a92052cc0568f5a048f4e546105f58e991d4aea54f5" # from https://go.dev/dl if [ "$ARCH" = 'arm64' ]; then GO_ARCH="darwin-arm64" diff --git a/scripts/installgo_windows.sh b/scripts/installgo_windows.sh index 8260c93048200..5e6a5d596dee0 100644 --- a/scripts/installgo_windows.sh +++ b/scripts/installgo_windows.sh @@ -2,7 +2,7 @@ set -eux -GO_VERSION="1.23.1" +GO_VERSION="1.23.2" setup_go () { choco upgrade golang --allow-downgrade --version=${GO_VERSION} diff --git a/tools/config_includer/generator.go b/tools/config_includer/generator.go index d4686cc984d33..bca1ce9dc0e25 100644 --- a/tools/config_includer/generator.go +++ b/tools/config_includer/generator.go @@ -28,7 +28,7 @@ func absolutePath(root, fn string) (string, error) { } pwd, err = filepath.Rel(root, filepath.Dir(pwd)) if err != nil { - return "", fmt.Errorf("Cannot determine location of %q relative to %q: %w", pwd, root, err) + return "", fmt.Errorf("cannot determine location of %q relative to %q: %w", pwd, root, err) } return string(filepath.Separator) + pwd, nil }