Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Mechanism to explicitly flush stats to exporters #773

Closed
arjantop opened this issue Jun 3, 2018 · 6 comments
Closed

Mechanism to explicitly flush stats to exporters #773

arjantop opened this issue Jun 3, 2018 · 6 comments

Comments

@arjantop
Copy link

arjantop commented Jun 3, 2018

Currently I see no way to push collected metrics to prometheus before program exit (especially in short batch programs), since views are reported periodically based on a timer.

What I have currently done is set view.SetReportingPeriod to something low and wait some duration and then perform the push.

@semistrict
Copy link
Contributor

Prometheus natively doesn't really support this using the pull model. What seems like it would work would be to provide OpenCensus support for the Prometheus Push Gateway: https://github.com/prometheus/pushgateway.

Mind if we repurpose this as a feature request on the Prometheus exporter?

@semistrict semistrict changed the title Add a method to force reportUsage of views Support exporting to Prometheus Push Gateway for short-lived processes Jun 4, 2018
@arjantop
Copy link
Author

arjantop commented Jun 4, 2018

You can currently push using the prometheus api (combined with opencensus). But if we get "native" push support in opencensus even better.

What I am doing currently:

  • set up exporter with provided registry
  • flush views lowering the view.SetReportingPeriod (a hack)
  • user prometheus api to push

@semistrict
Copy link
Contributor

Curious how you are pushing using the prometheus API. As I understand it, you register the exporter as an http.Handler and Prometheus scrapes it periodically. There isn't really a way to "force" Prometheus to scrape your app in a timely fashion. Sure, you can use SetReportingPeriod but all this does is change how often the page that Prometheus scrapes is updated. It doesn't guarantee that Prometheus will actually get the updated data.

@arjantop
Copy link
Author

arjantop commented Jun 4, 2018

No, I do not register the endpoint, opencensus Prometheus exporter is just an interface between opencensus views and native prometheus registry. I am using the push api that is using the gateway.

So I pass in explicit registry in NewExporter: prometheus.Options{Registry: registry}

And then use the push api: push.FromGatherer(job, nil, promGateway, registry)

@semistrict
Copy link
Contributor

Ah I see. I didn't realize that was possible. I will keep this open to add an example and document that usage.

I will also retitle to be closer to your original issue, namely that we need a way to flush exporters at process termination.

@semistrict semistrict changed the title Support exporting to Prometheus Push Gateway for short-lived processes Mechanism to flush exporters before process termination Jun 4, 2018
@semistrict semistrict changed the title Mechanism to flush exporters before process termination Mechanism to explicitly flush stats to exporters Jun 4, 2018
knyar added a commit to knyar/opencensus-go that referenced this issue Jul 25, 2018
- Report data for a given view when that view is unregistered;
- Add an explicit command to report all accumulated data.

This probably fixes census-instrumentation#773.
knyar added a commit to knyar/opencensus-go that referenced this issue Jul 26, 2018
semistrict pushed a commit that referenced this issue Jul 27, 2018
@songy23
Copy link
Contributor

songy23 commented Jan 24, 2019

Duplicated of #862.

@songy23 songy23 closed this as completed Jan 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants