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

MetricsServer v2 #469

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

MetricsServer v2 #469

wants to merge 14 commits into from

Conversation

7ue5wu
Copy link

@7ue5wu 7ue5wu commented Jul 3, 2023

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
  • Added new tests where applicable
  • ./gradlew test passes all tests
  • Extended README or added javadocs where applicable

private Observable<Measurements> measurements(long timeFrequency) {
final MetricsRegistry registry = MetricsRegistry.getInstance();
private Observable<MicrometerMeasurements> measurements(long timeFrequency) {
final MeterRegistry registry = Metrics.globalRegistry;
Copy link
Collaborator

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()) {
Copy link
Collaborator

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
Copy link
Collaborator

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 {
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 a good change, umm, minor thing if I may suggest is to create it as a separate class similar to GaugeMeasurement

@7ue5wu 7ue5wu had a problem deploying to Integrate Pull Request July 12, 2023 00:17 — with GitHub Actions Failure
Copy link
Collaborator

@hmitnflx hmitnflx left a 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));
Copy link
Collaborator

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

Copy link
Author

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));
Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

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

Already updated.

compileOnly libraries.spectatorApi
implementation libraries.spectatorApi
Copy link
Contributor

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?

Copy link
Author

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.

@@ -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'
Copy link
Contributor

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.

Copy link
Author

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;
Copy link
Contributor

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?

Copy link
Author

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Collaborator

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,
Copy link
Contributor

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.

Copy link
Collaborator

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.

@7ue5wu 7ue5wu had a problem deploying to Integrate Pull Request July 13, 2023 14:53 — with GitHub Actions Failure
@7ue5wu 7ue5wu had a problem deploying to Integrate Pull Request July 15, 2023 21:17 — with GitHub Actions Failure
@7ue5wu 7ue5wu had a problem deploying to Integrate Pull Request July 17, 2023 22:48 — with GitHub Actions Failure
@7ue5wu 7ue5wu had a problem deploying to Integrate Pull Request July 18, 2023 00:09 — with GitHub Actions Failure
Copy link
Collaborator

@hmitnflx hmitnflx left a 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";
Copy link
Collaborator

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;
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.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;
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
private MeterRegistry registry;
private MeterRegistry micrometerRegistry;

}

private Observable<Measurements> measurements(long timeFrequency) {
final MeterRegistry micrometerregistry = registry;
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
final MeterRegistry micrometerregistry = registry;

List<Measurements> measurements = new ArrayList<>();


for (Meter meter: micrometerregistry.getMeters()) {
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
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;
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
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;
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.registry = registry;
this.micrometerRegistry = registry;

@7ue5wu 7ue5wu had a problem deploying to Integrate Pull Request July 18, 2023 00:32 — with GitHub Actions Failure
@7ue5wu 7ue5wu had a problem deploying to Integrate Pull Request July 18, 2023 00:42 — with GitHub Actions Failure
@7ue5wu
Copy link
Author

7ue5wu commented Jul 18, 2023

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

Thank you, Harshit! Already updated.

Copy link
Collaborator

@hmitnflx hmitnflx left a 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
Copy link
Contributor

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?

Copy link
Author

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));
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it is correct.

Comment on lines +125 to +128
public MasterMain(ConfigurationFactory configFactory, AuditEventSubscriber auditEventSubscriber, MeterRegistry micrometerRegistry) {
this.micrometerRegistry = micrometerRegistry;
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor

@sundargates sundargates left a 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.

@github-actions
Copy link

github-actions bot commented Sep 5, 2023

Test Results

0 files   - 128  0 suites   - 128   0s ⏱️ - 7m 15s
0 tests  - 545  0 ✔️  - 536  0 💤  - 8  0  - 1 
0 runs   - 546  0 ✔️  - 537  0 💤  - 8  0  - 1 

Results for commit 32b27e3. ± Comparison against base commit 2b1ad2d.

♻️ This comment has been updated with latest results.

@hmitnflx hmitnflx had a problem deploying to Integrate Pull Request October 23, 2023 20:29 — with GitHub Actions Failure
@hmitnflx hmitnflx had a problem deploying to Integrate Pull Request October 23, 2023 21:07 — 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

3 participants