@@ -30,6 +30,7 @@ import (
30
30
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
31
31
"github.com/elastic/elastic-agent/internal/pkg/config"
32
32
monitoringCfg "github.com/elastic/elastic-agent/internal/pkg/core/monitoring/config"
33
+ otelMonitoring "github.com/elastic/elastic-agent/internal/pkg/otel/monitoring"
33
34
)
34
35
35
36
const (
@@ -58,7 +59,6 @@ const (
58
59
monitoringOutput = "monitoring"
59
60
defaultMonitoringNamespace = "default"
60
61
agentName = "elastic-agent"
61
- edotCollectorName = "elastic-agent/collector"
62
62
metricBeatName = "metricbeat"
63
63
fileBeatName = "filebeat"
64
64
@@ -74,9 +74,6 @@ const (
74
74
// metricset stream failure threshold before the stream is marked as DEGRADED
75
75
// to avoid marking the agent degraded for transient errors, we set the default threshold to 5
76
76
defaultMetricsStreamFailureThreshold = uint (5 )
77
-
78
- beatsMonitoringComponentInfoID = "beat/" + monitoringMetricsUnitID
79
- httpMonitoringComponentInfoID = "http/" + monitoringMetricsUnitID
80
77
)
81
78
82
79
var (
@@ -355,6 +352,16 @@ func (b *BeatsMonitor) Prepare(unit string) error {
355
352
return nil
356
353
}
357
354
355
+ // Returns true if any component in the list uses the otel runtime.
356
+ func usingOtelRuntime (componentInfos []componentInfo ) bool {
357
+ for _ , ci := range componentInfos {
358
+ if ci .RuntimeManager == component .OtelRuntimeManager {
359
+ return true
360
+ }
361
+ }
362
+ return false
363
+ }
364
+
358
365
// Cleanup removes files that were created for monitoring.
359
366
func (b * BeatsMonitor ) Cleanup (unit string ) error {
360
367
if ! b .Enabled () {
@@ -424,12 +431,12 @@ func (b *BeatsMonitor) getComponentInfos(components []component.Component, compo
424
431
if b .config .C .MonitorMetrics {
425
432
componentInfos = append (componentInfos ,
426
433
componentInfo {
427
- ID : beatsMonitoringComponentInfoID ,
434
+ ID : fmt . Sprintf ( "beat/%s" , monitoringMetricsUnitID ) ,
428
435
BinaryName : metricBeatName ,
429
436
RuntimeManager : component .RuntimeManager (b .config .C .RuntimeManager ),
430
437
},
431
438
componentInfo {
432
- ID : httpMonitoringComponentInfoID ,
439
+ ID : fmt . Sprintf ( "http/%s" , monitoringMetricsUnitID ) ,
433
440
BinaryName : metricBeatName ,
434
441
RuntimeManager : component .RuntimeManager (b .config .C .RuntimeManager ),
435
442
})
@@ -674,7 +681,27 @@ func (b *BeatsMonitor) getHttpStreams(
674
681
}
675
682
httpStreams = append (httpStreams , agentStream )
676
683
677
- var edotSubprocessEndpoints []interface {}
684
+ if usingOtelRuntime (componentInfos ) && b .isOtelRuntimeSubprocess {
685
+ edotSubprocessStream := map [string ]any {
686
+ idKey : fmt .Sprintf ("%s-edot-collector" , monitoringMetricsUnitID ),
687
+ "data_stream" : map [string ]interface {}{
688
+ "type" : "metrics" ,
689
+ "dataset" : dataset ,
690
+ "namespace" : monitoringNamespace ,
691
+ },
692
+ "metricsets" : []interface {}{"json" },
693
+ "path" : "/stats" ,
694
+ "hosts" : []interface {}{PrefixedEndpoint (otelMonitoring .EDOTMonitoringEndpoint ())},
695
+ "namespace" : "agent" ,
696
+ "period" : metricsCollectionIntervalString ,
697
+ "index" : indexName ,
698
+ "processors" : processorsForAgentHttpStream (agentName , otelMonitoring .EDOTComponentID , otelMonitoring .EDOTComponentID , monitoringNamespace , dataset , b .agentInfo ),
699
+ }
700
+ if failureThreshold != nil {
701
+ edotSubprocessStream [failureThresholdKey ] = * failureThreshold
702
+ }
703
+ httpStreams = append (httpStreams , edotSubprocessStream )
704
+ }
678
705
679
706
for _ , compInfo := range componentInfos {
680
707
binaryName := compInfo .BinaryName
@@ -683,12 +710,6 @@ func (b *BeatsMonitor) getHttpStreams(
683
710
}
684
711
685
712
endpoints := []interface {}{PrefixedEndpoint (BeatsMonitoringEndpoint (compInfo .ID ))}
686
- if compInfo .RuntimeManager == component .OtelRuntimeManager && compInfo .ID == httpMonitoringComponentInfoID && b .isOtelRuntimeSubprocess {
687
- // when Otel runtime is running as subprocess, we need to monitor it as a separate stream, thus we utilise the already
688
- // exposed endpoint of httpMonitoringComponentInfoID.
689
- edotSubprocessEndpoints = endpoints
690
- }
691
-
692
713
name := sanitizeName (binaryName )
693
714
694
715
// Do not create http streams if runtime-manager is otel and binary is of beat type
@@ -741,30 +762,6 @@ func (b *BeatsMonitor) getHttpStreams(
741
762
}
742
763
}
743
764
744
- if edotSubprocessEndpoints != nil {
745
- // Otel runtime subprocess metrics are collected using the same processors as the elastic-agent since we want only the
746
- // system resources.
747
- edotSubprocessStream := map [string ]any {
748
- idKey : fmt .Sprintf ("%s-edot-collector" , monitoringMetricsUnitID ),
749
- "data_stream" : map [string ]interface {}{
750
- "type" : "metrics" ,
751
- "dataset" : dataset ,
752
- "namespace" : monitoringNamespace ,
753
- },
754
- "metricsets" : []interface {}{"json" },
755
- "path" : "/stats" ,
756
- "hosts" : edotSubprocessEndpoints ,
757
- "namespace" : "agent" ,
758
- "period" : metricsCollectionIntervalString ,
759
- "index" : indexName ,
760
- "processors" : processorsForAgentHttpStream (agentName , edotCollectorName , edotCollectorName , monitoringNamespace , dataset , b .agentInfo ),
761
- }
762
- if failureThreshold != nil {
763
- edotSubprocessStream [failureThresholdKey ] = * failureThreshold
764
- }
765
- httpStreams = append (httpStreams , edotSubprocessStream )
766
- }
767
-
768
765
return httpStreams
769
766
}
770
767
0 commit comments