Skip to content

Commit 71fcfb7

Browse files
ChrsMarkandrzej-stencel
authored andcommitted
Add otel components command (#6539)
* Add otel components command Signed-off-by: ChrsMark <chrismarkou92@gmail.com> * fixes and test addition Signed-off-by: ChrsMark <chrismarkou92@gmail.com> * add note about components command in README Signed-off-by: ChrsMark <chrismarkou92@gmail.com> * fix fmt Signed-off-by: ChrsMark <chrismarkou92@gmail.com> --------- Signed-off-by: ChrsMark <chrismarkou92@gmail.com> Co-authored-by: Andrzej Stencel <andrzej.stencel@elastic.co> (cherry picked from commit be4ee59)
1 parent 3d53265 commit 71fcfb7

File tree

8 files changed

+524
-8
lines changed

8 files changed

+524
-8
lines changed
Lines changed: 32 additions & 0 deletions
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: Add `components` command for `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
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 2.0;
3+
// you may not use this file except in compliance with the Elastic License 2.0.
4+
5+
package cmd
6+
7+
import (
8+
"github.com/spf13/cobra"
9+
10+
"github.com/elastic/elastic-agent/internal/pkg/cli"
11+
"github.com/elastic/elastic-agent/internal/pkg/otel"
12+
)
13+
14+
func newComponentsCommandWithArgs(_ []string, _ *cli.IOStreams) *cobra.Command {
15+
cmd := &cobra.Command{
16+
Use: "components",
17+
Short: "Outputs available components in this collector distribution",
18+
Long: "Outputs available components in this collector distribution including their stability levels. The output format is not stable and can change between releases.",
19+
SilenceUsage: true, // do not display usage on error
20+
SilenceErrors: true,
21+
RunE: func(cmd *cobra.Command, _ []string) error {
22+
return otel.Components(cmd)
23+
},
24+
}
25+
26+
setupOtelFlags(cmd.Flags())
27+
cmd.SetHelpFunc(func(c *cobra.Command, s []string) {
28+
hideInheritedFlags(c)
29+
c.Root().HelpFunc()(c, s)
30+
})
31+
32+
return cmd
33+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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 2.0;
3+
// you may not use this file except in compliance with the Elastic License 2.0.
4+
5+
package cmd
6+
7+
import (
8+
"bytes"
9+
"os"
10+
"path/filepath"
11+
"testing"
12+
13+
"gopkg.in/yaml.v3"
14+
15+
"github.com/spf13/cobra"
16+
"github.com/stretchr/testify/require"
17+
18+
"github.com/elastic/elastic-agent/internal/pkg/otel"
19+
)
20+
21+
type componentsOutput struct {
22+
Receivers []struct {
23+
Name string `yaml:"name"`
24+
} `yaml:"receivers"`
25+
Processors []struct {
26+
Name string `yaml:"name"`
27+
} `yaml:"processors"`
28+
Exporters []struct {
29+
Name string `yaml:"name"`
30+
} `yaml:"exporters"`
31+
Connectors []struct {
32+
Name string `yaml:"name"`
33+
} `yaml:"connectors"`
34+
Extensions []struct {
35+
Name string `yaml:"name"`
36+
} `yaml:"extensions"`
37+
}
38+
39+
func TestComponentsCommand(t *testing.T) {
40+
41+
cmd := &cobra.Command{}
42+
cmd.SetArgs([]string{"components"})
43+
44+
expectedOutput, err := os.ReadFile(filepath.Join("testdata", "otel/components-output.yml"))
45+
require.NoError(t, err)
46+
expectedComponents := &componentsOutput{}
47+
err = yaml.Unmarshal(expectedOutput, expectedComponents)
48+
require.NoError(t, err)
49+
50+
b := bytes.NewBufferString("")
51+
cmd.SetOut(b)
52+
err = otel.Components(cmd)
53+
require.NoError(t, err)
54+
outputComponents := &componentsOutput{}
55+
err = yaml.Unmarshal(b.Bytes(), outputComponents)
56+
require.NoError(t, err)
57+
58+
for _, receiver := range expectedComponents.Receivers {
59+
found := false
60+
for _, rcvr := range outputComponents.Receivers {
61+
if receiver.Name == rcvr.Name {
62+
found = true
63+
break
64+
}
65+
}
66+
require.Truef(t, found, "receiver not found: %s", receiver.Name)
67+
}
68+
for _, exporter := range expectedComponents.Exporters {
69+
found := false
70+
for _, exprt := range outputComponents.Exporters {
71+
if exporter.Name == exprt.Name {
72+
found = true
73+
break
74+
}
75+
}
76+
require.Truef(t, found, "exporter not found: %s", exporter.Name)
77+
}
78+
for _, processor := range expectedComponents.Processors {
79+
found := false
80+
for _, prcsr := range outputComponents.Processors {
81+
if processor.Name == prcsr.Name {
82+
found = true
83+
break
84+
}
85+
}
86+
require.Truef(t, found, "processor not found: %s", processor.Name)
87+
}
88+
for _, connector := range expectedComponents.Connectors {
89+
found := false
90+
for _, cnctr := range outputComponents.Connectors {
91+
if connector.Name == cnctr.Name {
92+
found = true
93+
break
94+
}
95+
}
96+
require.Truef(t, found, "connector not found: %s", connector.Name)
97+
}
98+
for _, extension := range expectedComponents.Extensions {
99+
found := false
100+
for _, ext := range outputComponents.Extensions {
101+
if extension.Name == ext.Name {
102+
found = true
103+
break
104+
}
105+
}
106+
require.Truef(t, found, "extension not found: %s", extension.Name)
107+
}
108+
}

internal/pkg/agent/cmd/otel.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func newOtelCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Comman
4646

4747
setupOtelFlags(cmd.Flags())
4848
cmd.AddCommand(newValidateCommandWithArgs(args, streams))
49+
cmd.AddCommand(newComponentsCommandWithArgs(args, streams))
4950

5051
return cmd
5152
}
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
buildinfo:
2+
command: ./build/elastic-agent
3+
description: Elastic opentelemetry-collector distribution
4+
version: 9.0.0
5+
receivers:
6+
- name: filebeatreceiver
7+
stability:
8+
logs: Alpha
9+
metrics: Undefined
10+
traces: Undefined
11+
- name: filelog
12+
stability:
13+
logs: Beta
14+
metrics: Undefined
15+
traces: Undefined
16+
- name: hostmetrics
17+
stability:
18+
logs: Development
19+
metrics: Beta
20+
traces: Undefined
21+
- name: httpcheck
22+
stability:
23+
logs: Undefined
24+
metrics: Alpha
25+
traces: Undefined
26+
- name: jaeger
27+
stability:
28+
logs: Undefined
29+
metrics: Undefined
30+
traces: Beta
31+
- name: k8s_cluster
32+
stability:
33+
logs: Beta
34+
metrics: Beta
35+
traces: Undefined
36+
- name: k8sobjects
37+
stability:
38+
logs: Beta
39+
metrics: Undefined
40+
traces: Undefined
41+
- name: kubeletstats
42+
stability:
43+
logs: Undefined
44+
metrics: Beta
45+
traces: Undefined
46+
- name: metricbeatreceiver
47+
stability:
48+
logs: Alpha
49+
metrics: Undefined
50+
traces: Undefined
51+
- name: otlp
52+
stability:
53+
logs: Beta
54+
metrics: Stable
55+
traces: Stable
56+
- name: prometheus
57+
stability:
58+
logs: Undefined
59+
metrics: Beta
60+
traces: Undefined
61+
- name: zipkin
62+
stability:
63+
logs: Undefined
64+
metrics: Undefined
65+
traces: Beta
66+
processors:
67+
- name: attributes
68+
stability:
69+
logs: Beta
70+
metrics: Beta
71+
traces: Beta
72+
- name: batch
73+
stability:
74+
logs: Beta
75+
metrics: Beta
76+
traces: Beta
77+
- name: elasticinframetrics
78+
stability:
79+
logs: Undefined
80+
metrics: Alpha
81+
traces: Undefined
82+
- name: elastictrace
83+
stability:
84+
logs: Undefined
85+
metrics: Undefined
86+
traces: Alpha
87+
- name: filter
88+
stability:
89+
logs: Alpha
90+
metrics: Alpha
91+
traces: Alpha
92+
- name: k8sattributes
93+
stability:
94+
logs: Beta
95+
metrics: Beta
96+
traces: Beta
97+
- name: lsminterval
98+
stability:
99+
logs: Undefined
100+
metrics: Development
101+
traces: Undefined
102+
- name: memory_limiter
103+
stability:
104+
logs: Beta
105+
metrics: Beta
106+
traces: Beta
107+
- name: resource
108+
stability:
109+
logs: Beta
110+
metrics: Beta
111+
traces: Beta
112+
- name: resourcedetection
113+
stability:
114+
logs: Beta
115+
metrics: Beta
116+
traces: Beta
117+
- name: transform
118+
stability:
119+
logs: Alpha
120+
metrics: Alpha
121+
traces: Alpha
122+
exporters:
123+
- name: debug
124+
stability:
125+
logs: Development
126+
metrics: Development
127+
traces: Development
128+
- name: elasticsearch
129+
stability:
130+
logs: Beta
131+
metrics: Development
132+
traces: Beta
133+
- name: file
134+
stability:
135+
logs: Alpha
136+
metrics: Alpha
137+
traces: Alpha
138+
- name: loadbalancing
139+
stability:
140+
logs: Beta
141+
metrics: Development
142+
traces: Beta
143+
- name: otlp
144+
stability:
145+
logs: Beta
146+
metrics: Stable
147+
traces: Stable
148+
- name: otlphttp
149+
stability:
150+
logs: Beta
151+
metrics: Stable
152+
traces: Stable
153+
connectors:
154+
- name: routing
155+
stability:
156+
logs-to-logs: Alpha
157+
logs-to-metrics: Undefined
158+
logs-to-traces: Undefined
159+
metrics-to-logs: Undefined
160+
metrics-to-metrics: Alpha
161+
metrics-to-traces: Undefined
162+
traces-to-logs: Undefined
163+
traces-to-metrics: Undefined
164+
traces-to-traces: Alpha
165+
- name: signaltometrics
166+
stability:
167+
logs-to-logs: Undefined
168+
logs-to-metrics: Alpha
169+
logs-to-traces: Undefined
170+
metrics-to-logs: Undefined
171+
metrics-to-metrics: Alpha
172+
metrics-to-traces: Undefined
173+
traces-to-logs: Undefined
174+
traces-to-metrics: Alpha
175+
traces-to-traces: Undefined
176+
- name: spanmetrics
177+
stability:
178+
logs-to-logs: Undefined
179+
logs-to-metrics: Undefined
180+
logs-to-traces: Undefined
181+
metrics-to-logs: Undefined
182+
metrics-to-metrics: Undefined
183+
metrics-to-traces: Undefined
184+
traces-to-logs: Undefined
185+
traces-to-metrics: Alpha
186+
traces-to-traces: Undefined
187+
extensions:
188+
- name: file_storage
189+
stability:
190+
extension: Beta
191+
- name: health_check
192+
stability:
193+
extension: Beta
194+
- name: memory_limiter
195+
stability:
196+
extension: Development
197+
- name: pprof
198+
stability:
199+
extension: Beta

0 commit comments

Comments
 (0)