Skip to content

Commit

Permalink
[Ingest Manager] Proxy processes/elastic-agent to stats (#25193)
Browse files Browse the repository at this point in the history
[Ingest Manager] Proxy processes/elastic-agent to stats (#25193)
  • Loading branch information
michalpristas authored Apr 21, 2021
1 parent 7423634 commit 4052c69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion x-pack/elastic-agent/pkg/core/monitoring/server/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/gorilla/mux"

"github.com/elastic/beats/v7/metricbeat/mb/parse"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/program"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/artifact"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/monitoring/beats"
Expand Down Expand Up @@ -51,7 +52,7 @@ var (
}
)

func processHandler() func(http.ResponseWriter, *http.Request) error {
func processHandler(statsHandler func(http.ResponseWriter, *http.Request) error) func(http.ResponseWriter, *http.Request) error {
return func(w http.ResponseWriter, r *http.Request) error {
w.Header().Set("Content-Type", "application/json; charset=utf-8")

Expand All @@ -62,6 +63,11 @@ func processHandler() func(http.ResponseWriter, *http.Request) error {
return errorfWithStatus(http.StatusNotFound, "productID not found")
}

if id == paths.BinaryName {
// proxy stats for elastic agent process
return statsHandler(w, r)
}

metricsBytes, statusCode, metricsErr := processMetrics(r.Context(), id)
if metricsErr != nil {
return metricsErr
Expand Down
5 changes: 3 additions & 2 deletions x-pack/elastic-agent/pkg/core/monitoring/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ func New(

func exposeMetricsEndpoint(log *logger.Logger, config *common.Config, ns func(string) *monitoring.Namespace, routesFetchFn func() *sorted.Set, enableProcessStats bool) (*api.Server, error) {
r := mux.NewRouter()
r.Handle("/stats", createHandler(statsHandler(ns("stats"))))
statsHandler := statsHandler(ns("stats"))
r.Handle("/stats", createHandler(statsHandler))

if enableProcessStats {
r.HandleFunc("/processes", processesHandler(routesFetchFn))
r.Handle("/processes/{processID}", createHandler(processHandler()))
r.Handle("/processes/{processID}", createHandler(processHandler(statsHandler)))
}

mux := http.NewServeMux()
Expand Down

0 comments on commit 4052c69

Please sign in to comment.