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/11/02 20:46:29 UTC
[PR] adds optional per table metrics [accumulo]
keith-turner opened a new pull request, #5030:
URL: https://github.com/apache/accumulo/pull/5030
For a subset of metrics in the tablet server and scan server adds optional tableId tags to meters. In a follow on change the compactor could be updated to emit per table metrics, however its current code is very process oriented and this change should be in its own commit.
Each server process will automatically remove meters for tables that were delete or related to tables it has not been servicing in a while.
closes #4511
--
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] adds optional per table metrics [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on PR #5030:
URL: https://github.com/apache/accumulo/pull/5030#issuecomment-2455132260
The static analysis checks in the build had a really good find. Found a bug where I forgot check the future for the scheduled task.
```
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project accumulo-server-base: Compilation failure
[ERROR] /home/runner/work/accumulo/accumulo/server/base/src/main/java/org/apache/accumulo/server/metrics/PerTableMetrics.java:[81,56] error: [FutureReturnValueIgnored] Return value of methods returning Future must be checked. Ignoring returned Futures suppresses exceptions thrown from the code that completes the Future.
[ERROR] (see https://errorprone.info/bugpattern/FutureReturnValueIgnored)
[ERROR] Did you mean 'var unused = context.getScheduledExecutor().scheduleAtFixedRate(this::refresh, 30, 30, TimeUnit.SECONDS);' or to remove this line?
[ERROR]
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project accumulo-server-base: Compilation failure
```
--
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] adds optional per table metrics [accumulo]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on PR #5030:
URL: https://github.com/apache/accumulo/pull/5030#issuecomment-6043022767
Another option would be to allow the user to list in a property the namespaces or table names for which they want table metrics emitted. By default this might be empty, but with a property this would allow the user to opt-in to tag cardinality issues.
--
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] adds optional per table metrics [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5030:
URL: https://github.com/apache/accumulo/pull/5030#discussion_r1827993358
##########
server/base/src/main/java/org/apache/accumulo/server/metrics/PerTableMetrics.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.server.metrics;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.manager.state.tables.TableState;
+import org.apache.accumulo.core.metrics.MetricsProducer;
+import org.apache.accumulo.core.util.Timer;
+import org.apache.accumulo.server.ServerContext;
+import org.slf4j.Logger;
+
+import com.google.common.base.Preconditions;
+
+import io.micrometer.core.instrument.Meter;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tag;
+
+/**
+ * Common code for dealing with per table metrics. This code handles automatically creating and
+ * deleting per table metrics as needed. To use this class extend and implement
+ * {@link #newAllTablesMetrics(MeterRegistry, Consumer, List)} and
+ * {@link #newPerTableMetrics(MeterRegistry, TableId, Consumer, List)} to create per table metrics
+ * object and then use {@link #getTableMetrics(TableId)} to get those cached objects.
+ */
+public abstract class PerTableMetrics<T> implements MetricsProducer {
+
+ public static final String TABLE_ID_TAG_NAME = "tableId";
+
+ private final ServerContext context;
+
+ private static class TableMetricsInfo<T2> {
+ final T2 tableMetrics;
+ volatile Timer inactiveTime;
+ final List<Meter> meters;
+
+ public TableMetricsInfo(T2 tableMetrics, List<Meter> meters) {
+ this.tableMetrics = Objects.requireNonNull(tableMetrics);
+ this.meters = meters;
+ }
+ }
+
+ private final boolean perTableActive;
+ private final Supplier<Set<TableId>> activeTables;
+ private final ConcurrentHashMap<TableId,TableMetricsInfo<T>> perTableMetrics =
+ new ConcurrentHashMap<>();
+ private T allTableMetrics;
+ private volatile MeterRegistry registry;
+
+ public PerTableMetrics(ServerContext context, Supplier<Set<TableId>> activeTableSupplier) {
+ activeTables = activeTableSupplier;
+ perTableActive =
+ context.getConfiguration().getBoolean(Property.GENERAL_MICROMETER_TABLE_METRICS_ENABLED);
+ this.context = context;
+ if (perTableActive) {
+ context.getScheduledExecutor().scheduleAtFixedRate(this::refresh, 30, 30, TimeUnit.SECONDS);
+ }
+ }
+
+ /**
+ * This method exist so this class can log using the logger of the subclass.
+ */
+ protected abstract Logger getLog();
+
+ /**
+ * Subclasses should implement this method to create a TableMetrics object that will be used in
+ * the case when per table metrics are disabled. The object returned by this method will alway be
+ * returned by {@link #getTableMetrics(TableId)} no matter what the table id is.
+ *
+ * @param registry register an meters for the table metrics in this registry
+ * @param meters a consumer that accepts meters to be removed from the registry when the table
+ * metrics object is discarded. Currently this consumer does nothing with the meters, its
+ * passed for consistency with
+ * {@link #newPerTableMetrics(MeterRegistry, TableId, Consumer, List)}
+ * @param tags currently an empty collection of tags, this is passed for consistency with
+ * {@link #PerTableMetrics(ServerContext, Supplier)}
+ * @return a new object that will be cached and later returned by
+ * {@link #getTableMetrics(TableId)}
+ */
+ protected abstract T newAllTablesMetrics(MeterRegistry registry, Consumer<Meter> meters,
+ List<Tag> tags);
+
+ /**
+ *
+ * Subclasses should implement this method to create per table table metrics objects. This method
+ * is called in the case where per table metrics are enabled. These objects will be cached and
+ * returned by {@link #getTableMetrics(TableId)}. Table metrics object in the cache that are no
+ * longer needed will be automatically removed when the table is deleted or this server has not
+ * hosted the table for a bit.
+ *
+ * @param registry register an meters for the table metrics in this registry
+ * @param meters a consumer that accepts meters to be removed from the registry when the per table
+ * metrics object is discarded.
+ * @param tags returns a list with a single tag in it which is the tableId. These tags should be
+ * used when registering meters
+ * @return a new object that will be cached and later returned by
+ * {@link #getTableMetrics(TableId)}
+ */
+ protected abstract T newPerTableMetrics(MeterRegistry registry, TableId tableId,
+ Consumer<Meter> meters, List<Tag> tags);
+
+ private TableMetricsInfo<T> getOrCreateTableMetrics(TableId tableId) {
+ Preconditions.checkState(perTableActive);
+ return perTableMetrics.computeIfAbsent(tableId, tid -> {
+ List<Meter> meters = new ArrayList<>();
+ T tableMetrics = newPerTableMetrics(registry, tableId, meters::add,
+ List.of(Tag.of(TABLE_ID_TAG_NAME, tid.canonical())));
+ getLog().debug("Created {} meters for table id {} in metrics registry.", meters.size(),
+ tableId);
+ return new TableMetricsInfo<>(tableMetrics, meters);
+ });
+ }
+
+ public void registerMetrics(MeterRegistry registry) {
+ Preconditions.checkState(this.registry == null);
+ this.registry = registry;
+ if (!perTableActive) {
+ this.allTableMetrics = newAllTablesMetrics(registry, m -> {}, List.of());
+ }
+ }
+
+ public T getTableMetrics(TableId tableId) {
+ Preconditions.checkState(registry != null);
+
+ if (!perTableActive) {
+ return allTableMetrics;
+ }
+
+ return getOrCreateTableMetrics(tableId).tableMetrics;
+ }
+
+ /**
+ * This method will create per table metrics for any tables that are active on this server and
+ * currently have no table metrics object in the cache. It will also remove an per table metrics
+ * object from the cache that have been inactive for a while or where the table was deleted.
+ */
+ public synchronized void refresh() {
Review Comment:
It probably would be better to do that for all cases. Its only being done for the tablet server on tablet load for this method. The three other cases you mentioned are not done.
For the scan server I could not find a good place to register on tablet load, I will circle back and see what I can find. For now its probably ok that scan server does not register on load because it has no gauges, so when a scan happen it will touch meters which will load metrics. However that is shaky ground, if gauges were ever used then those may not be loaded until the timer task kicks in. Would also be good to push code to TabletHostingServer so that the metrics code can interact w/ the same code for each server type.
If all 4 cases are covered with callbacks then we could run the timer task less frequently. For the unload case I was completely leaving that to the timer task to catch.
--
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] adds optional per table metrics [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5030:
URL: https://github.com/apache/accumulo/pull/5030#discussion_r1828542110
##########
server/base/src/main/java/org/apache/accumulo/server/metrics/PerTableMetrics.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.server.metrics;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.manager.state.tables.TableState;
+import org.apache.accumulo.core.metrics.MetricsProducer;
+import org.apache.accumulo.core.util.Timer;
+import org.apache.accumulo.server.ServerContext;
+import org.slf4j.Logger;
+
+import com.google.common.base.Preconditions;
+
+import io.micrometer.core.instrument.Meter;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tag;
+
+/**
+ * Common code for dealing with per table metrics. This code handles automatically creating and
+ * deleting per table metrics as needed. To use this class extend and implement
+ * {@link #newAllTablesMetrics(MeterRegistry, Consumer, List)} and
+ * {@link #newPerTableMetrics(MeterRegistry, TableId, Consumer, List)} to create per table metrics
+ * object and then use {@link #getTableMetrics(TableId)} to get those cached objects.
+ */
+public abstract class PerTableMetrics<T> implements MetricsProducer {
+
+ public static final String TABLE_ID_TAG_NAME = "tableId";
+
+ private final ServerContext context;
+
+ private static class TableMetricsInfo<T2> {
+ final T2 tableMetrics;
+ volatile Timer inactiveTime;
+ final List<Meter> meters;
+
+ public TableMetricsInfo(T2 tableMetrics, List<Meter> meters) {
+ this.tableMetrics = Objects.requireNonNull(tableMetrics);
+ this.meters = meters;
+ }
+ }
+
+ private final boolean perTableActive;
+ private final Supplier<Set<TableId>> activeTables;
+ private final ConcurrentHashMap<TableId,TableMetricsInfo<T>> perTableMetrics =
+ new ConcurrentHashMap<>();
+ private T allTableMetrics;
+ private volatile MeterRegistry registry;
+
+ public PerTableMetrics(ServerContext context, Supplier<Set<TableId>> activeTableSupplier) {
+ activeTables = activeTableSupplier;
+ perTableActive =
+ context.getConfiguration().getBoolean(Property.GENERAL_MICROMETER_TABLE_METRICS_ENABLED);
+ this.context = context;
+ if (perTableActive) {
+ context.getScheduledExecutor().scheduleAtFixedRate(this::refresh, 30, 30, TimeUnit.SECONDS);
+ }
+ }
+
+ /**
+ * This method exist so this class can log using the logger of the subclass.
+ */
+ protected abstract Logger getLog();
+
+ /**
+ * Subclasses should implement this method to create a TableMetrics object that will be used in
+ * the case when per table metrics are disabled. The object returned by this method will alway be
+ * returned by {@link #getTableMetrics(TableId)} no matter what the table id is.
+ *
+ * @param registry register an meters for the table metrics in this registry
+ * @param meters a consumer that accepts meters to be removed from the registry when the table
+ * metrics object is discarded. Currently this consumer does nothing with the meters, its
+ * passed for consistency with
+ * {@link #newPerTableMetrics(MeterRegistry, TableId, Consumer, List)}
+ * @param tags currently an empty collection of tags, this is passed for consistency with
+ * {@link #PerTableMetrics(ServerContext, Supplier)}
+ * @return a new object that will be cached and later returned by
+ * {@link #getTableMetrics(TableId)}
+ */
+ protected abstract T newAllTablesMetrics(MeterRegistry registry, Consumer<Meter> meters,
+ List<Tag> tags);
+
+ /**
+ *
+ * Subclasses should implement this method to create per table table metrics objects. This method
+ * is called in the case where per table metrics are enabled. These objects will be cached and
+ * returned by {@link #getTableMetrics(TableId)}. Table metrics object in the cache that are no
+ * longer needed will be automatically removed when the table is deleted or this server has not
+ * hosted the table for a bit.
+ *
+ * @param registry register an meters for the table metrics in this registry
+ * @param meters a consumer that accepts meters to be removed from the registry when the per table
+ * metrics object is discarded.
+ * @param tags returns a list with a single tag in it which is the tableId. These tags should be
+ * used when registering meters
+ * @return a new object that will be cached and later returned by
+ * {@link #getTableMetrics(TableId)}
+ */
+ protected abstract T newPerTableMetrics(MeterRegistry registry, TableId tableId,
+ Consumer<Meter> meters, List<Tag> tags);
+
+ private TableMetricsInfo<T> getOrCreateTableMetrics(TableId tableId) {
+ Preconditions.checkState(perTableActive);
+ return perTableMetrics.computeIfAbsent(tableId, tid -> {
+ List<Meter> meters = new ArrayList<>();
+ T tableMetrics = newPerTableMetrics(registry, tableId, meters::add,
+ List.of(Tag.of(TABLE_ID_TAG_NAME, tid.canonical())));
+ getLog().debug("Created {} meters for table id {} in metrics registry.", meters.size(),
+ tableId);
+ return new TableMetricsInfo<>(tableMetrics, meters);
+ });
+ }
+
+ public void registerMetrics(MeterRegistry registry) {
+ Preconditions.checkState(this.registry == null);
+ this.registry = registry;
+ if (!perTableActive) {
+ this.allTableMetrics = newAllTablesMetrics(registry, m -> {}, List.of());
+ }
+ }
+
+ public T getTableMetrics(TableId tableId) {
+ Preconditions.checkState(registry != null);
+
+ if (!perTableActive) {
+ return allTableMetrics;
+ }
+
+ return getOrCreateTableMetrics(tableId).tableMetrics;
+ }
+
+ /**
+ * This method will create per table metrics for any tables that are active on this server and
+ * currently have no table metrics object in the cache. It will also remove an per table metrics
+ * object from the cache that have been inactive for a while or where the table was deleted.
+ */
+ public synchronized void refresh() {
Review Comment:
Made some changes related to this in afa401f. Was able to optimize and centralize the code for detecting changes in the set of table ids. Using those changes could efficiently handle a tablet being loaded and detect if anything needed to be done. However for the case of a tablet being unloaded found that is hard to handle that efficiently because when one tablet is unloaded other tablet may still have that same tablet id, so need to scan all tablets on each tablet unload to see if anything needs to be done. Decided not to do anything for this case and leave it to the periodic timer task. Was able to centralize that timer task and make it more efficient though.
--
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] adds optional per table metrics [accumulo]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #5030:
URL: https://github.com/apache/accumulo/pull/5030#discussion_r1827679310
##########
server/base/src/main/java/org/apache/accumulo/server/metrics/PerTableMetrics.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.server.metrics;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.manager.state.tables.TableState;
+import org.apache.accumulo.core.metrics.MetricsProducer;
+import org.apache.accumulo.core.util.Timer;
+import org.apache.accumulo.server.ServerContext;
+import org.slf4j.Logger;
+
+import com.google.common.base.Preconditions;
+
+import io.micrometer.core.instrument.Meter;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tag;
+
+/**
+ * Common code for dealing with per table metrics. This code handles automatically creating and
+ * deleting per table metrics as needed. To use this class extend and implement
+ * {@link #newAllTablesMetrics(MeterRegistry, Consumer, List)} and
+ * {@link #newPerTableMetrics(MeterRegistry, TableId, Consumer, List)} to create per table metrics
+ * object and then use {@link #getTableMetrics(TableId)} to get those cached objects.
+ */
+public abstract class PerTableMetrics<T> implements MetricsProducer {
+
+ public static final String TABLE_ID_TAG_NAME = "tableId";
+
+ private final ServerContext context;
+
+ private static class TableMetricsInfo<T2> {
+ final T2 tableMetrics;
+ volatile Timer inactiveTime;
+ final List<Meter> meters;
+
+ public TableMetricsInfo(T2 tableMetrics, List<Meter> meters) {
+ this.tableMetrics = Objects.requireNonNull(tableMetrics);
+ this.meters = meters;
+ }
+ }
+
+ private final boolean perTableActive;
+ private final Supplier<Set<TableId>> activeTables;
+ private final ConcurrentHashMap<TableId,TableMetricsInfo<T>> perTableMetrics =
+ new ConcurrentHashMap<>();
+ private T allTableMetrics;
+ private volatile MeterRegistry registry;
+
+ public PerTableMetrics(ServerContext context, Supplier<Set<TableId>> activeTableSupplier) {
+ activeTables = activeTableSupplier;
+ perTableActive =
+ context.getConfiguration().getBoolean(Property.GENERAL_MICROMETER_TABLE_METRICS_ENABLED);
+ this.context = context;
+ if (perTableActive) {
+ context.getScheduledExecutor().scheduleAtFixedRate(this::refresh, 30, 30, TimeUnit.SECONDS);
+ }
+ }
+
+ /**
+ * This method exist so this class can log using the logger of the subclass.
+ */
+ protected abstract Logger getLog();
+
+ /**
+ * Subclasses should implement this method to create a TableMetrics object that will be used in
+ * the case when per table metrics are disabled. The object returned by this method will alway be
+ * returned by {@link #getTableMetrics(TableId)} no matter what the table id is.
+ *
+ * @param registry register an meters for the table metrics in this registry
+ * @param meters a consumer that accepts meters to be removed from the registry when the table
+ * metrics object is discarded. Currently this consumer does nothing with the meters, its
+ * passed for consistency with
+ * {@link #newPerTableMetrics(MeterRegistry, TableId, Consumer, List)}
+ * @param tags currently an empty collection of tags, this is passed for consistency with
+ * {@link #PerTableMetrics(ServerContext, Supplier)}
+ * @return a new object that will be cached and later returned by
+ * {@link #getTableMetrics(TableId)}
+ */
+ protected abstract T newAllTablesMetrics(MeterRegistry registry, Consumer<Meter> meters,
+ List<Tag> tags);
+
+ /**
+ *
+ * Subclasses should implement this method to create per table table metrics objects. This method
+ * is called in the case where per table metrics are enabled. These objects will be cached and
+ * returned by {@link #getTableMetrics(TableId)}. Table metrics object in the cache that are no
+ * longer needed will be automatically removed when the table is deleted or this server has not
+ * hosted the table for a bit.
+ *
+ * @param registry register an meters for the table metrics in this registry
+ * @param meters a consumer that accepts meters to be removed from the registry when the per table
+ * metrics object is discarded.
+ * @param tags returns a list with a single tag in it which is the tableId. These tags should be
+ * used when registering meters
+ * @return a new object that will be cached and later returned by
+ * {@link #getTableMetrics(TableId)}
+ */
+ protected abstract T newPerTableMetrics(MeterRegistry registry, TableId tableId,
+ Consumer<Meter> meters, List<Tag> tags);
+
+ private TableMetricsInfo<T> getOrCreateTableMetrics(TableId tableId) {
+ Preconditions.checkState(perTableActive);
+ return perTableMetrics.computeIfAbsent(tableId, tid -> {
+ List<Meter> meters = new ArrayList<>();
+ T tableMetrics = newPerTableMetrics(registry, tableId, meters::add,
+ List.of(Tag.of(TABLE_ID_TAG_NAME, tid.canonical())));
+ getLog().debug("Created {} meters for table id {} in metrics registry.", meters.size(),
+ tableId);
+ return new TableMetricsInfo<>(tableMetrics, meters);
+ });
+ }
+
+ public void registerMetrics(MeterRegistry registry) {
+ Preconditions.checkState(this.registry == null);
+ this.registry = registry;
+ if (!perTableActive) {
+ this.allTableMetrics = newAllTablesMetrics(registry, m -> {}, List.of());
+ }
+ }
+
+ public T getTableMetrics(TableId tableId) {
+ Preconditions.checkState(registry != null);
+
+ if (!perTableActive) {
+ return allTableMetrics;
+ }
+
+ return getOrCreateTableMetrics(tableId).tableMetrics;
+ }
+
+ /**
+ * This method will create per table metrics for any tables that are active on this server and
+ * currently have no table metrics object in the cache. It will also remove an per table metrics
+ * object from the cache that have been inactive for a while or where the table was deleted.
+ */
+ public synchronized void refresh() {
Review Comment:
I'm curious if it might be better to evaluate whether per table metrics should be added or removed when a tablet is hosted or unhosted in the ScanServer and TabletServer. There are explicit mechanisms in the TabletServer for hosting and unhosting tablets. In the ScanServer we have the TabletMetadataLoader for hosting a tablet, and we could add an [evictionListener](https://github.com/ben-manes/caffeine/wiki/Removal) to the tabletMetadataCache to handle a tablet removal. Thoughts on that?
--
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] adds optional per table metrics [accumulo]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #5030:
URL: https://github.com/apache/accumulo/pull/5030#discussion_r1844499060
##########
server/base/src/main/java/org/apache/accumulo/server/metrics/PerTableMetrics.java:
##########
@@ -0,0 +1,297 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.server.metrics;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.manager.state.tables.TableState;
+import org.apache.accumulo.core.metrics.MetricsProducer;
+import org.apache.accumulo.core.util.Timer;
+import org.apache.accumulo.core.util.threads.ThreadPools;
+import org.apache.accumulo.server.ServerContext;
+import org.slf4j.Logger;
+
+import com.google.common.base.Preconditions;
+
+import io.micrometer.core.instrument.Meter;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tag;
+
+/**
+ * Common code for dealing with per table metrics. This code handles automatically creating and
+ * deleting per table metrics as needed. To use this class extend and implement
+ * {@link #newAllTablesMetrics(MeterRegistry, Consumer, List)} and
+ * {@link #newPerTableMetrics(MeterRegistry, TableId, Consumer, List)} to create per table metrics
+ * object and then use {@link #getTableMetrics(TableId)} to get those cached objects.
+ */
+public abstract class PerTableMetrics<T> implements MetricsProducer {
+
+ public static final String TABLE_ID_TAG_NAME = "tableId";
+
+ private final ServerContext context;
+
+ private static class TableMetricsInfo<T2> {
+ final T2 tableMetrics;
+ volatile Timer inactiveTime;
+ final List<Meter> meters;
+
+ public TableMetricsInfo(T2 tableMetrics, List<Meter> meters) {
+ this.tableMetrics = Objects.requireNonNull(tableMetrics);
+ this.meters = meters;
+ }
+ }
+
+ private final ActiveTableIdTracker activeTableIdTracker;
+ private final ConcurrentHashMap<TableId,TableMetricsInfo<T>> perTableMetrics =
+ new ConcurrentHashMap<>();
+ private T allTableMetrics;
+ private volatile MeterRegistry registry;
+
+ /**
+ * Tracks the active set of table ids in a scan server or tablet server for the purpose of per
+ * table metrics.
+ *
+ * <p>
+ * Each tablet or scan server should create a single instance of this object and pass it to all
+ * {@link PerTableMetrics} objects.
+ * </p>
+ *
+ * <p>
+ * This class does not offer a tabletUnloaded method because there is no efficient way to compute
+ * this. For more detail see {@link #tabletLoaded(KeyExtent)}
+ * </p>
+ *
+ */
+ public static class ActiveTableIdTracker {
+
+ private final List<PerTableMetrics<?>> listeners = new ArrayList<>();
+ private final Supplier<Set<TableId>> activeTableSupplier;
+ private final AtomicReference<Set<TableId>> currentTableIds;
+ private final boolean perTableActive;
+
+ /**
+ * @param activeTableSupplier this supplier should always return the latest set of table ids
+ * that exist on the server. This class will take care of caching that set.
+ */
+ public ActiveTableIdTracker(ServerContext context, Supplier<Set<TableId>> activeTableSupplier) {
+ this.activeTableSupplier = activeTableSupplier;
+ this.perTableActive =
+ context.getConfiguration().getBoolean(Property.GENERAL_MICROMETER_TABLE_METRICS_ENABLED);
+ if (perTableActive) {
+ // The scan server and tablets servers will make a best effort attempt to call tabletLoaded,
+ // but may not always because of exceptions. This periodic task will ensure changes in the
+ // active set of tableIds are seen. It also handles cleanup of tablet unload for which there
+ // is no explicit notification.
+ var future = context.getScheduledExecutor()
+ .scheduleAtFixedRate(this::checkIfTableIdsChanged, 30, 30, TimeUnit.SECONDS);
+ ThreadPools.watchCriticalScheduledTask(future);
+ }
+ this.currentTableIds = new AtomicReference<>(Set.of());
+ }
+
+ private synchronized void addChangeListener(PerTableMetrics<?> listener) {
+ if (perTableActive) {
+ listeners.add(listener);
+ }
+ }
+
+ private synchronized void checkIfTableIdsChanged() {
+ if (!perTableActive) {
+ return;
+ }
+
+ var latest = activeTableSupplier.get();
+ if (!latest.equals(currentTableIds.get())) {
+ currentTableIds.set(Set.copyOf(latest));
+ listeners.forEach(listener -> listener.refresh(latest));
+ }
+ }
+
+ /**
+ * If the table id for this tablet is not being tracked will notify all per table metrics
+ * implementations of the new table.
+ *
+ * <p>
+ * There is no corresponding tableUnloaded method because implementing it would be inefficient.
+ * When a scan server computes the set of table ids it iterates over all tablets. When a tablet
+ * is unloaded a scan server it could still have other tablets for the same table. On each
+ * tablet unload do not want to iterator over all other tablets to see if the table id is still
+ * active, which is what the implementation of tableUnloaded would do.
+ */
+ public void tabletLoaded(KeyExtent extent) {
+ if (perTableActive && !currentTableIds.get().contains(extent.tableId())) {
+ checkIfTableIdsChanged();
+ }
+ }
+
+ // This method avoids locking unless a table id is unknown. This is important because every scan
+ // on a scan server will call it and locking would introduce thread contention.
+ public void tabletsLoaded(Set<KeyExtent> extents) {
+ if (perTableActive) {
+ var currentSnapshot = currentTableIds.get();
+ for (var extent : extents) {
+ if (!currentSnapshot.contains(extent.tableId())) {
+ checkIfTableIdsChanged();
+ break;
+ }
+ }
+ }
+ }
+
+ public boolean isPerTableMetricsEnabled() {
+ return perTableActive;
+ }
+
+ }
+
+ public PerTableMetrics(ServerContext context, ActiveTableIdTracker activeTableIdTracker) {
+ this.context = context;
+ this.activeTableIdTracker = activeTableIdTracker;
+ this.activeTableIdTracker.addChangeListener(this);
+ }
+
+ /**
+ * This method exist so this class can log using the logger of the subclass.
+ */
+ protected abstract Logger getLog();
+
+ /**
+ * Subclasses should implement this method to create a TableMetrics object that will be used in
+ * the case when per table metrics are disabled. The object returned by this method will alway be
+ * returned by {@link #getTableMetrics(TableId)} no matter what the table id is.
+ *
+ * @param registry register an meters for the table metrics in this registry
+ * @param meters a consumer that accepts meters to be removed from the registry when the table
+ * metrics object is discarded. Currently this consumer does nothing with the meters, its
+ * passed for consistency with
+ * {@link #newPerTableMetrics(MeterRegistry, TableId, Consumer, List)}
+ * @param tags currently an empty collection of tags, this is passed for consistency with
+ * {@link #newPerTableMetrics(MeterRegistry, TableId, Consumer, List)}
+ * @return a new object that will be cached and later returned by
+ * {@link #getTableMetrics(TableId)}
+ */
+ protected abstract T newAllTablesMetrics(MeterRegistry registry, Consumer<Meter> meters,
+ List<Tag> tags);
+
+ /**
+ *
+ * Subclasses should implement this method to create per table table metrics objects. This method
+ * is called in the case where per table metrics are enabled. These objects will be cached and
+ * returned by {@link #getTableMetrics(TableId)}. Table metrics object in the cache that are no
+ * longer needed will be automatically removed when the table is deleted or this server has not
+ * hosted the table for a bit.
+ *
+ * @param registry register an meters for the table metrics in this registry
+ * @param meters a consumer that accepts meters to be removed from the registry when the per table
+ * metrics object is discarded.
+ * @param tags returns a list with a single tag in it which is the tableId. These tags should be
+ * used when registering meters
+ * @return a new object that will be cached and later returned by
+ * {@link #getTableMetrics(TableId)}
+ */
+ protected abstract T newPerTableMetrics(MeterRegistry registry, TableId tableId,
+ Consumer<Meter> meters, List<Tag> tags);
+
+ private TableMetricsInfo<T> getOrCreateTableMetrics(TableId tableId) {
+ Preconditions.checkState(activeTableIdTracker.isPerTableMetricsEnabled());
+ return perTableMetrics.computeIfAbsent(tableId, tid -> {
+ List<Meter> meters = new ArrayList<>();
+ T tableMetrics = newPerTableMetrics(registry, tableId, meters::add,
+ List.of(Tag.of(TABLE_ID_TAG_NAME, tid.canonical())));
Review Comment:
I'm thinking it might be more useful that have a tableName tag and use the table name instead of the tableId.
--
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] adds optional per table metrics [accumulo]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #5030:
URL: https://github.com/apache/accumulo/pull/5030#discussion_r1847100531
##########
server/tserver/src/main/java/org/apache/accumulo/tserver/metrics/TabletServerMetrics.java:
##########
@@ -63,8 +81,55 @@ private long getTotalEntriesWritten() {
return FileCompactor.getTotalEntriesWritten();
}
+ public static class TableMetrics {
Review Comment:
I did some digging to see if Micrometer had any support for dynamic tags. I found https://github.com/micrometer-metrics/micrometer/pull/4097, which essentially allows you to create templates for Meters, then these get registered when you supply the tags. I'm wondering if you had seen this, and if not, if it would change your implementation here. I'm thinking we could create the templates (MeterProvider in Micrometer) when the servers start up, then just apply and remove based on the table id tags.
##########
pom.xml:
##########
@@ -169,7 +169,7 @@
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-bom</artifactId>
- <version>1.12.2</version>
+ <version>1.13.6</version>
Review Comment:
FYI that some things will have to change down in the accumulo-testing Terraform contrib code when this is merged due to the version change.
--
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] adds optional per table metrics [accumulo]
Posted by "dtspence (via GitHub)" <gi...@apache.org>.
dtspence commented on PR #5030:
URL: https://github.com/apache/accumulo/pull/5030#issuecomment-6047776165
@dlmarion A few additional options for consideration:
- By default any `accumulo.*` tables are enabled.
- Tables are by default included, but exclusions can constrain cardinality.
- Allow configuration of inclusion/exclusion filter.
These may be too expansive, was considering default/no-configuration behavior.
--
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