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

Add the elections counter metric #4179

Conversation

dhingrak
Copy link
Contributor

@dhingrak dhingrak commented Mar 1, 2024

Added: Add the elections counter metric so users can set alerts if the number of elections over a certain period of time exceeds some number.

Fixes https://linear.app/eventstore/issue/DB-599/add-the-elections-counter-to-metrics

Copy link

linear bot commented Mar 1, 2024

@dhingrak dhingrak force-pushed the kunaldhingra/db-599-add-the-elections-counter-to-metrics branch from f85d7ae to 2f10c55 Compare March 4, 2024 19:02
@dhingrak dhingrak marked this pull request as ready for review March 4, 2024 19:14
@dhingrak dhingrak force-pushed the kunaldhingra/db-599-add-the-elections-counter-to-metrics branch from 2f10c55 to 207ce31 Compare March 5, 2024 00:22
@timothycoleman
Copy link
Contributor

looks good, handling the ElectionsDone message is a nice way to do it. We can make use of the existing CounterMetric though, and have the tracker handle the message directly instead of having an extra service

@dhingrak
Copy link
Contributor Author

dhingrak commented Mar 8, 2024

Sure. I will work on this.

@timothycoleman
Copy link
Contributor

timothycoleman commented Mar 10, 2024

Oh yeah and updating the documentation would be fab too (in a separate PR actually since it requires a different reviewer)

@dhingrak dhingrak force-pushed the kunaldhingra/db-599-add-the-elections-counter-to-metrics branch from 207ce31 to ed32779 Compare March 11, 2024 22:22
@dhingrak
Copy link
Contributor Author

@timothycoleman I have handled the Elections.Done message in tracker itself but I am not 100% sure if this is the right to do it.

Comment on lines 7 to 8
public interface IElectionCounterTracker {
void IncrementCounter();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public interface IElectionCounterTracker {
void IncrementCounter();
}
public interface IElectionCounterTracker : IHandle<Messages.ElectionMessage.ElectionsDone> {
}

ah ok sorry, i meant like this ^

@dhingrak dhingrak force-pushed the kunaldhingra/db-599-add-the-elections-counter-to-metrics branch from ed32779 to 52e348c Compare March 12, 2024 22:17
@dhingrak
Copy link
Contributor Author

I have added the IncrementCounter function because of Unit testing. This way the tests are easy to understand. We can test this with sut.Hanlde(null) if we want.

@timothycoleman
Copy link
Contributor

cool, thanks

yes we should test it by calling Handle, and remove the IncrementCounter method. That way the tests are using the tracker how it is supposed to be used

you can construct an electionsdone message like this

	private readonly Messages.ElectionMessage.ElectionsDone _electionsDoneMessage;

	public ElectionsCounterTrackerTests() {
		var endPoint = new DnsEndPoint("127.0.0.1", 1113);
		var memberInfo = Cluster.MemberInfo.Initial(Guid.Empty, DateTime.UtcNow,
			VNodeState.Unknown, true,
			endPoint, endPoint, endPoint, endPoint, endPoint,
			null, 0, 0, 0, false);
		_electionsDoneMessage = new(1, 1, memberInfo);
	}

@dhingrak dhingrak force-pushed the kunaldhingra/db-599-add-the-elections-counter-to-metrics branch 2 times, most recently from 0a3e700 to 870ef6d Compare March 13, 2024 16:52
@dhingrak dhingrak force-pushed the kunaldhingra/db-599-add-the-elections-counter-to-metrics branch from 870ef6d to dbfe9d3 Compare March 13, 2024 17:07
Copy link
Contributor

@timothycoleman timothycoleman left a comment

Choose a reason for hiding this comment

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

👍

@timothycoleman timothycoleman merged commit 71cdac7 into master Mar 14, 2024
7 of 8 checks passed
@timothycoleman timothycoleman deleted the kunaldhingra/db-599-add-the-elections-counter-to-metrics branch March 14, 2024 12:03
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.

None yet

3 participants