Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.14](backport #4908) Added k8s components to otel distribution #4978

Merged
merged 6 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17,546 changes: 10,600 additions & 6,946 deletions NOTICE.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: feature

# Change summary; a 80ish characters long description of the change.
summary: Makes the `elasticinframetrics` processor available to users running Elastic Agent in `otel` mode.

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
component: elastic-agent

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: https://github.com/owner/repo/1234

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
#issue: https://github.com/owner/repo/1234
170 changes: 92 additions & 78 deletions go.mod

Large diffs are not rendered by default.

372 changes: 210 additions & 162 deletions go.sum

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions internal/pkg/agent/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package cmd

import (
"testing"

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

func TestAgent(t *testing.T) {
Expand All @@ -30,3 +33,18 @@ func TestAgent(t *testing.T) {
// assert.True(t, strings.Contains(string(contents), "Hello I am running"))
// })
}

func TestAddCommandIfNotNil(t *testing.T) {
cmd := &cobra.Command{}

parent := &cobra.Command{}
addCommandIfNotNil(parent, cmd)
require.Equal(t, 1, len(parent.Commands()))

parent = &cobra.Command{}
addCommandIfNotNil(parent, nil)
require.Equal(t, 0, len(parent.Commands()))

// this should not panic
addCommandIfNotNil(nil, cmd)
}
33 changes: 21 additions & 12 deletions internal/pkg/agent/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,19 @@ func NewCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command {
run := newRunCommandWithArgs(args, streams)
cmd.AddCommand(basecmd.NewDefaultCommandsWithArgs(args, streams)...)
cmd.AddCommand(run)
cmd.AddCommand(newInstallCommandWithArgs(args, streams))
cmd.AddCommand(newUninstallCommandWithArgs(args, streams))
cmd.AddCommand(newUpgradeCommandWithArgs(args, streams))
cmd.AddCommand(newEnrollCommandWithArgs(args, streams))
cmd.AddCommand(newInspectCommandWithArgs(args, streams))
cmd.AddCommand(newWatchCommandWithArgs(args, streams))
cmd.AddCommand(newContainerCommand(args, streams))
cmd.AddCommand(newStatusCommand(args, streams))
cmd.AddCommand(newDiagnosticsCommand(args, streams))
cmd.AddCommand(newComponentCommandWithArgs(args, streams))
cmd.AddCommand(newLogsCommandWithArgs(args, streams))
cmd.AddCommand(newOtelCommandWithArgs(args, streams))

addCommandIfNotNil(cmd, newInstallCommandWithArgs(args, streams))
addCommandIfNotNil(cmd, newUninstallCommandWithArgs(args, streams))
addCommandIfNotNil(cmd, newUpgradeCommandWithArgs(args, streams))
addCommandIfNotNil(cmd, newEnrollCommandWithArgs(args, streams))
addCommandIfNotNil(cmd, newInspectCommandWithArgs(args, streams))
addCommandIfNotNil(cmd, newWatchCommandWithArgs(args, streams))
addCommandIfNotNil(cmd, newContainerCommand(args, streams))
addCommandIfNotNil(cmd, newStatusCommand(args, streams))
addCommandIfNotNil(cmd, newDiagnosticsCommand(args, streams))
addCommandIfNotNil(cmd, newComponentCommandWithArgs(args, streams))
addCommandIfNotNil(cmd, newLogsCommandWithArgs(args, streams))
addCommandIfNotNil(cmd, newOtelCommandWithArgs(args, streams))

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

return cmd
}

func addCommandIfNotNil(parent, cmd *cobra.Command) {
if cmd == nil || parent == nil {
return
}

parent.AddCommand(cmd)
}
7 changes: 2 additions & 5 deletions internal/pkg/agent/cmd/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package cmd

import (
Expand All @@ -18,11 +20,6 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/otel"
)

const (
configFlagName = "config"
setFlagName = "set"
)

func newOtelCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "otel",
Expand Down
15 changes: 11 additions & 4 deletions internal/pkg/agent/cmd/otel_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package cmd

import (
Expand All @@ -16,11 +18,16 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
)

const (
otelConfigFlagName = "config"
otelSetFlagName = "set"
)

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

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

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

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

setVals, err := cmd.Flags().GetStringArray(setFlagName)
setVals, err := cmd.Flags().GetStringArray(otelSetFlagName)
if err != nil {
return nil, fmt.Errorf("failed to retrieve set flags: %w", err)
}
Expand Down
45 changes: 43 additions & 2 deletions internal/pkg/agent/cmd/otel_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package cmd

import (
Expand All @@ -10,15 +12,17 @@ import (
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
)

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

expectedFlags := []string{
configFlagName,
setFlagName,
otelConfigFlagName,
otelSetFlagName,
"feature-gates",
}

Expand All @@ -27,6 +31,43 @@ func TestOtelFlagsSetup(t *testing.T) {
}
}

func TestGetConfigFiles(t *testing.T) {
cmd := newOtelCommandWithArgs(nil, nil)
configFile := "sample.yaml"
require.NoError(t, cmd.Flag(otelConfigFlagName).Value.Set(configFile))

setVal := "set=val"
sets, err := getSets([]string{setVal})
require.NoError(t, err)
require.NoError(t, cmd.Flag(otelSetFlagName).Value.Set(setVal))

expectedConfigFiles := append([]string{configFile}, sets...)
configFiles, err := getConfigFiles(cmd, false)
require.NoError(t, err)
require.Equal(t, expectedConfigFiles, configFiles)
}

func TestGetConfigFilesWithDefault(t *testing.T) {
cmd := newOtelCommandWithArgs(nil, nil)

setVal := "set=val"
sets, err := getSets([]string{setVal})
require.NoError(t, err)
require.NoError(t, cmd.Flag(otelSetFlagName).Value.Set(setVal))

expectedConfigFiles := append([]string{paths.OtelConfigFile()}, sets...)
configFiles, err := getConfigFiles(cmd, true)
require.NoError(t, err)
require.Equal(t, expectedConfigFiles, configFiles)
}

func TestGetConfigErrorWhenNoConfig(t *testing.T) {
cmd := newOtelCommandWithArgs(nil, nil)

_, err := getConfigFiles(cmd, false)
require.Error(t, err)
}

func TestGetSets(t *testing.T) {
testCases := []struct {
name string
Expand Down
17 changes: 17 additions & 0 deletions internal/pkg/agent/cmd/otel_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build windows

package cmd

import (
"github.com/spf13/cobra"

"github.com/elastic/elastic-agent/internal/pkg/cli"
)

func newOtelCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command {
return nil
}
17 changes: 17 additions & 0 deletions internal/pkg/agent/cmd/otel_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build windows

package cmd

import (
"testing"

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

func TestOtelCommandIsNil(t *testing.T) {
require.Nil(t, newOtelCommandWithArgs(nil, nil))
}
2 changes: 2 additions & 0 deletions internal/pkg/agent/cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package cmd

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/agent/cmd/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//go:build !windows

package cmd

import (
Expand Down
33 changes: 19 additions & 14 deletions internal/pkg/otel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ This section provides a summary of components included in the Elastic Distributi

| Component | Version |
|---|---|
| filelogreceiver | v0.102.0|
| otlpreceiver | v0.102.1|
| filelogreceiver | v0.103.0|
| hostmetricsreceiver | v0.103.0|
| k8sclusterreceiver | v0.103.0|
| kubeletstatsreceiver | v0.103.0|
| otlpreceiver | v0.103.0|



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

| Component | Version |
|---|---|
| elasticsearchexporter | v0.102.0|
| fileexporter | v0.102.0|
| debugexporter | v0.102.1|
| otlpexporter | v0.102.1|
| elasticsearchexporter | v0.103.0|
| fileexporter | v0.103.0|
| debugexporter | v0.103.0|
| otlpexporter | v0.103.0|



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

| Component | Version |
|---|---|
| attributesprocessor | v0.102.0|
| filterprocessor | v0.102.0|
| k8sattributesprocessor | v0.102.0|
| resourcedetectionprocessor | v0.102.0|
| resourceprocessor | v0.102.0|
| transformprocessor | v0.102.0|
| batchprocessor | v0.102.1|
| elasticinframetricsprocessor | v0.2.0|
| attributesprocessor | v0.103.0|
| filterprocessor | v0.103.0|
| k8sattributesprocessor | v0.103.0|
| resourcedetectionprocessor | v0.103.0|
| resourceprocessor | v0.103.0|
| transformprocessor | v0.103.0|
| batchprocessor | v0.103.0|



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

| Component | Version |
|---|---|
| memorylimiterextension | v0.102.1|
| storage/filestorage | v0.103.0|
| memorylimiterextension | v0.103.0|

Loading
Loading