Skip to content

Commit

Permalink
Merge branch 'main' into converter-sync-exporter-job-names
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbaranowski authored Dec 15, 2023
2 parents 7d8c3ee + a215d1b commit 0d21490
Show file tree
Hide file tree
Showing 102 changed files with 3,168 additions and 1,684 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Main (unreleased)

### Breaking changes

- `otelcol.receiver.prometheus` will drop all `otel_scope_info` metrics when converting them to OTLP. (@wildum)
- If the `otel_scope_info` metric has labels `otel_scope_name` and `otel_scope_version`,
their values will be used to set OTLP Instrumentation Scope name and version respectively.
- Labels of `otel_scope_info` metrics other than `otel_scope_name` and `otel_scope_version`
are added as scope attributes with the matching name and version.

- The `target` block in `prometheus.exporter.blackbox` requires a mandatory `name`
argument instead of a block label. (@hainenber)

Expand All @@ -37,6 +43,9 @@ Main (unreleased)

- `pyroscope.ebpf` support python on arm64 platforms. (@korniltsev)

- `otelcol.receiver.prometheus` does not drop histograms without buckets anymore. (@wildum)

- Added exemplars support to `otelcol.receiver.prometheus`. (@wildum)
- `mimir.rules.kubernetes` may now retry its startup on failure. (@hainenber)

- Added links between compatible components in the documentation to make it
Expand All @@ -52,6 +61,8 @@ Main (unreleased)

- Add support for passing extra arguments to the static converter such as `-config.expand-env`. (@erikbaranowski)

- Added 'country' mmdb-type to log pipeline-stage geoip. (@superstes)

### Bugfixes

- Update `pyroscope.ebpf` to fix a logical bug causing to profile to many kthreads instead of regular processes https://github.com/grafana/pyroscope/pull/2778 (@korniltsev)
Expand All @@ -66,6 +77,8 @@ Main (unreleased)

- Fixes `otelcol.connector.servicegraph` store ttl default value from 2ms to 2s. (@rlankfo)

- Add staleness tracking to labelstore to reduce memory usage. (@mattdurham)

### Other changes

- Bump github.com/IBM/sarama from v1.41.2 to v1.42.1
Expand Down Expand Up @@ -144,6 +157,8 @@ v0.38.0 (2023-11-21)

- Added support for python profiling to `pyroscope.ebpf` component. (@korniltsev)

- Added support for native Prometheus histograms to `otelcol.exporter.prometheus` (@wildum)

- Windows Flow Installer: Add /CONFIG /DISABLEPROFILING and /DISABLEREPORTING flag (@jkroepke)

- Add queueing logs remote write client for `loki.write` when WAL is enabled. (@thepalbi)
Expand Down
77 changes: 67 additions & 10 deletions cmd/internal/flowmode/cmd_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/grafana/agent/converter"
convert_diag "github.com/grafana/agent/converter/diag"
Expand Down Expand Up @@ -45,7 +46,8 @@ non-critical issues identified during the conversion where an
output can still be generated.
The -e flag can be used to pass extra arguments to the converter
which used by the original format.`,
which were used by the original format. Multiple arguments can be passed
by separating them with a space.`,
Args: cobra.RangeArgs(0, 1),
SilenceUsage: true,

