-
Notifications
You must be signed in to change notification settings - Fork 200
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
MetricsServer v2 #469
MetricsServer v2 #469
Conversation
private Observable<Measurements> measurements(long timeFrequency) { | ||
final MetricsRegistry registry = MetricsRegistry.getInstance(); | ||
private Observable<MicrometerMeasurements> measurements(long timeFrequency) { | ||
final MeterRegistry registry = Metrics.globalRegistry; |
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.
you can keep both.
final MeterRegistry micrometerRegistry = Metrics.globalRegistry;
final MetricsRegistry mantisMeterRegistry = MetricsRegistry.getInstance();
measurements.add(new Measurements(metrics.getMetricGroupId().name(), | ||
timestamp, counters, gauges, tags)); | ||
List<MicrometerMeasurements> measurements = new ArrayList<>(); | ||
for (Meter meter: registry.getMeters()) { |
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.
for (Meter meter : mantisMeterRegistry) {
// ... keep everything the same. No changes!!!
}
for (Meter meter : micrometerRegistry) {
// ... do other thing
// we use Measurements.java and add a new field called List
}
@@ -46,6 +48,21 @@ public Measurements( | |||
this.tags = tags; | |||
} | |||
|
|||
@JsonCreator |
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.
instead of adding a new method, please add a new Collection<MicrometerMeasurements>
arg to the original constructor and refactor accordingly.
'}'; | ||
} | ||
|
||
public static class MicrometerMeasurement { |
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 a good change, umm, minor thing if I may suggest is to create it as a separate class similar to GaugeMeasurement
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.
These changes look good to me, thank you for making these changes. Appreciate it!
I've asked @sundargates to also take a look at the PR for a second set of eyes.
gauges.add(new GaugeMeasurement(gaugeEntry.getKey().metricName(), gaugeEntry.getValue().doubleValue())); | ||
} | ||
measurements.add(new Measurements(metrics.getMetricGroupId().name(), | ||
timestamp, counters, gauges, null,tags)); |
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.
minor: please use Collections.emptyList()
instead of null
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.
Already updated.
for (Meter meter: micrometerregistry.getMeters()) { | ||
Collection<MicrometerMeasurement> micrometers = new LinkedList<>(); | ||
micrometers.add(new MicrometerMeasurement(meter.getId().getType(), meter.measure().iterator().next().getValue())); | ||
measurements.add(new Measurements(meter.getId().getName(), timestamp, null, null, micrometers, tags)); |
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.
minor: please use Collections.emptyList()
instead of null
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.
Already updated.
mantis-common/build.gradle
Outdated
compileOnly libraries.spectatorApi | ||
implementation libraries.spectatorApi |
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.
Do we even need spectatorApi after migration to micrometer?
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, but I think we need to keep it now because we still keep both metrics during migration.
mantis-common/build.gradle
Outdated
@@ -41,6 +41,7 @@ dependencies { | |||
api libraries.slf4jLog4j12 | |||
implementation libraries.commonsIo | |||
implementation 'net.jcip:jcip-annotations:1.0' | |||
implementation 'io.micrometer:micrometer-core:1.11.0' |
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.
nit: move this to 3rdparty dependencies in root build.gradle.
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.
Already updated.
@@ -63,31 +67,39 @@ public MetricsServer(int port, long publishRateInSeconds, Map<String, String> ta | |||
} | |||
|
|||
private Observable<Measurements> measurements(long timeFrequency) { | |||
final MeterRegistry micrometerregistry = Metrics.globalRegistry; |
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.
nit: Can we avoid using this singleton?
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.
Could you please be more specific?
|
||
import io.micrometer.core.instrument.Meter; | ||
|
||
public class MicrometerMeasurement { |
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 lombok @value.
|
||
import io.micrometer.core.instrument.Meter; | ||
|
||
public class MicrometerMeasurement { |
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.
Do we even need this type, or can we convert the micrometer measurements to the existing measures DS?
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.
I think we should keep them separate to allow identify mantis metrics vs micrometer metrics.
Eventually, we can migrate Measurements to MicrometerMeasurement only.
@@ -38,11 +40,13 @@ public Measurements( | |||
@JsonProperty("timestamp") long timestamp, | |||
@JsonProperty("counters") Collection<CounterMeasurement> counters, | |||
@JsonProperty("gauges") Collection<GaugeMeasurement> gauges, | |||
@JsonProperty("micrometers") Collection<MicrometerMeasurement> micrometers, |
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.
Why do we need this when we are already emitting the existing data-structures? Unless the downstream understands this DS, emitting it is unnecessary.
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.
The CounterMeasurement
and GaugeMeasurement
are for existing mantis internal metrics. All micrometer metrics will be part of the MicrometerMeasurement
for now.
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.
looks good to me except for reverting metrics change in MasterMain and other minor suggestions/comments.
I'll approve and we can merge after addressing
.addCounter("masterInitError") | ||
.build(); | ||
Metrics m = MetricsRegistry.getInstance().registerAndGet(metrics); | ||
String groupName = "MasterMain"; |
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.
umm, I'd suggest not changing the metrics in this class to use micrometer just yet.
this.port = port; | ||
this.publishRateInSeconds = publishRateInSeconds; | ||
this.tags = tags; | ||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
mapper.registerModule(new Jdk8Module()); | ||
this.registry = registry; |
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.registry = registry; | |
this.micrometerRegistry = registry; |
@@ -53,41 +58,51 @@ public class MetricsServer { | |||
private int port; | |||
private Map<String, String> tags; | |||
private long publishRateInSeconds; | |||
private MeterRegistry registry; |
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.
private MeterRegistry registry; | |
private MeterRegistry micrometerRegistry; |
} | ||
|
||
private Observable<Measurements> measurements(long timeFrequency) { | ||
final MeterRegistry micrometerregistry = registry; |
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.
final MeterRegistry micrometerregistry = registry; |
List<Measurements> measurements = new ArrayList<>(); | ||
|
||
|
||
for (Meter meter: micrometerregistry.getMeters()) { |
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.
for (Meter meter: micrometerregistry.getMeters()) { | |
for (Meter meter: this.micrometerRegistry.getMeters()) { |
@@ -117,17 +120,16 @@ public class MasterMain implements Service { | |||
private MasterConfiguration config; | |||
private SchedulingService schedulingService; | |||
private ILeadershipManager leadershipManager; | |||
private final MeterRegistry registry; |
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.
private final MeterRegistry registry; | |
private final MeterRegistry micrometerRegistry; |
public MasterMain(ConfigurationFactory configFactory, AuditEventSubscriber auditEventSubscriber) { | ||
|
||
public MasterMain(ConfigurationFactory configFactory, AuditEventSubscriber auditEventSubscriber, MeterRegistry registry) { | ||
this.registry = registry; |
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.registry = registry; | |
this.micrometerRegistry = registry; |
Thank you, Harshit! Already updated. |
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.
Thanks for making this change. I really appreciate it.
I believe it's your first change for mantis OSS project. Kudos!
I'll take care of merging it in sometime.
@@ -41,6 +40,8 @@ dependencies { | |||
api libraries.slf4jLog4j12 | |||
implementation libraries.commonsIo | |||
implementation 'net.jcip:jcip-annotations:1.0' | |||
implementation libraries.micrometerCore | |||
implementation libraries.spectatorApi |
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.
Is this needed because we are dual publishing the metrics?
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.
Yes, the spectator library can be removed when all the metrics have been changed.
for (Meter meter: microRegistry.getMeters()) { | ||
Collection<MicrometerMeasurement> micrometers = new LinkedList<>(); | ||
micrometers.add(new MicrometerMeasurement(meter.getId().getType(), meter.measure().iterator().next().getValue())); | ||
measurements.add(new Measurements(meter.getId().getName(), timestamp, Collections.emptyList(), Collections.emptyList(), micrometers, tags)); |
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.
We are generating a measurement instance for every micrometer metric, even though measurements are supposed to consist of a collection of counters, timers, and other components for a specific group ID. Considering this, is the semantics of having a 1:1 relationship between the measurements instance and micrometer metric correct?
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.
Yes, it is correct.
public MasterMain(ConfigurationFactory configFactory, AuditEventSubscriber auditEventSubscriber, MeterRegistry micrometerRegistry) { | ||
this.micrometerRegistry = micrometerRegistry; |
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.
I think we can use the CompositeRegistry singleton here since this is the leaf node.
private final MeterRegistry registry; | ||
|
||
|
||
private LocalJobExecutorNetworked(MeterRegistry registry) { |
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.
We don't need the MeterRegistry in the constructor here since this is also a leaf node. This would avoid some of the other extraneous changes.
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.
LGTM, except for a few minor comments.
…rement> in MetricsServer
… then add the arg
eccb356
to
49b2ab2
Compare
Context
The result will show below, and I am still trying to flatten the measurement field. Wanna get some early feedback and advice.
`data: {"name":"httpServer-mantis-rxnetty-server-8487_requestBacklog","timestamp":1688354626236,"type":"GAUGE","model":"v2","measurement":"[Measurement{statistic='VALUE', value=0.0}]","tags":{}}
data: {"name":"httpServer-mantis-rxnetty-server-8487_failedRequests","timestamp":1688354626236,"type":"COUNTER","model":"v2","measurement":"[Measurement{statistic='COUNT', value=0.0}]","tags":{}}`
Checklist
./gradlew build
compiles code correctly./gradlew test
passes all tests