Skip to content
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

Cherry-pick #22605 to 7.x: Add support for customized monitoring API #23279

Merged
merged 2 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for customized monitoring API (#22605)
(cherry picked from commit 82c11d4)
  • Loading branch information
newly12 authored and urso committed Dec 24, 2020
commit 18832e40d102e4435622b6590aac2be186cbb7b7
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Added new `rate_limit` processor for enforcing rate limits on event throughput. {pull}22883[22883]
- Allow node/namespace metadata to be disabled on kubernetes metagen and ensure add_kubernetes_metadata honors host {pull}23012[23012]
- Improve equals check. {pull}22778[22778]
- Honor kube event resysncs to handle missed watch events {pull}22668[22668]
- Add support for customized monitoring API. {pull}22605[22605]

*Auditbeat*

Expand Down
15 changes: 15 additions & 0 deletions libbeat/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
type handlerFunc func(http.ResponseWriter, *http.Request)
type lookupFunc func(string) *monitoring.Namespace

var handlerFuncMap = make(map[string]handlerFunc)

// NewWithDefaultRoutes creates a new server with default API routes.
func NewWithDefaultRoutes(log *logp.Logger, config *common.Config, ns lookupFunc) (*Server, error) {
mux := http.NewServeMux()
Expand All @@ -38,6 +40,10 @@ func NewWithDefaultRoutes(log *logp.Logger, config *common.Config, ns lookupFunc
mux.HandleFunc("/state", makeAPIHandler(ns("state")))
mux.HandleFunc("/stats", makeAPIHandler(ns("stats")))
mux.HandleFunc("/dataset", makeAPIHandler(ns("dataset")))

for api, h := range handlerFuncMap {
mux.HandleFunc(api, h)
}
return New(log, mux, config)
}

Expand Down Expand Up @@ -73,3 +79,12 @@ func prettyPrint(w http.ResponseWriter, data common.MapStr, u *url.URL) {
fmt.Fprintf(w, data.String())
}
}

// AddHandlerFunc provides interface to add customized handlerFunc
func AddHandlerFunc(api string, h handlerFunc) error {
if _, exist := handlerFuncMap[api]; exist {
return fmt.Errorf("%s already exist", api)
}
handlerFuncMap[api] = h
return nil
}