Skip to content

Commit b69d948

Browse files
mergify[bot]michalpristasandrzej-stencel
authored
[8.14](backport #4908) Added k8s components to otel distribution (#4978)
* Added k8s components to otel distribution (#4908) (cherry picked from commit 6b78791) # Conflicts: # NOTICE.txt # go.mod # go.sum # internal/pkg/agent/cmd/common.go # internal/pkg/otel/README.md # internal/pkg/otel/components.go # internal/pkg/otel/run_test.go # internal/pkg/otel/testdata/all-components.yml * conflicts * resolved conflict with 8.14 branch * remove 8.15 commands * missing file --------- Co-authored-by: Michal Pristas <michal.pristas@gmail.com> Co-authored-by: Andrzej Stencel <andrzej.stencel@elastic.co>
1 parent e63611c commit b69d948

23 files changed

+11230
-7225
lines changed

NOTICE.txt

+10,600-6,946
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: feature
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Makes the `elasticinframetrics` processor available to users running Elastic Agent in `otel` mode.
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
22+
component: elastic-agent
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
#pr: https://github.com/owner/repo/1234
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
#issue: https://github.com/owner/repo/1234

go.mod

+92-78
Large diffs are not rendered by default.

go.sum

+210-162
Large diffs are not rendered by default.

internal/pkg/agent/cmd/cmd_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ package cmd
66

77
import (
88
"testing"
9+
10+
"github.com/spf13/cobra"
11+
"github.com/stretchr/testify/require"
912
)
1013

1114
func TestAgent(t *testing.T) {
@@ -30,3 +33,18 @@ func TestAgent(t *testing.T) {
3033
// assert.True(t, strings.Contains(string(contents), "Hello I am running"))
3134
// })
3235
}
36+
37+
func TestAddCommandIfNotNil(t *testing.T) {
38+
cmd := &cobra.Command{}
39+
40+
parent := &cobra.Command{}
41+
addCommandIfNotNil(parent, cmd)
42+
require.Equal(t, 1, len(parent.Commands()))
43+
44+
parent = &cobra.Command{}
45+
addCommandIfNotNil(parent, nil)
46+
require.Equal(t, 0, len(parent.Commands()))
47+
48+
// this should not panic
49+
addCommandIfNotNil(nil, cmd)
50+
}

internal/pkg/agent/cmd/common.go

+21-12
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,19 @@ func NewCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command {
7272
run := newRunCommandWithArgs(args, streams)
7373
cmd.AddCommand(basecmd.NewDefaultCommandsWithArgs(args, streams)...)
7474
cmd.AddCommand(run)
75-
cmd.AddCommand(newInstallCommandWithArgs(args, streams))
76-
cmd.AddCommand(newUninstallCommandWithArgs(args, streams))
77-
cmd.AddCommand(newUpgradeCommandWithArgs(args, streams))
78-
cmd.AddCommand(newEnrollCommandWithArgs(args, streams))
79-
cmd.AddCommand(newInspectCommandWithArgs(args, streams))
80-
cmd.AddCommand(newWatchCommandWithArgs(args, streams))
81-
cmd.AddCommand(newContainerCommand(args, streams))
82-
cmd.AddCommand(newStatusCommand(args, streams))
83-
cmd.AddCommand(newDiagnosticsCommand(args, streams))
84-
cmd.AddCommand(newComponentCommandWithArgs(args, streams))
85-
cmd.AddCommand(newLogsCommandWithArgs(args, streams))
86-
cmd.AddCommand(newOtelCommandWithArgs(args, streams))
75+
76+
addCommandIfNotNil(cmd, newInstallCommandWithArgs(args, streams))
77+
addCommandIfNotNil(cmd, newUninstallCommandWithArgs(args, streams))
78+
addCommandIfNotNil(cmd, newUpgradeCommandWithArgs(args, streams))
79+
addCommandIfNotNil(cmd, newEnrollCommandWithArgs(args, streams))
80+
addCommandIfNotNil(cmd, newInspectCommandWithArgs(args, streams))
81+
addCommandIfNotNil(cmd, newWatchCommandWithArgs(args, streams))
82+
addCommandIfNotNil(cmd, newContainerCommand(args, streams))
83+
addCommandIfNotNil(cmd, newStatusCommand(args, streams))
84+
addCommandIfNotNil(cmd, newDiagnosticsCommand(args, streams))
85+
addCommandIfNotNil(cmd, newComponentCommandWithArgs(args, streams))
86+
addCommandIfNotNil(cmd, newLogsCommandWithArgs(args, streams))
87+
addCommandIfNotNil(cmd, newOtelCommandWithArgs(args, streams))
8788

8889
// windows special hidden sub-command (only added on Windows)
8990
reexec := newReExecWindowsCommand(args, streams)
@@ -95,3 +96,11 @@ func NewCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command {
9596

9697
return cmd
9798
}
99+
100+
func addCommandIfNotNil(parent, cmd *cobra.Command) {
101+
if cmd == nil || parent == nil {
102+
return
103+
}
104+
105+
parent.AddCommand(cmd)
106+
}

internal/pkg/agent/cmd/otel.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// or more contributor license agreements. Licensed under the Elastic License;
33
// you may not use this file except in compliance with the Elastic License.
44

5+
//go:build !windows
6+
57
package cmd
68

79
import (
@@ -18,11 +20,6 @@ import (
1820
"github.com/elastic/elastic-agent/internal/pkg/otel"
1921
)
2022

21-
const (
22-
configFlagName = "config"
23-
setFlagName = "set"
24-
)
25-
2623
func newOtelCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command {
2724
cmd := &cobra.Command{
2825
Use: "otel",

internal/pkg/agent/cmd/otel_flags.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// or more contributor license agreements. Licensed under the Elastic License;
33
// you may not use this file except in compliance with the Elastic License.
44

5+
//go:build !windows
6+
57
package cmd
68

79
import (
@@ -16,11 +18,16 @@ import (
1618
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
1719
)
1820

21+
const (
22+
otelConfigFlagName = "config"
23+
otelSetFlagName = "set"
24+
)
25+
1926
func setupOtelFlags(flags *pflag.FlagSet) {
20-
flags.StringArray(configFlagName, []string{}, "Locations to the config file(s), note that only a"+
27+
flags.StringArray(otelConfigFlagName, []string{}, "Locations to the config file(s), note that only a"+
2128
" single location can be set per flag entry e.g. `--config=file:/path/to/first --config=file:path/to/second`.")
2229

23-
flags.StringArray(setFlagName, []string{}, "Set arbitrary component config property. The component has to be defined in the config file and the flag"+
30+
flags.StringArray(otelSetFlagName, []string{}, "Set arbitrary component config property. The component has to be defined in the config file and the flag"+
2431
" has a higher precedence. Array config properties are overridden and maps are joined. Example --set=processors.batch.timeout=2s")
2532

2633
goFlags := new(flag.FlagSet)
@@ -30,7 +37,7 @@ func setupOtelFlags(flags *pflag.FlagSet) {
3037
}
3138

3239
func getConfigFiles(cmd *cobra.Command, useDefault bool) ([]string, error) {
33-
configFiles, err := cmd.Flags().GetStringArray(configFlagName)
40+
configFiles, err := cmd.Flags().GetStringArray(otelConfigFlagName)
3441
if err != nil {
3542
return nil, fmt.Errorf("failed to retrieve config flags: %w", err)
3643
}
@@ -42,7 +49,7 @@ func getConfigFiles(cmd *cobra.Command, useDefault bool) ([]string, error) {
4249
configFiles = append(configFiles, paths.OtelConfigFile())
4350
}
4451

45-
setVals, err := cmd.Flags().GetStringArray(setFlagName)
52+
setVals, err := cmd.Flags().GetStringArray(otelSetFlagName)
4653
if err != nil {
4754
return nil, fmt.Errorf("failed to retrieve set flags: %w", err)
4855
}

internal/pkg/agent/cmd/otel_flags_test.go

+43-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// or more contributor license agreements. Licensed under the Elastic License;
33
// you may not use this file except in compliance with the Elastic License.
44

5+
//go:build !windows
6+
57
package cmd
68

79
import (
@@ -10,15 +12,17 @@ import (
1012
"github.com/spf13/pflag"
1113
"github.com/stretchr/testify/assert"
1214
"github.com/stretchr/testify/require"
15+
16+
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
1317
)
1418

1519
func TestOtelFlagsSetup(t *testing.T) {
1620
fs := new(pflag.FlagSet)
1721
setupOtelFlags(fs)
1822

1923
expectedFlags := []string{
20-
configFlagName,
21-
setFlagName,
24+
otelConfigFlagName,
25+
otelSetFlagName,
2226
"feature-gates",
2327
}
2428

@@ -27,6 +31,43 @@ func TestOtelFlagsSetup(t *testing.T) {
2731
}
2832
}
2933

34+
func TestGetConfigFiles(t *testing.T) {
35+
cmd := newOtelCommandWithArgs(nil, nil)
36+
configFile := "sample.yaml"
37+
require.NoError(t, cmd.Flag(otelConfigFlagName).Value.Set(configFile))
38+
39+
setVal := "set=val"
40+
sets, err := getSets([]string{setVal})
41+
require.NoError(t, err)
42+
require.NoError(t, cmd.Flag(otelSetFlagName).Value.Set(setVal))
43+
44+
expectedConfigFiles := append([]string{configFile}, sets...)
45+
configFiles, err := getConfigFiles(cmd, false)
46+
require.NoError(t, err)
47+
require.Equal(t, expectedConfigFiles, configFiles)
48+
}
49+
50+
func TestGetConfigFilesWithDefault(t *testing.T) {
51+
cmd := newOtelCommandWithArgs(nil, nil)
52+
53+
setVal := "set=val"
54+
sets, err := getSets([]string{setVal})
55+
require.NoError(t, err)
56+
require.NoError(t, cmd.Flag(otelSetFlagName).Value.Set(setVal))
57+
58+
expectedConfigFiles := append([]string{paths.OtelConfigFile()}, sets...)
59+
configFiles, err := getConfigFiles(cmd, true)
60+
require.NoError(t, err)
61+
require.Equal(t, expectedConfigFiles, configFiles)
62+
}
63+
64+
func TestGetConfigErrorWhenNoConfig(t *testing.T) {
65+
cmd := newOtelCommandWithArgs(nil, nil)
66+
67+
_, err := getConfigFiles(cmd, false)
68+
require.Error(t, err)
69+
}
70+
3071
func TestGetSets(t *testing.T) {
3172
testCases := []struct {
3273
name string
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License;
3+
// you may not use this file except in compliance with the Elastic License.
4+
5+
//go:build windows
6+
7+
package cmd
8+
9+
import (
10+
"github.com/spf13/cobra"
11+
12+
"github.com/elastic/elastic-agent/internal/pkg/cli"
13+
)
14+
15+
func newOtelCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command {
16+
return nil
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License;
3+
// you may not use this file except in compliance with the Elastic License.
4+
5+
//go:build windows
6+
7+
package cmd
8+
9+
import (
10+
"testing"
11+
12+
"github.com/stretchr/testify/require"
13+
)
14+
15+
func TestOtelCommandIsNil(t *testing.T) {
16+
require.Nil(t, newOtelCommandWithArgs(nil, nil))
17+
}

internal/pkg/agent/cmd/validate.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// or more contributor license agreements. Licensed under the Elastic License;
33
// you may not use this file except in compliance with the Elastic License.
44

5+
//go:build !windows
6+
57
package cmd
68

79
import (

internal/pkg/agent/cmd/validate_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// or more contributor license agreements. Licensed under the Elastic License;
33
// you may not use this file except in compliance with the Elastic License.
44

5+
//go:build !windows
6+
57
package cmd
68

79
import (

internal/pkg/otel/README.md

+19-14
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ This section provides a summary of components included in the Elastic Distributi
3131

3232
| Component | Version |
3333
|---|---|
34-
| filelogreceiver | v0.102.0|
35-
| otlpreceiver | v0.102.1|
34+
| filelogreceiver | v0.103.0|
35+
| hostmetricsreceiver | v0.103.0|
36+
| k8sclusterreceiver | v0.103.0|
37+
| kubeletstatsreceiver | v0.103.0|
38+
| otlpreceiver | v0.103.0|
3639

3740

3841

@@ -41,10 +44,10 @@ This section provides a summary of components included in the Elastic Distributi
4144

4245
| Component | Version |
4346
|---|---|
44-
| elasticsearchexporter | v0.102.0|
45-
| fileexporter | v0.102.0|
46-
| debugexporter | v0.102.1|
47-
| otlpexporter | v0.102.1|
47+
| elasticsearchexporter | v0.103.0|
48+
| fileexporter | v0.103.0|
49+
| debugexporter | v0.103.0|
50+
| otlpexporter | v0.103.0|
4851

4952

5053

@@ -53,13 +56,14 @@ This section provides a summary of components included in the Elastic Distributi
5356

5457
| Component | Version |
5558
|---|---|
56-
| attributesprocessor | v0.102.0|
57-
| filterprocessor | v0.102.0|
58-
| k8sattributesprocessor | v0.102.0|
59-
| resourcedetectionprocessor | v0.102.0|
60-
| resourceprocessor | v0.102.0|
61-
| transformprocessor | v0.102.0|
62-
| batchprocessor | v0.102.1|
59+
| elasticinframetricsprocessor | v0.2.0|
60+
| attributesprocessor | v0.103.0|
61+
| filterprocessor | v0.103.0|
62+
| k8sattributesprocessor | v0.103.0|
63+
| resourcedetectionprocessor | v0.103.0|
64+
| resourceprocessor | v0.103.0|
65+
| transformprocessor | v0.103.0|
66+
| batchprocessor | v0.103.0|
6367

6468

6569

@@ -68,5 +72,6 @@ This section provides a summary of components included in the Elastic Distributi
6872

6973
| Component | Version |
7074
|---|---|
71-
| memorylimiterextension | v0.102.1|
75+
| storage/filestorage | v0.103.0|
76+
| memorylimiterextension | v0.103.0|
7277

0 commit comments

Comments
 (0)