keith-turner commented on code in PR #3551: URL: https://github.com/apache/accumulo/pull/3551#discussion_r1261640397
########## server/manager/src/main/java/org/apache/accumulo/manager/metrics/QueueMetrics.java: ########## @@ -0,0 +1,95 @@ +/* + * 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.manager.metrics; + +import static org.apache.accumulo.core.metrics.MetricsUtil.formatString; +import static org.apache.accumulo.core.metrics.MetricsUtil.getCommonTags; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + +import org.apache.accumulo.core.metrics.MetricsProducer; +import org.apache.accumulo.core.spi.compaction.CompactionExecutorId; +import org.apache.accumulo.core.util.threads.ThreadPools; +import org.apache.accumulo.manager.compaction.queue.CompactionJobQueues; + +import io.micrometer.core.instrument.Gauge; +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tags; + +public class QueueMetrics implements MetricsProducer { + private static final long DEFAULT_MIN_REFRESH_DELAY = TimeUnit.SECONDS.toMillis(5); + private MeterRegistry meterRegistry = null; + private final CompactionJobQueues compactionJobQueues; + private AtomicLong queueCount; + + public QueueMetrics(CompactionJobQueues compactionJobQueues) { + this.compactionJobQueues = compactionJobQueues; + ScheduledExecutorService scheduler = ThreadPools.getServerThreadPools() + .createScheduledExecutorService(1, "queueMetricsPoller", false); + Runtime.getRuntime().addShutdownHook(new Thread(scheduler::shutdownNow)); + ThreadPools.watchNonCriticalScheduledTask(scheduler.scheduleAtFixedRate(this::update, + DEFAULT_MIN_REFRESH_DELAY, DEFAULT_MIN_REFRESH_DELAY, TimeUnit.MILLISECONDS)); + } + + public void update() { + if (meterRegistry != null) { + queueCount = meterRegistry.gauge(METRICS_COMPACTOR_JOB_PRIORITY_QUEUES, new AtomicLong(0)); + } + if (queueCount != null) { + queueCount.set(compactionJobQueues.getQueueCount()); + } + + for (CompactionExecutorId ceid : compactionJobQueues.getQueueIds()) { + // Normalize the queueId to match metrics tag naming convention. + String queueId = formatString(ceid.toString()); + + // Register queues by ID rather than by object as queues can be deleted. + Gauge + .builder(METRICS_COMPACTOR_JOB_PRIORITY_QUEUE_LENGTH, ceid, + compactionJobQueues::getQueueMaxSize) + .description("Length of priority queues") + .tags(Tags.concat(getCommonTags(), "queue.id", queueId)).register(meterRegistry); Review Comment: Is there any problem w/ re-registering something that already exists? ########## core/src/main/java/org/apache/accumulo/core/metrics/MetricsUtil.java: ########## @@ -121,10 +123,29 @@ public static List<Tag> getCommonTags() { return commonTags; } - // Centralize any specific string formatting for metric names and/or tags. + /** + * Centralize any specific string formatting for metric names and/or tags. Ensure strings match + * the micrometer naming convention. + */ public static String formatString(String name) { - // Ensure strings are not split by the metrics registry naming scheme. - // Add special character eliminations here. + + // Handle spaces + name = name.replace(" ", "."); + // Handle snake_case notation + name = name.replace("_", "."); + + // Handle camelCase notation + Pattern camelCasePattern = Pattern.compile("[a-z][A-Z][a-z]"); Review Comment: This compiled pattern could be moved to a static var so its not compiled for each method call. ########## server/manager/src/main/java/org/apache/accumulo/manager/metrics/QueueMetrics.java: ########## @@ -0,0 +1,95 @@ +/* + * 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.manager.metrics; + +import static org.apache.accumulo.core.metrics.MetricsUtil.formatString; +import static org.apache.accumulo.core.metrics.MetricsUtil.getCommonTags; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + +import org.apache.accumulo.core.metrics.MetricsProducer; +import org.apache.accumulo.core.spi.compaction.CompactionExecutorId; +import org.apache.accumulo.core.util.threads.ThreadPools; +import org.apache.accumulo.manager.compaction.queue.CompactionJobQueues; + +import io.micrometer.core.instrument.Gauge; +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tags; + +public class QueueMetrics implements MetricsProducer { + private static final long DEFAULT_MIN_REFRESH_DELAY = TimeUnit.SECONDS.toMillis(5); + private MeterRegistry meterRegistry = null; + private final CompactionJobQueues compactionJobQueues; + private AtomicLong queueCount; + + public QueueMetrics(CompactionJobQueues compactionJobQueues) { + this.compactionJobQueues = compactionJobQueues; + ScheduledExecutorService scheduler = ThreadPools.getServerThreadPools() + .createScheduledExecutorService(1, "queueMetricsPoller", false); + Runtime.getRuntime().addShutdownHook(new Thread(scheduler::shutdownNow)); + ThreadPools.watchNonCriticalScheduledTask(scheduler.scheduleAtFixedRate(this::update, + DEFAULT_MIN_REFRESH_DELAY, DEFAULT_MIN_REFRESH_DELAY, TimeUnit.MILLISECONDS)); Review Comment: Is this scheduled task for handling new queues coming into existence? ########## test/src/main/java/org/apache/accumulo/test/functional/BulkNewIT.java: ########## @@ -508,6 +532,26 @@ public void testEndOfFirstTablet() throws Exception { @Test public void testManyFiles() throws Exception { + + // Metrics collector Thread + final LinkedBlockingQueue<TestStatsDSink.Metric> queueMetrics = new LinkedBlockingQueue<>(); + final AtomicBoolean shutdownTailer = new AtomicBoolean(false); Review Comment: Should something eventually set this to true? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
