Skip to content

Add mongodb-query-exporter#1756

Merged
brian-brazil merged 1 commit intoprometheus:masterfrom
raffis:monogdb-query-exporter
Nov 12, 2020
Merged

Add mongodb-query-exporter#1756
brian-brazil merged 1 commit intoprometheus:masterfrom
raffis:monogdb-query-exporter

Conversation

@raffis
Copy link
Contributor

@raffis raffis commented Oct 4, 2020

Add mongodb-query-exporter to the list of exporters.
The mongodb-query-exporter creates prometheus metrics out of MongoDB aggregations.

Signed-off-by: Raffael Sahli <sahli@gyselroth.com>
@brian-brazil
Copy link
Contributor

Thanks for sharing, it looks like you should be using ConstMetrics. For example https://github.com/raffis/mongodb-query-exporter/blob/c871a06191355d06180dd88ee2ceba8ab68707fb/collector/main.go#L262 is trying to workaround incorrectly using direct instrumentation in an exporter (and more generally I question whether this sort of exporter can actually produce a Counter - everything should be a Gauge). This will be simpler, and ensure series disappear correctly.

You should also be pulling the metrics synchronously at scrape time, not based on a background timer - see https://prometheus.io/docs/instrumenting/writing_exporters/#scheduling

@raffis
Copy link
Contributor Author

raffis commented Oct 5, 2020

Thanks for sharing, it looks like you should be using ConstMetrics. For example https://github.com/raffis/mongodb-query-exporter/blob/c871a06191355d06180dd88ee2ceba8ab68707fb/collector/main.go#L262 is trying to workaround incorrectly using direct instrumentation in an exporter (and more generally I question whether this sort of exporter can actually produce a Counter - everything should be a Gauge). This will be simpler, and ensure series disappear correctly.

You should also be pulling the metrics synchronously at scrape time, not based on a background timer - see https://prometheus.io/docs/instrumenting/writing_exporters/#scheduling

Appreciate the review 👍 , will think about the counters again but yes I think I have to agree on this that there will probably never be an actual use case for this.

@beorn7 beorn7 added the exporters and integrations Requests for new entries in the list of exporters and integrations label Oct 5, 2020
@raffis
Copy link
Contributor Author

raffis commented Nov 11, 2020

Thanks for sharing, it looks like you should be using ConstMetrics. For example https://github.com/raffis/mongodb-query-exporter/blob/c871a06191355d06180dd88ee2ceba8ab68707fb/collector/main.go#L262 is trying to workaround incorrectly using direct instrumentation in an exporter (and more generally I question whether this sort of exporter can actually produce a Counter - everything should be a Gauge). This will be simpler, and ensure series disappear correctly.

You should also be pulling the metrics synchronously at scrape time, not based on a background timer - see https://prometheus.io/docs/instrumenting/writing_exporters/#scheduling

Your suggestions are now implemented:

  • Dropped support for counter
  • Using ConstMetrics now
  • Pulling synchronously at scrape time
  • (Added support for cache instead)

@brian-brazil
Copy link
Contributor

Your cache is broken, as you're concurrently reading and modifying c.cache from different goroutines. Concurrent map modification and access must be protected by a mutex.

I also think you don't need a custom registry here, the default one should suffice.

@raffis
Copy link
Contributor Author

raffis commented Nov 12, 2020

Your cache is broken, as you're concurrently reading and modifying c.cache from different goroutines. Concurrent map modification and access must be protected by a mutex.

Indeed, good catch.

I also think you don't need a custom registry here, the default one should suffice.

I used a custom one because of testing, with the one at package level you would have to unregister depening on the case. Or did I miss here something?

@brian-brazil
Copy link
Contributor

I used a custom one because of testing, with the one at package level you would have to unregister depening on the case. Or did I miss here something?

I'm looking at your main function, which seems to have an unneeded registry. I didn't look at the tests, but custom registries aren't unusual there.

@raffis
Copy link
Contributor Author

raffis commented Nov 12, 2020

Your cache is broken, as you're concurrently reading and modifying c.cache from different goroutines. Concurrent map modification and access must be protected by a mutex.

I also think you don't need a custom registry here, the default one should suffice.

It's fixed now in master.

@brian-brazil brian-brazil merged commit f3c7e32 into prometheus:master Nov 12, 2020
@brian-brazil
Copy link
Contributor

Thanks!

I'd suggest using a defer for the unlock in getCached, as that's going to be more robust in the face of future code changes.

@raffis
Copy link
Contributor Author

raffis commented Nov 12, 2020

Thanks for the suggestions, appreciate it!

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

Labels

exporters and integrations Requests for new entries in the list of exporters and integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants