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

cli to push metrics to aggregator service #8835

Merged
merged 6 commits into from
May 3, 2021
Merged

cli to push metrics to aggregator service #8835

merged 6 commits into from
May 3, 2021

Conversation

kasey
Copy link
Contributor

@kasey kasey commented Apr 28, 2021

What type of PR is this?
Feature

What does this PR do? Why is it needed?

This PR implements a cli to collect the majority of the beaconcha.in beacon-node and validator metrics collection specification. It does not implement the system metrics collector at this time. The purpose of this feature is to allow users who wish to use beaconcha.in monitoring to scrape data from their prysm processes and ship them to beaconcha.in's collection API. The cli gives users the option of specifying any endpoint, so if desired the same tool can be used to post data to a custom API.

Which issues(s) does this PR fix?

Fixes #8833
Other notes for review
This pull request should be merged into clientstats-prometheus-changes before merging it down! The PR for that branch is at #8834

This PR will introduce the client stats scraper itself. These 2 PRs have been broken up because the boilerplate of a new cli command adds to the line count and this PR includes changes to some existing core services.

@kasey kasey requested a review from a team as a code owner April 28, 2021 18:57
@kasey kasey requested review from farazdagi, terencechain and rkapka and removed request for a team April 28, 2021 18:57
cmd/client-stats/main.go Outdated Show resolved Hide resolved
shared/clientstats/scrapers.go Outdated Show resolved Hide resolved
var m *dto.Metric
var ok bool

f, ok = pf["process_cpu_seconds_total"]
Copy link
Contributor

Choose a reason for hiding this comment

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

If these hard-coded strings change in the future (although unlikely), it would be easier if they lived as consts at the top of the file perhaps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO in an instance like this where the value is used in one place it is more readable to keep the strings inline, but don't feel super strongly about it.

shared/clientstats/scrapers.go Outdated Show resolved Hide resolved
var m *dto.Metric
var ok bool

f, ok = pf["beacon_head_slot"]
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on the hard-coded strings

return bytes.NewBuffer(b), err
}

func NewBeaconNodeScraper(promExpoURL string) Scraper {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not too much preference here, but the file would be more readable if we kept structs at the top, constructor functions next, exported functions next, then finally unexported funcs

shared/clientstats/updaters.go Outdated Show resolved Hide resolved
shared/clientstats/interfaces.go Show resolved Hide resolved
cmd/client-stats/main.go Outdated Show resolved Hide resolved
@kasey kasey force-pushed the clientstats-prometheus-changes branch from a5210cb to 954c185 Compare April 28, 2021 23:09
@kasey kasey changed the title cli to push metrics to aggregator service WIP cli to push metrics to aggregator service Apr 29, 2021
@kasey kasey changed the title WIP cli to push metrics to aggregator service WIP: cli to push metrics to aggregator service Apr 29, 2021
@kasey kasey force-pushed the clientstats-cli branch 2 times, most recently from b55ae68 to fae8ea9 Compare April 29, 2021 18:15
@kasey kasey force-pushed the clientstats-prometheus-changes branch from 793764a to 4f7d958 Compare April 29, 2021 19:29
@kasey kasey force-pushed the clientstats-prometheus-changes branch from 4f7d958 to 6ea2ab6 Compare April 29, 2021 20:06
@kasey kasey force-pushed the clientstats-cli branch 2 times, most recently from 2b6d35d to f69f21f Compare April 29, 2021 20:28
@kasey kasey changed the title WIP: cli to push metrics to aggregator service cli to push metrics to aggregator service Apr 29, 2021
@kasey kasey force-pushed the clientstats-prometheus-changes branch from 6ea2ab6 to 99b9e4e Compare April 29, 2021 20:40
@kasey kasey force-pushed the clientstats-cli branch 3 times, most recently from a6127d7 to 46dc9b6 Compare April 30, 2021 03:44
@kasey kasey force-pushed the clientstats-prometheus-changes branch from 4dc9dab to a278440 Compare April 30, 2021 15:57
@kasey kasey force-pushed the clientstats-prometheus-changes branch from a278440 to 2e8b491 Compare April 30, 2021 17:48
@codecov
Copy link

codecov bot commented Apr 30, 2021

Codecov Report

Merging #8835 (35fe43d) into develop (a6e1ff0) will decrease coverage by 0.04%.
The diff coverage is 62.87%.

@@             Coverage Diff             @@
##           develop    #8835      +/-   ##
===========================================
- Coverage    60.59%   60.55%   -0.05%     
===========================================
  Files          525      527       +2     
  Lines        36978    37108     +130     
===========================================
+ Hits         22406    22469      +63     
- Misses       11350    11402      +52     
- Partials      3222     3237      +15     

@kasey kasey force-pushed the clientstats-prometheus-changes branch from 2e8b491 to f1dc18e Compare April 30, 2021 18:45
@delete-merged-branch delete-merged-branch bot deleted the branch develop April 30, 2021 20:37
@kasey kasey changed the base branch from clientstats-prometheus-changes to develop April 30, 2021 20:47
rauljordan
rauljordan previously approved these changes Apr 30, 2021
@rauljordan rauljordan added the Ready For Review A pull request ready for code review label Apr 30, 2021
bnScraper := beaconNodeScraper{}
bnScraper.tripper = &mockRT{body: prometheusTestBody}
r, err := bnScraper.Scrape()
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Can be more consistent with rest of the codebase by doing

require.NoError(t, err, Unexpected error calling beaconNodeScraper.Scrape)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, although I just realized I've been using assert.NoError in multiple places rather than require.NoError. I see the difference is that require uses FatalF and assert uses Errorf. I'll put more care into picking between assert/require going forward.

cmd/client-stats/main.go Outdated Show resolved Hide resolved
// It is used by the cli to write to stdout when an http endpoint
// is not provided. The output could be piped into another program
// or used for debugging.
func NewGenericClientStatsUpdater(w io.Writer) Updater {
Copy link
Member

Choose a reason for hiding this comment

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

These are not tested but I think that's perfectly fine

kasey added 6 commits May 3, 2021 09:01
* adds client-stats types beacause they are
  used by some of the prometheus collection code.
* new prometheus collector for db disk size
* new prometheus collector for web3 client
  connection status
@kasey kasey merged commit dace0f9 into develop May 3, 2021
@delete-merged-branch delete-merged-branch bot deleted the clientstats-cli branch May 3, 2021 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for beaconcha.in style metrics tracking
3 participants