@@ -26,7 +26,6 @@ import (
2626 "github.com/elastic/elastic-agent/internal/pkg/agent/control/proto"
2727 "github.com/elastic/elastic-agent/internal/pkg/agent/errors"
2828 "github.com/elastic/elastic-agent/internal/pkg/agent/program"
29- "github.com/elastic/elastic-agent/internal/pkg/core/monitoring/beats"
3029 monitoring "github.com/elastic/elastic-agent/internal/pkg/core/monitoring/beats"
3130 monitoringCfg "github.com/elastic/elastic-agent/internal/pkg/core/monitoring/config"
3231 "github.com/elastic/elastic-agent/internal/pkg/core/socket"
@@ -37,6 +36,10 @@ import (
3736 "github.com/elastic/elastic-agent/pkg/core/logger"
3837)
3938
39+ const (
40+ agentName = "elastic-agent"
41+ )
42+
4043// Server is the daemon side of the control protocol.
4144type Server struct {
4245 logger * logger.Logger
@@ -225,7 +228,8 @@ func (s *Server) ProcMeta(ctx context.Context, _ *proto.Empty) (*proto.ProcMetaR
225228 // gather spec data for all rk/apps running
226229 specs := s .getSpecInfo ("" , "" )
227230 for _ , si := range specs {
228- endpoint := monitoring .MonitoringEndpoint (si .spec , runtime .GOOS , si .rk )
231+ isSidecar := strings .HasSuffix (si .app , "_monitoring" )
232+ endpoint := monitoring .MonitoringEndpoint (si .spec , runtime .GOOS , si .rk , isSidecar )
229233 client := newSocketRequester (si .app , si .rk , endpoint )
230234
231235 procMeta := client .procMeta (ctx )
@@ -258,9 +262,9 @@ func (s *Server) Pprof(ctx context.Context, req *proto.PprofRequest) (*proto.Ppr
258262 ch := make (chan * proto.PprofResult , 1 )
259263
260264 // retrieve elastic-agent pprof data if requested or application is unspecified.
261- if req .AppName == "" || req .AppName == "elastic-agent" {
262- endpoint := beats .AgentMonitoringEndpoint (runtime .GOOS , s .monitoringCfg .HTTP )
263- c := newSocketRequester ("elastic-agent" , "" , endpoint )
265+ if req .AppName == "" || req .AppName == agentName {
266+ endpoint := monitoring .AgentMonitoringEndpoint (runtime .GOOS , s .monitoringCfg .HTTP )
267+ c := newSocketRequester (agentName , "" , endpoint )
264268 for _ , opt := range req .PprofType {
265269 wg .Add (1 )
266270 go func (opt proto.PprofOption ) {
@@ -273,11 +277,11 @@ func (s *Server) Pprof(ctx context.Context, req *proto.PprofRequest) (*proto.Ppr
273277
274278 // get requested rk/appname spec or all specs
275279 var specs []specInfo
276- if req .AppName != "elastic-agent" {
280+ if req .AppName != agentName {
277281 specs = s .getSpecInfo (req .RouteKey , req .AppName )
278282 }
279283 for _ , si := range specs {
280- endpoint := monitoring .MonitoringEndpoint (si .spec , runtime .GOOS , si .rk )
284+ endpoint := monitoring .MonitoringEndpoint (si .spec , runtime .GOOS , si .rk , false )
281285 c := newSocketRequester (si .app , si .rk , endpoint )
282286 // Launch a concurrent goroutine to gather all pprof endpoints from a socket.
283287 for _ , opt := range req .PprofType {
@@ -315,8 +319,8 @@ func (s *Server) ProcMetrics(ctx context.Context, _ *proto.Empty) (*proto.ProcMe
315319 }
316320
317321 // gather metrics buffer data from the elastic-agent
318- endpoint := beats .AgentMonitoringEndpoint (runtime .GOOS , s .monitoringCfg .HTTP )
319- c := newSocketRequester ("elastic-agent" , "" , endpoint )
322+ endpoint := monitoring .AgentMonitoringEndpoint (runtime .GOOS , s .monitoringCfg .HTTP )
323+ c := newSocketRequester (agentName , "" , endpoint )
320324 metrics := c .procMetrics (ctx )
321325
322326 resp := & proto.ProcMetricsResponse {
@@ -326,7 +330,8 @@ func (s *Server) ProcMetrics(ctx context.Context, _ *proto.Empty) (*proto.ProcMe
326330 // gather metrics buffer data from all other processes
327331 specs := s .getSpecInfo ("" , "" )
328332 for _ , si := range specs {
329- endpoint := monitoring .MonitoringEndpoint (si .spec , runtime .GOOS , si .rk )
333+ isSidecar := strings .HasSuffix (si .app , "_monitoring" )
334+ endpoint := monitoring .MonitoringEndpoint (si .spec , runtime .GOOS , si .rk , isSidecar )
330335 client := newSocketRequester (si .app , si .rk , endpoint )
331336
332337 s .logger .Infof ("gather metrics from %s" , endpoint )
0 commit comments