Skip to content

Commit

Permalink
Merge branch 'master' into feat/processors/snmp_lookup
Browse files Browse the repository at this point in the history
* master:
  fix(inputs.win_perf_counter): Do not rely on returned buffer size (influxdata#14241)
  feat(inputs.modbus): Add support for string-fields (influxdata#14145)
  chore(deps): Bump cloud.google.com/go/storage from 1.30.1 to 1.34.1 (influxdata#14253)
  chore(deps): Bump github.com/rabbitmq/amqp091-go from 1.8.1 to 1.9.0 (influxdata#14252)
  chore(deps): Bump github.com/hashicorp/consul/api from 1.25.1 to 1.26.1 (influxdata#14251)
  chore(deps): Bump github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs from 1.23.5 to 1.26.0 (influxdata#14249)
  fix(config): Fix comment removal in TOML files (influxdata#14240)
  feat(outputs.prometheus_client): Support listen on vsock (influxdata#14108)
  fix(inputs.mqtt_consumer): Resolve could not mark message delivered (influxdata#14243)
  chore(linters): Fix findings found by testifylint for Windows and enable it. (influxdata#14238)
  feat(migrations): Add option migration for inputs.nats_consumer (influxdata#14234)
  feat(migrations): Add option migration for inputs.mqtt_consumer (influxdata#14233)
  test(inputs.jolokia2_agent): Sort metrics as order is not consistent (influxdata#14227)
  • Loading branch information
Hipska committed Nov 7, 2023
2 parents e6150ca + 0e2203d commit 6d415cb
Show file tree
Hide file tree
Showing 50 changed files with 1,879 additions and 681 deletions.
17 changes: 17 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ linters:
- sqlclosecheck
- staticcheck
- tenv
- testifylint
- tparallel
- typecheck
- unconvert
Expand Down Expand Up @@ -246,6 +247,22 @@ linters-settings:
# Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
# Default: false
all: true
testifylint:
# Enable specific checkers.
# https://github.com/Antonboom/testifylint#checkers
# Default: ["bool-compare", "compares", "empty", "error-is-as", "error-nil", "expected-actual", "float-compare", "len", "require-error", "suite-dont-use-pkg", "suite-extra-assert-call"]
enable:
- bool-compare
- compares
- empty
- error-is-as
- error-nil
- expected-actual
- len
- require-error
- suite-dont-use-pkg
- suite-extra-assert-call
- suite-thelper

run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
Expand Down
4 changes: 2 additions & 2 deletions cmd/telegraf/main_win_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ func TestWindowsFlagsAreSet(t *testing.T) {
require.Equal(t, expectedString, m.serviceName)
require.Equal(t, expectedString, m.serviceDisplayName)
require.Equal(t, expectedString, m.serviceRestartDelay)
require.Equal(t, true, m.serviceAutoRestart)
require.Equal(t, true, m.console)
require.True(t, m.serviceAutoRestart)
require.True(t, m.console)
}
99 changes: 0 additions & 99 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"testing"
"time"

"github.com/compose-spec/compose-go/template"
"github.com/compose-spec/compose-go/utils"
"github.com/coreos/go-semver/semver"
"github.com/influxdata/toml"
"github.com/influxdata/toml/ast"
Expand Down Expand Up @@ -791,103 +789,6 @@ func parseConfig(contents []byte) (*ast.Table, error) {
return toml.Parse(outputBytes)
}

func removeComments(contents []byte) ([]byte, error) {
tomlReader := bytes.NewReader(contents)

// Initialize variables for tracking state
var inQuote, inComment, escaped bool
var quoteChar byte

// Initialize buffer for modified TOML data
var output bytes.Buffer

buf := make([]byte, 1)
// Iterate over each character in the file
for {
_, err := tomlReader.Read(buf)
if err != nil {
if errors.Is(err, io.EOF) {
break
}
return nil, err
}
char := buf[0]

// Toggle the escaped state at backslash to we have true every odd occurrence.
if char == '\\' {
escaped = !escaped
}

if inComment {
// If we're currently in a comment, check if this character ends the comment
if char == '\n' {
// End of line, comment is finished
inComment = false
_, _ = output.WriteRune('\n')
}
} else if inQuote {
// If we're currently in a quote, check if this character ends the quote
if char == quoteChar && !escaped {
// End of quote, we're no longer in a quote
inQuote = false
}
output.WriteByte(char)
} else {
// Not in a comment or a quote
if (char == '"' || char == '\'') && !escaped {
// Start of quote
inQuote = true
quoteChar = char
output.WriteByte(char)
} else if char == '#' && !escaped {
// Start of comment
inComment = true
} else {
// Not a comment or a quote, just output the character
output.WriteByte(char)
}
}

// Reset escaping if any other character occurred
if char != '\\' {
escaped = false
}
}
return output.Bytes(), nil
}

func substituteEnvironment(contents []byte, oldReplacementBehavior bool) ([]byte, error) {
options := []template.Option{
template.WithReplacementFunction(func(s string, m template.Mapping, cfg *template.Config) (string, error) {
result, applied, err := template.DefaultReplacementAppliedFunc(s, m, cfg)
if err == nil && !applied {
// Keep undeclared environment-variable patterns to reproduce
// pre-v1.27 behavior
return s, nil
}
if err != nil && strings.HasPrefix(err.Error(), "Invalid template:") {
// Keep invalid template patterns to ignore regexp substitutions
// like ${1}
return s, nil
}
return result, err
}),
template.WithoutLogging,
}
if oldReplacementBehavior {
options = append(options, template.WithPattern(oldVarRe))
}

envMap := utils.GetAsEqualsMap(os.Environ())
retVal, err := template.SubstituteWithOptions(string(contents), func(k string) (string, bool) {
if v, ok := envMap[k]; ok {
return v, ok
}
return "", false
}, options...)
return []byte(retVal), err
}

func (c *Config) addAggregator(name string, table *ast.Table) error {
creator, ok := aggregators.Aggregators[name]
if !ok {
Expand Down

0 comments on commit 6d415cb

Please sign in to comment.