-
Notifications
You must be signed in to change notification settings - Fork 477
Fix ZombieTServer metrics in for LateLastContactIT failure #4527
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
Merged
EdColeman
merged 5 commits into
apache:2.1
from
EdColeman:fix_zombie_tserver_metrics_init
May 6, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5840d48
Fix ZombieTServer metrics in for LateLastContactIT failure
EdColeman 3940f6a
Add default noop distribution summary
EdColeman 5a8d452
Use new NoOpDistributionSummary as default
98e22de
address PR comments
8aaf877
add logging if no-op record is called
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
server/base/src/main/java/org/apache/accumulo/server/metrics/NoOpDistributionSummary.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * 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 org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import io.micrometer.core.instrument.DistributionSummary; | ||
| import io.micrometer.core.instrument.Tag; | ||
| import io.micrometer.core.instrument.Tags; | ||
| import io.micrometer.core.instrument.distribution.HistogramSnapshot; | ||
|
|
||
| /** | ||
| * Provides a default DistributionSummary that does not do anything. This can be used to prevent NPE | ||
| * if metrics have not been initialized when a DistributionSummary is expected. | ||
| * <p> | ||
| * Normally DistributionSummaries are created using a builder that takes a registry. | ||
| * | ||
| * <pre> | ||
| * DistributionSummary distSum; | ||
| * ... | ||
| * public void registerMetrics(MeterRegistry registry) { | ||
| * ... | ||
| * distSum = DistributionSummary.builder("metric name").description("...").register(registry); | ||
| * ... | ||
| * } | ||
| * </pre> | ||
| * | ||
| * Until the registration is called, the instance variable is null. If code then tries to update the | ||
| * metric, a NPE is thrown. Using this class to provide a default value prevents this from occurring | ||
| * and on registration, it is replaced with a valid instance. | ||
| */ | ||
| public class NoOpDistributionSummary implements DistributionSummary { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(NoOpDistributionSummary.class); | ||
|
|
||
| @Override | ||
| public void record(double v) { | ||
| LOG.debug("record ignored - distribution summary will not be available."); | ||
| } | ||
|
|
||
| @Override | ||
| public long count() { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public double totalAmount() { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public double max() { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public HistogramSnapshot takeSnapshot() { | ||
| return new HistogramSnapshot(0L, 0.0, 0.0, null, null, null); | ||
| } | ||
|
|
||
| @Override | ||
| public Id getId() { | ||
| return new Id("thrift.metrics.uninitialized", Tags.of(Tag.of("none", "uninitialized")), null, | ||
| "placeholder for uninitialized thrift metrics", Type.OTHER); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...er/base/src/test/java/org/apache/accumulo/server/metrics/NoOpDistributionSummaryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * 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 static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class NoOpDistributionSummaryTest { | ||
| @Test | ||
| public void testNoOp() { | ||
| NoOpDistributionSummary noop = new NoOpDistributionSummary(); | ||
| assertDoesNotThrow(() -> noop.getId()); | ||
| assertDoesNotThrow(() -> noop.takeSnapshot()); | ||
| assertDoesNotThrow(() -> noop.max()); | ||
| assertDoesNotThrow(() -> noop.count()); | ||
| assertDoesNotThrow(() -> noop.totalAmount()); | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
server/base/src/test/java/org/apache/accumulo/server/metrics/ThriftMetricsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * 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 static org.apache.accumulo.core.metrics.MetricsProducer.METRICS_THRIFT_EXECUTE; | ||
| import static org.apache.accumulo.core.metrics.MetricsProducer.METRICS_THRIFT_IDLE; | ||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import io.micrometer.core.instrument.DistributionSummary; | ||
| import io.micrometer.core.instrument.MeterRegistry; | ||
| import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
|
|
||
| class ThriftMetricsTest { | ||
| private final static Logger LOG = LoggerFactory.getLogger(ThriftMetricsTest.class); | ||
|
|
||
| @Test | ||
| void testNoNPE() { | ||
| ThriftMetrics tm = new ThriftMetrics(); | ||
| assertDoesNotThrow(() -> tm.addIdle(1)); | ||
| assertDoesNotThrow(() -> tm.addExecute(1)); | ||
| } | ||
|
|
||
| @Test | ||
| void registerMetrics() { | ||
| MeterRegistry registry = new SimpleMeterRegistry(); | ||
| ThriftMetrics tm = new ThriftMetrics(); | ||
| tm.registerMetrics(registry); | ||
| tm.addExecute(1000); | ||
| tm.addIdle(1000); | ||
|
|
||
| registry.forEachMeter(m -> { | ||
| LOG.trace("meter: {}", m.getId()); | ||
| assertInstanceOf(DistributionSummary.class, m); | ||
| assertFalse(m instanceof NoOpDistributionSummary); | ||
| }); | ||
| assertTrue(registry.get(METRICS_THRIFT_IDLE).summary().count() > 0); | ||
| assertTrue(registry.get(METRICS_THRIFT_EXECUTE).summary().count() > 0); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.