Skip to content

Commit 55f5d4f

Browse files
committed
docs and comments
1 parent c577a9f commit 55f5d4f

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# elasticdiagnosticsextension
2+
3+
`elasticdiagnosticsextension` is an internal package for peforming diagnostics and is used in conjunction with EDOT:
4+
5+
## Features
6+
7+
- Acts as a registrar and keeps track of common diagnostic hooks.
8+
- Collects profiles using `runtime/pprof`.
9+
- Collects internal telemetry exposed by the OTeL Collector.
10+
- Implements the `extensioncapabilities.ConfigWatcher` interface and stores the latest configuration of the running collector.
11+
- Listens for diagnostic requests and provides diagnostic data.
12+
13+
## Design
14+
15+
### Diagnostic hooks:
16+
- Individual beats register custom diagnostic hooks and these hooks are called when we run the elastic-agent diagnostics command.
17+
- Our extension stores these hooks and executes them everytime it gets a "diagnostics" request.
18+
19+
### Request/Response format:
20+
- This extension runs an HTTP server and listens to new requests on `/diagnostics` path.
21+
- It doesn't expect any requets params or body.
22+
- The response format is defined in [response.go](./response.go).
23+
- `GlobalDiagnostics`: Data related to the overall process:
24+
1. Profiles.
25+
2. Internal telemetry.
26+
3. latest collector configuration.
27+
- `ComponentDiagnostics`: Data from individual receivers, collected via registered diagnostic hooks.
28+
29+
### Interaction with Elastic-Agent service in hybrid mode.
30+
31+
- When the user triggers the diagnostic request, EDOT diagnostics are injected at two levels:
32+
1. At top-Level:
33+
- When `DiagnosticAgent()` is called in [server.go](https://github.com/elastic/elastic-agent/blob/710c49f45433e2f136a6e41cae980c1aa37dabdd/pkg/control/v2/server/server.go#L197).
34+
- Diagnostics are captured at the global level and stored under the `edot/*` directory in the resulting ZIP archive.
35+
2. At component-level:
36+
- When `otelMgr.PerformComponentsDiagnostics()` is called in [coordinator.go](https://github.com/elastic/elastic-agent/blob/710c49f45433e2f136a6e41cae980c1aa37dabdd/internal/pkg/agent/application/coordinator/coordinator.go#L863).
37+
- Diagnostics are added per component and stored under the `components/{comp}/*` directory in the resulting ZIP archive.

internal/pkg/otel/elasticdiagnosticsextension/extension.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net"
1010
"net/http"
1111
"os"
12-
"runtime"
1312
"runtime/pprof"
1413
"strconv"
1514
"sync"
@@ -45,7 +44,9 @@ type diagnosticsExtension struct {
4544
collectorConfig *confmap.Conf
4645
componentHooks map[string][]*diagHook
4746
globalHooks map[string]*diagHook
48-
hooksMtx sync.Mutex
47+
48+
hooksMtx sync.Mutex
49+
confgMtx sync.Mutex
4950
}
5051

5152
type serviceConfig struct {
@@ -156,6 +157,8 @@ func (d *diagnosticsExtension) Shutdown(ctx context.Context) error {
156157
}
157158

158159
func (d *diagnosticsExtension) NotifyConfig(ctx context.Context, conf *confmap.Conf) error {
160+
d.confgMtx.Lock()
161+
defer d.confgMtx.Unlock()
159162
d.collectorConfig = conf
160163
return nil
161164
}
@@ -237,12 +240,3 @@ func extractMetricAddress(readers []otelconf.MetricReader) string {
237240
}
238241
return ""
239242
}
240-
241-
func changeOwner(path string, uid, gid int) error {
242-
if runtime.GOOS == "windows" {
243-
// on windows it always returns the syscall.EWINDOWS error, wrapped in *PathError
244-
return nil
245-
}
246-
247-
return os.Chown(path, uid, gid)
248-
}

internal/pkg/otel/manager/diagnostics.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,14 @@ func (m *OTelManager) PerformComponentDiagnostics(
164164

165165
extDiagnostics, err := otel.PerformDiagnosticsExt()
166166
if errors.Is(err, syscall.ENOENT) || errors.Is(err, syscall.ECONNREFUSED) {
167+
// We're not running the EDOT if:
168+
// 1. Either the socket doesn't exist
169+
// 2. It is refusing the connections.
170+
m.logger.Debugf("Couldn't fetch diagnostics from EDOT: %v", err)
167171
return diagnostics, nil
168172
}
169173
if err != nil {
170-
m.logger.Errorf("error fetching diagnostics: %v", err)
171-
return nil, err
174+
return nil, fmt.Errorf("error fetching otel diagnostics: %w", err)
172175
}
173176

174177
for idx, diag := range diagnostics {

0 commit comments

Comments
 (0)