Expand Down Expand Up @@ -75,7 +77,7 @@ which used by the original format.`,
cmd.Flags().StringVarP(&f.report, "report", "r", f.report, "The filepath and filename where the report is written.")
cmd.Flags().StringVarP(&f.sourceFormat, "source-format", "f", f.sourceFormat, fmt.Sprintf("The format of the source file. Supported formats: %s.", supportedFormatsList()))
cmd.Flags().BoolVarP(&f.bypassErrors, "bypass-errors", "b", f.bypassErrors, "Enable bypassing errors when converting")
cmd.Flags().StringVarP(&f.extraArgs, "extra-args", "e", f.extraArgs, "Extra arguments from the original format used by the converter")
cmd.Flags().StringVarP(&f.extraArgs, "extra-args", "e", f.extraArgs, "Extra arguments from the original format used by the converter. Multiple arguments can be passed by separating them with a space.")
return cmd
}

Expand Down Expand Up @@ -118,7 +120,12 @@ func convert(r io.Reader, fc *flowConvert) error {
return err
}

riverBytes, diags := converter.Convert(inputBytes, converter.Input(fc.sourceFormat), parseExtraArgs(fc.extraArgs))
ea, err := parseExtraArgs(fc.extraArgs)
if err != nil {
return err
}

riverBytes, diags := converter.Convert(inputBytes, converter.Input(fc.sourceFormat), ea)
err = generateConvertReport(diags, fc)
if err != nil {
return err
Expand Down Expand Up @@ -181,14 +188,64 @@ func supportedFormatsList() string {
return strings.Join(ret, ", ")
}

func parseExtraArgs(extraArgs string) []string {
func parseExtraArgs(extraArgs string) ([]string, error) {
var result []string
if extraArgs != "" {
arguments := strings.Fields(extraArgs)
for _, arg := range arguments {
parts := strings.Split(arg, "=")
result = append(result, parts...)
if extraArgs == "" {
return result, nil
}

arguments := strings.Fields(extraArgs)
for i, arg := range arguments {
fs := pflag.NewFlagSet("extra-args", pflag.ExitOnError)
fs.ParseErrorsWhitelist.UnknownFlags = true
keyStartIndex := 0
doParseFlagValue := false

// Split the argument into key and value.
splitArgs := strings.SplitN(arg, "=", 2)

// Append the key to the result.
result = append(result, splitArgs[0])

// If the flag has a value, add it to the FlagSet for parsing.
if len(splitArgs) == 2 && splitArgs[1] != "" {
doParseFlagValue = true
if arg[1] == '-' { // longhand flag, ie. --flag=value
keyStartIndex = 2
} else if arg[0] == '-' { // shorthand flag, ie. -f=value
keyStartIndex = 1
} else { // invalid flag that was split on '=' but has no dashes in the key
return nil, fmt.Errorf("invalid flag found: %s", arg)
}
}

if doParseFlagValue {
result = append(result, "")
lastIndex := len(result) - 1
key := splitArgs[0][keyStartIndex:]
if keyStartIndex == 2 {
fs.StringVar(&result[lastIndex], key, result[lastIndex], "")
} else {
// static mode uses keys with a single dash. We need to sanitize them here.
if len(key) != 1 {
arguments[i] = "-" + arguments[i]
fs.StringVar(&result[lastIndex], key, result[lastIndex], "")
} else {
fs.StringVarP(&result[lastIndex], "", key, result[lastIndex], "")
}
}

// We must parse the flag here because the pointer to the array element
// &result[lastIndex] is overridden by the next iteration of the loop.
// This can be improved if we preallocate the array, however we won't
// know the final length without analyzing the arguments so there
// is some complexity in doing so.
err := fs.Parse(arguments)
if err != nil {
return nil, err
}
}
}
return result

return result, nil
}
86 changes: 86 additions & 0 deletions cmd/internal/flowmode/cmd_convert_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package flowmode

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestParseExtraArgs(t *testing.T) {
type testCase struct {
name string
extraArgs string
expected []string
expectedError string
}

var testCases = []testCase{
{
name: "integrations next with env vars",
extraArgs: "-enable-features=integrations-next -config.expand-env",
expected: []string{"-enable-features", "integrations-next", "-config.expand-env"},
},
{
name: "longhand",
extraArgs: "--key=value",
expected: []string{"--key", "value"},
},
{
name: "shorthand",
extraArgs: "-k=value",
expected: []string{"-k", "value"},
},
{
name: "bool longhand",
extraArgs: "--boolVariable",
expected: []string{"--boolVariable"},
},
{
name: "bool shorthand",
extraArgs: "-b",
expected: []string{"-b"},
},
{
name: "combo",
extraArgs: "--key=value -k=value --boolVariable -b",
expected: []string{"--key", "value", "-k", "value", "--boolVariable", "-b"},
},
{
name: "spaced",
extraArgs: "--key value",
expected: []string{"--key", "value"},
},
{
name: "value with equals",
extraArgs: `--key="foo=bar"`,
expected: []string{"--key", `"foo=bar"`},
},
{
name: "no value",
extraArgs: "--key=",
expected: []string{"--key"},
},
{
name: "no dashes",
extraArgs: "key",
expected: []string{"key"},
},
{
name: "no dashes with value",
extraArgs: "key=value",
expectedError: "invalid flag found: key=value",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
res, err := parseExtraArgs(tc.extraArgs)
if tc.expectedError != "" {
require.EqualError(t, err, tc.expectedError)
return
}
require.NoError(t, err)
require.Equal(t, tc.expected, res)
})
}
}
11 changes: 8 additions & 3 deletions cmd/internal/flowmode/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ depending on the nature of the reload error.
BoolVar(&r.disableReporting, "disable-reporting", r.disableReporting, "Disable reporting of enabled components to Grafana.")
cmd.Flags().StringVar(&r.configFormat, "config.format", r.configFormat, fmt.Sprintf("The format of the source file. Supported formats: %s.", supportedFormatsList()))
cmd.Flags().BoolVar(&r.configBypassConversionErrors, "config.bypass-conversion-errors", r.configBypassConversionErrors, "Enable bypassing errors when converting")
cmd.Flags().StringVar(&r.configExtraArgs, "config.extra-args", r.configExtraArgs, "Extra arguments from the original format used by the converter")
cmd.Flags().StringVar(&r.configExtraArgs, "config.extra-args", r.configExtraArgs, "Extra arguments from the original format used by the converter. Multiple arguments can be passed by separating them with a space.")
return cmd
}

Expand Down Expand Up @@ -247,7 +247,7 @@ func (fr *flowRun) Run(configPath string) error {
return fmt.Errorf("failed to create otel service")
}

labelService := labelstore.New(l)
labelService := labelstore.New(l, reg)

f := flow.New(flow.Options{
Logger: l,
Expand Down Expand Up @@ -405,7 +405,12 @@ func loadFlowSource(path string, converterSourceFormat string, converterBypassEr
}
if converterSourceFormat != "flow" {
var diags convert_diag.Diagnostics
bb, diags = converter.Convert(bb, converter.Input(converterSourceFormat), parseExtraArgs(configExtraArgs))
ea, err := parseExtraArgs(configExtraArgs)
if err != nil {
return nil, err
}

bb, diags = converter.Convert(bb, converter.Input(converterSourceFormat), ea)
hasError := hasErrorLevel(diags, convert_diag.SeverityLevelError)
hasCritical := hasErrorLevel(diags, convert_diag.SeverityLevelCritical)
if hasCritical || (!converterBypassErrors && hasError) {
Expand Down
Loading

0 comments on commit 0d21490

Please sign in to comment.