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

Fix Warning & Operation metrics #14323

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hamistao
Copy link
Contributor

lxd_operations_total and lxd_warnings_total are currently being taken clusterwide, instead of returning just the entities related to the Node responding the metrics request. This goes against the overall design of the metrics, that are supposed to be per node and queried on each node on a cluster.
To fix this, this PR filters the queries for those entities based on the Node.

Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

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

Do warnings always have a node?

@hamistao
Copy link
Contributor Author

Do warnings always have a node?

They do not, this is marked as Draft while I/we decide on how to handle nodeless warnings, I am thinking just include them in all node's metrics.

@tomponline
Copy link
Member

Do warnings always have a node?

They do not, this is marked as Draft while I/we decide on how to handle nodeless warnings, I am thinking just include them in all node's metrics.

Yeah, or just on the leader?

@hamistao
Copy link
Contributor Author

Yeah, or just on the leader?

I think this makes even more sense. Since Prometheus is supposed to scrape them on every node, counting them for each node can have the effect of readundantly counting these warnings many times when aggregating the measurements.

lxd/api_metrics.go Outdated Show resolved Hide resolved
@hamistao hamistao force-pushed the fix_warning_operation_metrics branch from 471cc6e to 880764a Compare October 23, 2024 10:01
@hamistao
Copy link
Contributor Author

@tomponline @markylaing I am thinking on waiting for #14261 before proceeding here since I intend to use the LeaderInfo function defined there. I have cherry picked some commits to test and it all works fine.

@hamistao hamistao force-pushed the fix_warning_operation_metrics branch from 880764a to 7b088a0 Compare November 1, 2024 13:38
@tomponline
Copy link
Member

@hamistao please can we get this one fixed ready for LXD 6.2 release

@hamistao hamistao force-pushed the fix_warning_operation_metrics branch from 7b088a0 to bd71ccc Compare November 6, 2024 11:20
@tomponline tomponline marked this pull request as ready for review November 6, 2024 11:30
@hamistao hamistao force-pushed the fix_warning_operation_metrics branch from bd71ccc to 2a24a74 Compare November 6, 2024 19:57
lxd/api_metrics.go Outdated Show resolved Hide resolved
@@ -378,10 +379,40 @@ func getFilteredMetrics(s *state.State, r *http.Request, compress bool, metricSe
return response.SyncResponsePlain(true, compress, metricSet.String())
}

func internalMetrics(ctx context.Context, daemonStartTime time.Time, tx *db.ClusterTx) *metrics.MetricSet {
Copy link
Member

Choose a reason for hiding this comment

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

the change to this function's signature should be a separate commit as not related to the commit message

Copy link
Contributor Author

@hamistao hamistao Nov 12, 2024

Choose a reason for hiding this comment

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

I must include the state as a parameter on internalMetrics for this commit since clusterMemberWarnings requires it to call s.LeaderInfo(), so it is a change necessary for "Filtering query for Warnings appropriately" (as per the commit message).
That said, I can split this in two commits if you think it would be simpler.

Copy link
Member

Choose a reason for hiding this comment

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

Personally I would have plumbed in the replacement of daemonStartTime argument with *state.State as single commit first, including passing s.StartTime instead of daemonStartTime to out.AddSamples().

Then as another commit I would have introcuced the clusterMemberWarnings function and replaced the call to dbCluster.GetWarnings in internalMetrics.

As it is now the changes are munged together and harder to review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted! I find it useful to understand how you think about this so I can try to make your life easier :)

I will be pushing these changes along with the tests

Signed-off-by: hamistao <[email protected]>
(cherry picked from commit 24f150cf451eef796d879f1a191004ef0504b301)
Signed-off-by: hamistao <[email protected]>
Signed-off-by: hamistao <[email protected]>
(cherry picked from commit decddf5adfbd0c34c1f189c4eff16c19b3527abd)
Signed-off-by: hamistao <[email protected]>
Filters query for Warnings on the metrics handler by Node. Since some
Warnings do not have a node, nodeless Warnings are only being included
if querying the metrics from the leader node.

Signed-off-by: hamistao <[email protected]>
@hamistao hamistao force-pushed the fix_warning_operation_metrics branch from 2a24a74 to e24204d Compare November 12, 2024 17:02
Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

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

Is it possible to add some tests for this behaviour by faking some warnings and checking they only appear in the leader endpoint?

@hamistao
Copy link
Contributor Author

Is it possible to add some tests for this behaviour by faking some warnings and checking they only appear in the leader endpoint?

@tomponline Yes, it is. This is precisely how I have been testing: making dummy warnings with lxd sql.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants