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

Implement Prometheus statser #284

Open
tiedotguy opened this issue Feb 11, 2020 · 6 comments
Open

Implement Prometheus statser #284

tiedotguy opened this issue Feb 11, 2020 · 6 comments

Comments

@tiedotguy
Copy link
Collaborator

tiedotguy commented Feb 11, 2020

This would allow for internal metrics to be monitored from prom.

This could be useful when there's a large number of ephemeral hosts, and other backends may not scale as well with the high cardinality of internal metrics across many hosts.

This is mostly stand-alone and doesn't interact with the more complicated aspects of how gostatsd handles things, as it's mostly just adding an http server + prom, so it's probably a good issue for someone looking to get across the code base.

This is explicitly not a prom backend, this is only for internal metrics, see #285 for that.

@0xYao
Copy link

0xYao commented Oct 30, 2020

This would allow for internal metrics to be monitored from prom.

This could be useful when there's a large number of ephemeral hosts, and other backends may not scale as well with the high cardinality of internal metrics across many hosts.

This is mostly stand-alone and doesn't interact with the more complicated aspects of how gostatsd handles things, as it's mostly just adding an http server + prom, so it's probably a good issue for someone looking to get across the code base.

This is explicitly not a prom backend, this is only for internal metrics, see #285 for that.

Hey, I am keen to give this issue a go. All good if I take it from here?

@tiedotguy
Copy link
Collaborator Author

That'd be great!

@0xYao
Copy link

0xYao commented Oct 31, 2020

Would pkg/web be the right place to make the changes, or is there a more suitable directory where I can add the HTTP server with Prometheus to?

@tiedotguy
Copy link
Collaborator Author

I'm not familiar with the Prom SDK in go, but my approach would be to create an appropriate PromStatser (which also includes the necessary Handler) in createStatser, then propagate that through to NewHttpServer, then if it's enabled (for that particular http server), attempt a type assertion to convert the interface to a PromStatser, and then attach the Handler if it's the right type.

If it's the wrong type, return an error - fast fail on startup is encouraged.

@0xYao
Copy link

0xYao commented Nov 8, 2020

When you said if it's enabled, do you mean if the flag for such as enablePrometheus is set to true? For example, in the NewHttpServer function in pkg/web/httpservers.go, we have this if statement:

if enableIngestion {
  server.rawMetricsV2 = newRawHttpHandlerV2(logger, serverName, handler)
  routes = append(routes,
		route{path: "/v2/raw", handler: server.rawMetricsV2.MetricHandler, methods: []string{"POST"}, name: "metricsv2_post"},
		route{path: "/v2/event", handler: server.rawMetricsV2.EventHandler, methods: []string{"POST"}, name: "eventsv2_post"},
	)
}

So this means if ingestion is enabled, then attach the MetricHandler and EventHandler to the routes, which then is attached to the server. I guess I can do similar things for the Prometheus Statser? But does that mean that I have to pass in additional parameters such as the Statser and a flag enablePrometheus to the NewHttpServer method to make it work?

If it is not the case, then I am not sure what you mean by checking if it's enabled and how we can attach the handler.

@tiedotguy
Copy link
Collaborator Author

You don't need to worry about Metric/EventHandler, that would be for making a prom backend (#285), this is purely for internal metrics.

I would suggest approaching this in two steps. First, implement the stats.Statser interface, exposing prom metrics without regard for pkg/web. This is just so that you can get the prom stuff working. Ideally this would be done without using the DefaultRegistry/DefaultGatherer, so as to avoid singletons.

Once you've got the metrics exposed and working that way, you need to get the http.Handler through to pkg/web. As mentioned, I recommend just passing the stats.Statser through and doing a type check on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants