You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by "keith-turner (via GitHub)" <gi...@apache.org> on 2024/10/29 02:14:35 UTC
[PR] Simplifies metrics initialization [accumulo]
keith-turner opened a new pull request, #5021:
URL: https://github.com/apache/accumulo/pull/5021
The metrics initialization code supported adding registries prior to initialization, however nothing used this functionality. Simplified the code by removing support for pending registries. This simplification allowed avoiding using the composite metrics registry when there is only a single registry.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Simplifies metrics initialization [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner merged PR #5021:
URL: https://github.com/apache/accumulo/pull/5021
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Simplifies metrics initialization [accumulo]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #5021:
URL: https://github.com/apache/accumulo/pull/5021#discussion_r1820651445
##########
server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java:
##########
@@ -251,23 +206,42 @@ public DistributionStatisticConfig configure(Meter.Id id,
String userRegistryFactories =
context.getConfiguration().get(Property.GENERAL_MICROMETER_FACTORY);
+ List<MeterRegistry> registries = new ArrayList<>();
+
for (String factoryName : getTrimmedStrings(userRegistryFactories)) {
try {
MeterRegistry registry = getRegistryFromFactory(factoryName, context);
registry.config().commonTags(commonTags.values());
registry.config().meterFilter(replicationFilter);
- addRegistry(registry);
+ registries.add(registry);
} catch (ReflectiveOperationException ex) {
LOG.warn("Could not load registry {}", factoryName, ex);
}
}
- pendingRegistries.forEach(registry -> composite.add(registry));
+ if (registries.size() == 1) {
+ meterRegistry = registries.get(0);
+ } else {
+ var composite = new CompositeMeterRegistry();
+ composite.config().commonTags(commonTags.values());
+ registries.forEach(composite::add);
+ meterRegistry = composite;
+ }
+
+ if (jvmMetricsEnabled) {
+ LOG.info("enabling detailed jvm, classloader, jvm gc and process metrics");
+ new ClassLoaderMetrics().bindTo(meterRegistry);
+ new JvmMemoryMetrics().bindTo(meterRegistry);
+ jvmGcMetrics = new JvmGcMetrics();
+ jvmGcMetrics.bindTo(meterRegistry);
+ new ProcessorMetrics().bindTo(meterRegistry);
+ new JvmThreadMetrics().bindTo(meterRegistry);
+ }
LOG.info("Metrics initialization. Register producers: {}", producers);
- producers.forEach(p -> p.registerMetrics(composite));
+ producers.forEach(p -> p.registerMetrics(meterRegistry));
- Metrics.globalRegistry.add(composite);
+ Metrics.globalRegistry.add(meterRegistry);
Review Comment:
I'm wondering if we should just add each MeterRegistry to the global registry directly, and then call p.registerMetrics using the global registry. I'm not sure what benefit there is to using a composite registry in this code. If we were to do this, then I think we would want to add the user MeterRegistry's to the global first, then set up the JVM metrics and the MetricsProducers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Simplifies metrics initialization [accumulo]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #5021:
URL: https://github.com/apache/accumulo/pull/5021#discussion_r1820622084
##########
server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java:
##########
@@ -251,23 +206,42 @@ public DistributionStatisticConfig configure(Meter.Id id,
String userRegistryFactories =
context.getConfiguration().get(Property.GENERAL_MICROMETER_FACTORY);
+ List<MeterRegistry> registries = new ArrayList<>();
+
for (String factoryName : getTrimmedStrings(userRegistryFactories)) {
try {
MeterRegistry registry = getRegistryFromFactory(factoryName, context);
registry.config().commonTags(commonTags.values());
registry.config().meterFilter(replicationFilter);
- addRegistry(registry);
+ registries.add(registry);
} catch (ReflectiveOperationException ex) {
LOG.warn("Could not load registry {}", factoryName, ex);
}
}
- pendingRegistries.forEach(registry -> composite.add(registry));
+ if (registries.size() == 1) {
+ meterRegistry = registries.get(0);
+ } else {
+ var composite = new CompositeMeterRegistry();
+ composite.config().commonTags(commonTags.values());
+ registries.forEach(composite::add);
+ meterRegistry = composite;
Review Comment:
I noticed something interesting while working on #4993, but I have not dug into it further. [Metrics.globalRegistry](https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/instrument/Metrics.java#L36) itself is a CompositeMeterRegistry. Our code ends up creating the following structure:
```
-- CompositeMeterRegistry (Metrics.globalRegistry)
-- CompositeMeterRegistry (the one we create above)
-- LoggingMeterRegistry
-- Other user supplied MeterRegistry's
```
I don't think we need to create the second level CompositeMeterRegistry, I think we can just call `MeterRegistry.add` for each user supplied MeterRegistry. It's also the case that Meters are getting bound to registries at different places in the hierarchy. For example, #5006 shows that ThreadPool Meters are being bound to the top level global registry.
Finally, I think that the Property description changes that I made in #4993 are incorrect, but agagin, I have not tested this yet. I think that the current code disables the reporting of the Metrics, but not the collection of the Metrics in the Accumulo code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Simplifies metrics initialization [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5021:
URL: https://github.com/apache/accumulo/pull/5021#discussion_r1822794192
##########
server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java:
##########
@@ -180,98 +100,75 @@ public void addMetricsProducers(MetricsProducer... producer) {
"called addMetricsProducers() without providing at least one producer - this has no effect");
return;
}
- lock.lock();
- try {
- if (composite == null) {
- producers.addAll(Arrays.asList(producer));
- } else {
- Arrays.stream(producer).forEach(p -> p.registerMetrics(composite));
- }
- } finally {
- lock.unlock();
- }
- }
- @Override
- public MeterRegistry getRegistry() {
- lock.lock();
- try {
- if (composite == null) {
- throw new IllegalStateException("metrics have not been initialized, call init() first");
- }
- } finally {
- lock.unlock();
+ if (commonTags == null) {
+ producers.addAll(Arrays.asList(producer));
+ } else {
+ Arrays.stream(producer).forEach(p -> p.registerMetrics(Metrics.globalRegistry));
}
- return composite;
}
@Override
- public void init() {
+ public synchronized void init(Collection<Tag> tags) {
Review Comment:
I'll give that a try, if it works it would be a nice improvement.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Simplifies metrics initialization [accumulo]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #5021:
URL: https://github.com/apache/accumulo/pull/5021#discussion_r1821658159
##########
server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java:
##########
@@ -180,98 +100,75 @@ public void addMetricsProducers(MetricsProducer... producer) {
"called addMetricsProducers() without providing at least one producer - this has no effect");
return;
}
- lock.lock();
- try {
- if (composite == null) {
- producers.addAll(Arrays.asList(producer));
- } else {
- Arrays.stream(producer).forEach(p -> p.registerMetrics(composite));
- }
- } finally {
- lock.unlock();
- }
- }
- @Override
- public MeterRegistry getRegistry() {
- lock.lock();
- try {
- if (composite == null) {
- throw new IllegalStateException("metrics have not been initialized, call init() first");
- }
- } finally {
- lock.unlock();
+ if (commonTags == null) {
+ producers.addAll(Arrays.asList(producer));
+ } else {
+ Arrays.stream(producer).forEach(p -> p.registerMetrics(Metrics.globalRegistry));
}
- return composite;
}
@Override
- public void init() {
+ public synchronized void init(Collection<Tag> tags) {
Review Comment:
It looks like `addMetricsProducers` is almost always called before `init`. I wonder if we should just change `init` to `init(Collection<Tag> tags, MetricsProducer... producers)` and get rid of `addMetricProducers`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Simplifies metrics initialization [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5021:
URL: https://github.com/apache/accumulo/pull/5021#discussion_r1823355640
##########
server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java:
##########
@@ -180,98 +100,75 @@ public void addMetricsProducers(MetricsProducer... producer) {
"called addMetricsProducers() without providing at least one producer - this has no effect");
return;
}
- lock.lock();
- try {
- if (composite == null) {
- producers.addAll(Arrays.asList(producer));
- } else {
- Arrays.stream(producer).forEach(p -> p.registerMetrics(composite));
- }
- } finally {
- lock.unlock();
- }
- }
- @Override
- public MeterRegistry getRegistry() {
- lock.lock();
- try {
- if (composite == null) {
- throw new IllegalStateException("metrics have not been initialized, call init() first");
- }
- } finally {
- lock.unlock();
+ if (commonTags == null) {
+ producers.addAll(Arrays.asList(producer));
+ } else {
+ Arrays.stream(producer).forEach(p -> p.registerMetrics(Metrics.globalRegistry));
}
- return composite;
}
@Override
- public void init() {
+ public synchronized void init(Collection<Tag> tags) {
Review Comment:
Looked into it and there is once place that `addMetricsProducer` is called that is not close to the init code. That place is in the thrift code where some thrift metrics are added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Simplifies metrics initialization [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5021:
URL: https://github.com/apache/accumulo/pull/5021#discussion_r1821493309
##########
server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java:
##########
@@ -251,23 +206,42 @@ public DistributionStatisticConfig configure(Meter.Id id,
String userRegistryFactories =
context.getConfiguration().get(Property.GENERAL_MICROMETER_FACTORY);
+ List<MeterRegistry> registries = new ArrayList<>();
+
for (String factoryName : getTrimmedStrings(userRegistryFactories)) {
try {
MeterRegistry registry = getRegistryFromFactory(factoryName, context);
registry.config().commonTags(commonTags.values());
registry.config().meterFilter(replicationFilter);
- addRegistry(registry);
+ registries.add(registry);
} catch (ReflectiveOperationException ex) {
LOG.warn("Could not load registry {}", factoryName, ex);
}
}
- pendingRegistries.forEach(registry -> composite.add(registry));
+ if (registries.size() == 1) {
+ meterRegistry = registries.get(0);
+ } else {
+ var composite = new CompositeMeterRegistry();
+ composite.config().commonTags(commonTags.values());
+ registries.forEach(composite::add);
+ meterRegistry = composite;
Review Comment:
> I don't think we need to create the second level CompositeMeterRegistry, I think we can just call MeterRegistry.add for each user supplied MeterRegistry.
Made that update in 0f70a87aef5b383c4c564c7462e6298e615044eb. That change removes the double CompositeMeterRegistry. Also noticed there was functionality around common tags that was never used so removed that functionality in 0f70a87aef5b383c4c564c7462e6298e615044eb to simplify the code further.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Simplifies metrics initialization [accumulo]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #5021:
URL: https://github.com/apache/accumulo/pull/5021#discussion_r1820642506
##########
server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java:
##########
@@ -251,23 +206,42 @@ public DistributionStatisticConfig configure(Meter.Id id,
String userRegistryFactories =
context.getConfiguration().get(Property.GENERAL_MICROMETER_FACTORY);
+ List<MeterRegistry> registries = new ArrayList<>();
+
for (String factoryName : getTrimmedStrings(userRegistryFactories)) {
try {
MeterRegistry registry = getRegistryFromFactory(factoryName, context);
registry.config().commonTags(commonTags.values());
registry.config().meterFilter(replicationFilter);
- addRegistry(registry);
+ registries.add(registry);
} catch (ReflectiveOperationException ex) {
LOG.warn("Could not load registry {}", factoryName, ex);
}
}
- pendingRegistries.forEach(registry -> composite.add(registry));
+ if (registries.size() == 1) {
+ meterRegistry = registries.get(0);
+ } else {
+ var composite = new CompositeMeterRegistry();
+ composite.config().commonTags(commonTags.values());
+ registries.forEach(composite::add);
+ meterRegistry = composite;
Review Comment:
I dug into this a little bit, and I think that metrics are *not* collected as long as we don't set a MeterRegistry on the global one. Reason being that the global registry is a CompositeMeterRegistry, and when a Meter is created on a CompositeMeterRegistry, it creates it on the first child MeterRegistry. If there is not one, then it uses a NoopMeter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org