Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Implementation of all Vitess counters => Prom#79

Closed
zmagg wants to merge 2 commits intomasterfrom
zmagg_prom_multicounters
Closed

Implementation of all Vitess counters => Prom#79
zmagg wants to merge 2 commits intomasterfrom
zmagg_prom_multicounters

Conversation

@zmagg
Copy link
Copy Markdown

@zmagg zmagg commented Mar 8, 2018

Implementing Prometheus-native metrics.

Types of metrics to implement

  • Counters
  • MultiCounters
  • MultiCounterFunc
  • Timings
  • MultiTimings
  • direct calls to NewInt()
  • direct calls to stats.Publish(...IntFunc())

Other things to do

  • Add tests for each of the types of metrics
  • Get TravisCI working with the new packages I've added to the vendor file (promhttp)

Things not ported

  • NewString / NewStringMap / PublishJSONFunc
    Prom. doesn't handle string values. Some of these could be converted into different types, if we'd like to export the metrics anyway.

  • NewFloat
    This isn't called anywhere today. We could maybe export them anyway in case there are any callers in the future.

  • direct calls to stats.Publish(...CounterFunc())
    I think this should get ported in a followup PR, possibly refactoring it to use MultiCounterFunc.

Additional things to do in follow-on PRs

  • Visit Rates / DurationFunc callsites and instrument them so that we can derive the rate/duration in Prometheus at querytime.

Breaking changes

As much as possible, I tried to not change anything about the existing expvar stats. However, there were a few inconsistencies in namings that made it difficult to do the camelcase => snakecase transformation necessary for Prometheus exporting. Also, it's nice to have a consistent name for things.

The following are things that changed:

  • VTGateWarnings => VtgateWarnings to match the rest of the things that have a Vtgate prefix.

@zmagg zmagg changed the title Multicounters => Prom Implementation of all Vitess counters => Prom Mar 19, 2018
Copy link
Copy Markdown
Collaborator

@demmer demmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think this is really good and you're definitely on the right track!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better golang style would be to just call this function Init.

You also need a doc comment of the form "// Init initializes the backend with the given namespace" to appease the linter.

More to the point you should install govet / golint / etc and hook it up with your editor.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh TIL.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran govet & golint on all the packages I added. Is there a convention for what to do for files in a package that you edited that you didn't modify that fail? (stats/ring.go fails)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to me something that warrants another public API function... better IMO would be to just fold this in as part of Init.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these NewXYZCollector functions should be exposed as part of the public API.

I think you should either make them newXYZCollector or just inline the struct creation into prombackend.NewMultiCounter

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great feedback, this is a lot clearer inlined.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that if you stash the pointer to mc as part of the multiCountersCollector, then in the Collect implementation you don't need to go back again and call stats.GetMultiCounter(name) since you can just have the pointer to the underlying counter in the multiCountersCollector itself.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this can all be simplified a lot if we go with the approach I mentioned before where the pointer to the underlying counter / multicounter / multicounterfunc object is stored in the collector itself.

Then you wouldn't need all these separate locks -- you can have a single one for the registry of pull backends and pull metrics since the only coordination needs to be at initialization / registration time.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an erroneous typo

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing godoc string

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another mistaken edit.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well you put help in Counters already... I think both belong there.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need this if the Help() method is defined on the Counters struct.
It also seems like we want a corresponding Name() function at the same level.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need Name() (or to store it), so I've gotten rid of it.

@zmagg zmagg force-pushed the zmagg_prom_multicounters branch 2 times, most recently from eecdf8b to 0f125d7 Compare March 27, 2018 23:58
@zmagg
Copy link
Copy Markdown
Author

zmagg commented Mar 28, 2018

Superceded by vitessio#3784

@zmagg zmagg closed this Mar 28, 2018
@zmagg zmagg reopened this Mar 30, 2018
@zmagg zmagg force-pushed the zmagg_prom_multicounters branch from 0f125d7 to 2926920 Compare March 30, 2018 04:57
@zmagg zmagg closed this Apr 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants