-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Prometheus remote write endpoint #16609
Changes from 10 commits
4039278
a356dd7
8cc5380
0b35dcd
5bf8324
da960f3
db3bad5
0adda8c
d51a12a
58e41ca
d052651
fd89b1f
3e92bfb
2e9af93
87a5946
a0880f3
59f4b41
14d2643
ae87c0b
d542b14
c4ebbfc
efbf774
e5d7c20
5a7049b
276a287
45d6c11
001e4d8
18c6ce2
eb755ac
841fc7c
453e808
02c7902
6402466
05bdecd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//// | ||
This file is generated! See scripts/mage/docs_collector.go | ||
//// | ||
|
||
[[metricbeat-metricset-prometheus-remote_write]] | ||
=== Prometheus remote_write metricset | ||
|
||
beta[] | ||
|
||
include::../../../module/prometheus/remote_write/_meta/docs.asciidoc[] | ||
|
||
|
||
==== Fields | ||
|
||
For a description of each field in the metricset, see the | ||
<<exported-fields-prometheus,exported fields>> section. | ||
|
||
Here is an example document generated by this metricset: | ||
|
||
[source,json] | ||
---- | ||
include::../../../module/prometheus/remote_write/_meta/data.json[] | ||
---- |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,12 @@ type HttpEvent struct { | |
meta server.Meta | ||
} | ||
|
||
// MetricSetFactory accepts a BaseMetricSet and returns a MetricSet. If there | ||
// was an error creating the MetricSet then an error will be returned. The | ||
// returned MetricSet must also implement either EventFetcher or EventsFetcher | ||
// (but not both). | ||
type HandlerFactory func(h *HttpServer) func(writer http.ResponseWriter, req *http.Request) | ||
|
||
func (h *HttpEvent) GetEvent() common.MapStr { | ||
return h.event | ||
} | ||
|
@@ -52,7 +58,15 @@ func (h *HttpEvent) GetMeta() server.Meta { | |
return h.meta | ||
} | ||
|
||
func NewHttpServer(mb mb.BaseMetricSet) (server.Server, error) { | ||
func (h *HttpEvent) SetEvent(event common.MapStr) { | ||
h.event = event | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having that you are now passing a custom handler when initializing (which I think is a good idea), do you need an HttpEvent construct anymore? This was used to pass data between a generic HTTP server and the metricset. But now the metricset is in control of the requests, and can directly build and send events to the output. That should make things simpler, WDYT? |
||
|
||
func (h *HttpEvent) SetMeta(meta server.Meta) { | ||
h.meta = meta | ||
} | ||
|
||
func NewHttpServer(mb mb.BaseMetricSet, factory HandlerFactory) (server.Server, error) { | ||
config := defaultHttpConfig() | ||
err := mb.Module().UnpackConfig(&config) | ||
if err != nil { | ||
|
@@ -71,10 +85,9 @@ func NewHttpServer(mb mb.BaseMetricSet) (server.Server, error) { | |
ctx: ctx, | ||
stop: cancel, | ||
} | ||
|
||
httpServer := &http.Server{ | ||
Addr: net.JoinHostPort(config.Host, strconv.Itoa(int(config.Port))), | ||
Handler: http.HandlerFunc(h.handleFunc), | ||
Handler: http.HandlerFunc(factory(h)), | ||
} | ||
if tlsConfig != nil { | ||
httpServer.TLSConfig = tlsConfig.BuildModuleConfig(config.Host) | ||
|
@@ -116,6 +129,10 @@ func (h *HttpServer) GetEvents() chan server.Event { | |
return h.eventQueue | ||
} | ||
|
||
func (h *HttpServer) WriteEvents(event server.Event) { | ||
h.eventQueue <- event | ||
} | ||
|
||
func (h *HttpServer) handleFunc(writer http.ResponseWriter, req *http.Request) { | ||
switch req.Method { | ||
case "POST": | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need a factory? The metricset is already initializing the server, so you could pass a private
metricset.handleFunc
which implementsfunc(writer http.ResponseWriter, req *http.Request)