-
Notifications
You must be signed in to change notification settings - Fork 195
[otel] Implement EDOT diagnostics extension #10052
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
Merged
Merged
Changes from all commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
a6d9cc6
edot diagnostics
VihasMakwana d0ac8ef
revert otel.yml
VihasMakwana 26ffcc1
add for supervised
VihasMakwana 351576b
cleanup
VihasMakwana f43056b
more fixes
VihasMakwana c577a9f
spelling and comments
VihasMakwana 55f5d4f
docs and comments
VihasMakwana e4748bd
test case
VihasMakwana 0505bb5
diagram
VihasMakwana 0a2d4f8
Merge branch 'main' into edot-diagnostics
VihasMakwana e40eb22
fix test
VihasMakwana 8540565
fix CI
VihasMakwana 7122db9
cleanup and npipe
VihasMakwana 648e6d8
comments
VihasMakwana 27c79fd
rename
VihasMakwana 9c3b7d8
Merge branch 'main' into edot-diagnostics
VihasMakwana f42929e
go.mod and notice
VihasMakwana a168b5a
go.mod and notice
VihasMakwana dcd4b41
restore otel-merged.yaml
VihasMakwana 7adba49
refactor ZipArchiveEDOT
VihasMakwana ddc4822
checkci
VihasMakwana 144c806
license
VihasMakwana 1eaf1ae
initial commit
VihasMakwana 2ab3171
timeout
VihasMakwana e670fa1
fix tests
VihasMakwana acc4b0b
fix tests
VihasMakwana 7ecb4d8
comments
VihasMakwana b60459e
error handling
VihasMakwana cdb3684
lint
VihasMakwana 0069ae6
test case
VihasMakwana 2031093
readme
VihasMakwana 65d9080
gofmt
VihasMakwana e30ec8c
remove println
VihasMakwana 8e32595
test
VihasMakwana 1cdf78a
add cpu profile
VihasMakwana 6abeca1
remove telemetry for now.
VihasMakwana e34f760
Merge branch 'main' into edot-extension-only
VihasMakwana 82062b8
remove redundant code
VihasMakwana 84c55b0
doc
VihasMakwana cb18e45
fix npipe
VihasMakwana 12d114c
Update internal/pkg/otel/extension/elasticdiagnostics/extension.go
VihasMakwana 3c59f14
readme
VihasMakwana 09f543d
readme
VihasMakwana cc9731a
Merge branch 'main' into edot-diagnostics
VihasMakwana a281488
Merge branch 'edot-extension-only' into edot-diagnostics
VihasMakwana ea8e734
Update internal/pkg/otel/extension/elasticdiagnostics/extension.go
VihasMakwana 4a337c6
mutex
VihasMakwana b7f88e1
Merge branch 'main' into edot-extension-only
VihasMakwana c0ac15d
comments
VihasMakwana 2d87ba0
Update generated_component_test.go
VihasMakwana 848f2e6
Update generated_component_test.go
VihasMakwana a7f947d
comments
VihasMakwana 36f37fe
test thorough
VihasMakwana 050580a
use eventuallyWith
VihasMakwana 559ba60
update go.mod and notice
VihasMakwana 4eca3ba
Merge branch 'edot-extension-only' into edot-diagnostics
VihasMakwana 4d8212a
add cpu
VihasMakwana b377c31
comment
VihasMakwana d40ca9c
Merge branch 'main' into edot-diagnostics
VihasMakwana 71b2669
test
VihasMakwana f0d4b4c
Merge branch 'main' into edot-diagnostics
VihasMakwana be617fb
fix test
VihasMakwana 97bad15
lint
VihasMakwana ccfff1d
lint
VihasMakwana 0cef9d5
test
VihasMakwana 420f379
comments
VihasMakwana dd87904
cleanup
VihasMakwana 710c642
comments
VihasMakwana 51808e4
fix test
VihasMakwana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
// you may not use this file except in compliance with the Elastic License 2.0. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" | ||
"github.com/elastic/elastic-agent/internal/pkg/cli" | ||
"github.com/elastic/elastic-agent/internal/pkg/diagnostics" | ||
"github.com/elastic/elastic-agent/internal/pkg/otel" | ||
"github.com/elastic/elastic-agent/pkg/control/v2/client" | ||
) | ||
|
||
func newOtelDiagnosticsCommand(streams *cli.IOStreams) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "diagnostics", | ||
Short: "Gather diagnostics information from the EDOT and write it to a zip archive", | ||
Long: "This command gathers diagnostics information from the EDOT and writes it to a zip archive", | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
if err := otelDiagnosticCmd(streams, cmd); err != nil { | ||
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) | ||
os.Exit(1) | ||
} | ||
return nil | ||
}, | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
} | ||
cmd.Flags().StringP("file", "f", "", "name of the output diagnostics zip archive") | ||
cmd.Flags().BoolP("cpu-profile", "p", false, "wait to collect a CPU profile") | ||
return cmd | ||
} | ||
|
||
func otelDiagnosticCmd(streams *cli.IOStreams, cmd *cobra.Command) error { | ||
cpuProfile, _ := cmd.Flags().GetBool("cpu-profile") | ||
resp, err := otel.PerformDiagnosticsExt(cmd.Context(), cpuProfile) | ||
if err != nil { | ||
return fmt.Errorf("failed to get edot diagnostics: %w", err) | ||
} | ||
|
||
agentDiag := make([]client.DiagnosticFileResult, 0) | ||
for _, r := range resp.GlobalDiagnostics { | ||
agentDiag = append(agentDiag, client.DiagnosticFileResult{ | ||
Name: r.Name, | ||
Filename: r.Filename, | ||
ContentType: r.ContentType, | ||
Content: r.Content, | ||
Description: r.Description, | ||
}) | ||
} | ||
|
||
componentDiag := make([]client.DiagnosticComponentResult, 0) | ||
for _, r := range resp.ComponentDiagnostics { | ||
res := client.DiagnosticComponentResult{ | ||
Results: make([]client.DiagnosticFileResult, 0), | ||
} | ||
res.Results = append(res.Results, client.DiagnosticFileResult{ | ||
Name: r.Name, | ||
Filename: r.Filename, | ||
ContentType: r.ContentType, | ||
Content: r.Content, | ||
Description: r.Description, | ||
}) | ||
res.ComponentID = r.Name | ||
componentDiag = append(componentDiag, res) | ||
} | ||
componentDiag = aggregateComponentDiagnostics(componentDiag) | ||
|
||
filepath, _ := cmd.Flags().GetString("file") | ||
if filepath == "" { | ||
ts := time.Now().UTC() | ||
filepath = "edot-diagnostics-" + ts.Format("2006-01-02T15-04-05Z07-00") + ".zip" // RFC3339 format that replaces : with -, so it will work on Windows | ||
} | ||
f, err := createFile(filepath) | ||
if err != nil { | ||
return fmt.Errorf("could not create diagnostics file %q: %w", filepath, err) | ||
} | ||
defer f.Close() | ||
|
||
// In EDOT, the logs path does not exist, so we ignore that error. | ||
if err := diagnostics.ZipArchive(streams.Err, f, paths.Top(), agentDiag, nil, componentDiag, false); err != nil && !os.IsNotExist(err) { | ||
return fmt.Errorf("unable to create archive %q: %w", filepath, err) | ||
} | ||
fmt.Fprintf(streams.Out, "Created diagnostics archive %q\n", filepath) | ||
fmt.Fprintln(streams.Out, "** WARNING **\nCreated archive may contain plain text credentials.\nEnsure that files in archive are redacted before sharing.\n*******") | ||
return nil | ||
} | ||
|
||
// aggregateComponentDiagnostics takes a slice of DiagnosticComponentResult and merges | ||
// results for components with the same ComponentID. | ||
func aggregateComponentDiagnostics(diags []client.DiagnosticComponentResult) []client.DiagnosticComponentResult { | ||
m := make(map[string]client.DiagnosticComponentResult) | ||
for _, d := range diags { | ||
if existing, ok := m[d.ComponentID]; ok { | ||
existing.Results = append(existing.Results, d.Results...) | ||
m[d.ComponentID] = existing | ||
} else { | ||
m[d.ComponentID] = d | ||
} | ||
} | ||
result := make([]client.DiagnosticComponentResult, 0, len(m)) | ||
for _, v := range m { | ||
result = append(result, v) | ||
} | ||
return result | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.