-
Notifications
You must be signed in to change notification settings - Fork 90
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
testutils/promrated: add prom query to collect pubkey to cluster information #1562
Conversation
Codecov ReportBase: 54.28% // Head: 54.10% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1562 +/- ##
==========================================
- Coverage 54.28% 54.10% -0.19%
==========================================
Files 153 156 +3
Lines 19436 19579 +143
==========================================
+ Hits 10551 10593 +42
- Misses 7455 7549 +94
- Partials 1430 1437 +7
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
testutil/promrated/prometheus.go
Outdated
) | ||
|
||
const ( | ||
promEndpoint = "https://vm.monitoring.gcp.obol.tech" | ||
promQuery = "group%20by%20%28cluster_name%2C%20ccluster_hash%2C%20cluster_peer%2C%20cluster_network%2C%20pubkey_full%29%20%28core_scheduler_validator_balance_gwei%29" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write normal text, http libraries should handle escaping
testutil/promrated/prometheus.go
Outdated
) | ||
|
||
const ( | ||
promEndpoint = "https://vm.monitoring.gcp.obol.tech" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
best avoid globals, make this a flag with a default value
testutil/promrated/prometheus.go
Outdated
promQuery = "group%20by%20%28cluster_name%2C%20ccluster_hash%2C%20cluster_peer%2C%20cluster_network%2C%20pubkey_full%29%20%28core_scheduler_validator_balance_gwei%29" | ||
) | ||
|
||
type ClusterInfo struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always unexport names by default.
testutil/promrated/prometheus.go
Outdated
return nil, err | ||
} | ||
|
||
if res.StatusCode == 200 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testutil/promrated/prometheus.go
Outdated
|
||
func getPromClusters(ctx context.Context, promAuth string) (*http.Response, error) { | ||
client := new(http.Client) | ||
url := fmt.Sprintf("%s/query?query=%s", promEndpoint, promQuery) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the url
package to build the url (avoid unstructured untyped logic)
testutil/promrated/prometheus.go
Outdated
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) | ||
if err != nil { | ||
log.Error(ctx, "HTTP Request malformed for prom query", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't log and return errors, rather just return errors and log at the root (the loop or processor that is doing the scheduling).
testutil/promrated/prometheus.go
Outdated
return res, nil | ||
} | ||
|
||
func readPromJSON(ctx context.Context, res *http.Response) (*PromResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is two function calls and pretty common go code, can inline. Also you need to close the request body.
testutil/promrated/prometheus.go
Outdated
return nil, errors.New("error processing prom metrics", z.Str("url", res.Request.RequestURI)) | ||
} | ||
|
||
func getPromClusters(ctx context.Context, promAuth string) (*http.Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning a http response isn't a good abstraction, rather colocate http wrangling stuff and return proper business logic types
testutil/promrated/prometheus.go
Outdated
@@ -41,6 +81,73 @@ func serveMonitoring(addr string) error { | |||
return errors.Wrap(server.ListenAndServe(), "failed to serve prometheus metrics") | |||
} | |||
|
|||
func getPubkeyToClusterInfo(ctx context.Context, promAuth string) (map[string]prometheus.Labels, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getPubkeyToClusterInfo
name can improve, what about getClusters
or getClustersFromProm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add godoc please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather return a proper type instead of map of strings. Also remember that clusters contain multiple validators. Suggest:
type Validator struct {
PubkeyHex string
ClusterName string
ClusterHash string
ClusterPeer string
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getPubkeyToClusterInfo
name can improve, what aboutgetClusters
orgetClustersFromProm
Yeah this naming is what I was used to for map types, can change it
testutil/promrated/prometheus.go
Outdated
Metric PromMetric `json:"metric"` | ||
} | ||
|
||
type PromData struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for all these types, you can just define a single nested type since it is only used for unmarshalling. Also, only include fields that you are actually using.
type promResponse struct {
Data struct {
Result []struct{
...
} `json:result`
} `json:"data"`
}
testutil/promrated/prometheus.go
Outdated
} | ||
|
||
type PromMetric struct { | ||
*ClusterInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid pointers
Adding in prometheus query to get all the necessary cluster information and associated private keys.
category: misc
ticket: #1540