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

Change metrics with micrometer in mantis-control-plane #515

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

7ue5wu
Copy link

@7ue5wu 7ue5wu commented Aug 7, 2023

Context

Explain context and other details for this pull request.

Checklist

  • ./gradlew build compiles code correctly
  • Added new tests where applicable
  • ./gradlew test passes all tests
  • Extended README or added javadocs where applicable

@@ -70,7 +70,7 @@ public static HighAvailabilityServices createHAServices(CoreConfiguration config
}
else {
if (HAServiceInstanceRef.get() == null) {
HAServiceInstanceRef.compareAndSet(null, new ZkHighAvailabilityServices(configuration));
HAServiceInstanceRef.compareAndSet(null, new ZkHighAvailabilityServices(configuration, new SimpleMeterRegistry()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you instead pass MeterRegistry as an arg?

masterConnectRetryCounter = m.getCounter("MasterConnectRetryCount");
this.meterRegistry = meterRegistry;
String groupName = MasterClientWrapper.class.getCanonicalName();
masterConnectRetryCounter = meterRegistry.counter(groupName + ".MasterConnectRetryCount");
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor comment that . should be _

masterConnectRetryCounter = m.getCounter("MasterConnectRetryCount");
this.meterRegistry = meterRegistry;
String groupName = MasterClientWrapper.class.getCanonicalName();
masterConnectRetryCounter = meterRegistry.counter(groupName + ".MasterConnectRetryCount");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
masterConnectRetryCounter = meterRegistry.counter(groupName + ".MasterConnectRetryCount");
masterConnectRetryCounter = meterRegistry.counter(groupName + "_MasterConnectRetryCount");

this.failureCounter = metrics.getCounter("failureCounter");
this.workerSentHeartbeats = metrics.getCounter("workerSentHeartbeats");
String groupName = "ReportStatusServiceHttpImpl";
this.failureCounter = Counter.builder(groupName + ".failureCounter").register(meterRegistry);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
this.failureCounter = Counter.builder(groupName + ".failureCounter").register(meterRegistry);
this.failureCounter = meterRegistry.counter(groupName + "_failureCounter");

btw, is there a difference between doing

meterRegistry.counter(...) vs
Counter.builder(...).register(meterRegistry)

If not, I prefer we follow the first approach as much as possible.

this.workerSentHeartbeats = metrics.getCounter("workerSentHeartbeats");
String groupName = "ReportStatusServiceHttpImpl";
this.failureCounter = Counter.builder(groupName + ".failureCounter").register(meterRegistry);
this.workerSentHeartbeats = Counter.builder(groupName + ".workerSentHeartbeats").register(meterRegistry);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
this.workerSentHeartbeats = Counter.builder(groupName + ".workerSentHeartbeats").register(meterRegistry);
this.workerSentHeartbeats = Counter.builder(groupName + "_workerSentHeartbeats").register(meterRegistry);

this.jobRouteHandler = jobRouteHandler;
MasterConfiguration config = ConfigurationProvider.getConfig();
this.cache = createCache(actorSystem, config.getApiCacheMinSize(), config.getApiCacheMaxSize(),
config.getApiCacheTtlMilliseconds());
this.jobListGET = meterRegistry.counter("V0JobRoute" + "_" +"jobListGET");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
this.jobListGET = meterRegistry.counter("V0JobRoute" + "_" +"jobListGET");
this.jobListGET = meterRegistry.counter("V0JobRoute_jobListGET");

can you apply similar change to following lines as well? thx!

}

private Gauge addGauge(String meterName,int value) {
Gauge gauge = Gauge.builder("JobClusterActor_legacyGaugeCallbackMetricGroup_"+meterName, () -> 1.0 * value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you don't need legacyGaugeCallbackMetricGroup_ infix here because the GaugeCallback used here is io.mantisrx.common.metrics.spectator.GaugeCallback which doesn't use this string.
Also, the value being passed in is incorrect. I believe you want to call addGauge with the lambda and pass it as-is to Gauge.builder.

For eg:

this.acceptedJobsGauge = addGauge("acceptedJobsGauge", () -> 1.0 * this.jobManager.acceptedJobsCount());

and define addGauge as follows:

private Gauge addGauge(String meterName, Supplier<Number> gaugeFun) {
  return Gauge.builder("JobClusterActor_" + meterName, gaugeFunc).tags("jobCluster", name).register(meterRegistry);
}

public void incrementCounter(final String metric, final Iterable<Tag> tags) {
registry.counter(new MetricId(METRIC_GROUP_ID, metric, tags).getSpectatorId(registry)).increment();
public void incrementCounter(final String metric, final Tags tags) {
meterRegistry.counter(METRIC_GROUP_ID + "_" + metric, tags).increment();
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is smart I like it.

@@ -75,13 +72,13 @@ public void recordMisses(int count) {
@Override
public void recordLoadSuccess(long loadTime) {
loadSuccessCount.increment();
totalLoadTime.set(TimeUnit.MILLISECONDS.convert(loadTime, TimeUnit.NANOSECONDS));
totalLoadTime.record(Duration.ofDays(TimeUnit.MILLISECONDS.convert(loadTime, TimeUnit.NANOSECONDS)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

why use Duration.ofDays here?

Copy link
Author

Choose a reason for hiding this comment

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

Oh! Actually, I was supposed to use Duration.ofNanos here.

this.noWorkersFoundCounter = m.getCounter("noWorkersFound");
this.workersFoundCounter = m.getCounter("workersFound");
this.meterRegistry = meterRegistry;
this.noWorkersFoundCounter = meterRegistry.counter("Storage_noWorkersFound");
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor comment: pl keep storage in lower-case to be consistent with original metrics.
It'd be storage instead of Storage

@7ue5wu 7ue5wu had a problem deploying to Integrate Pull Request August 11, 2023 16:09 — with GitHub Actions Failure
@7ue5wu 7ue5wu had a problem deploying to Integrate Pull Request August 14, 2023 23:29 — with GitHub Actions Failure
@7ue5wu 7ue5wu had a problem deploying to Integrate Pull Request August 15, 2023 20:41 — with GitHub Actions Failure
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

2 participants