-
Notifications
You must be signed in to change notification settings - Fork 11
feat(inkless:storage): split S3 error metrics by operation #716
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
Open
jeqo
wants to merge
1
commit into
main
Choose a base branch
from
jeqo/s3-throttling-per-op-metric
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
121 changes: 121 additions & 0 deletions
121
storage/inkless/src/test/java/io/aiven/inkless/storage_backend/s3/MetricCollectorTest.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,121 @@ | ||
| /* | ||
| * Inkless | ||
| * Copyright (C) 2024 - 2025 Aiven OY | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package io.aiven.inkless.storage_backend.s3; | ||
|
|
||
| import org.apache.kafka.common.metrics.KafkaMetric; | ||
| import org.apache.kafka.common.metrics.Metrics; | ||
|
|
||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Map; | ||
|
|
||
| import software.amazon.awssdk.core.internal.metrics.SdkErrorType; | ||
| import software.amazon.awssdk.core.metrics.CoreMetric; | ||
| import software.amazon.awssdk.metrics.MetricCollection; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class MetricCollectorTest { | ||
| private static final String GROUP = "s3-client-metrics"; | ||
|
|
||
| private final Metrics metrics = new Metrics(); | ||
| private final MetricCollector collector = new MetricCollector(metrics); | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| metrics.close(); | ||
| } | ||
|
|
||
| @Test | ||
| void recordsRequestAndLatencyForOperation() { | ||
| collector.publish(collection("DeleteObjects", Duration.ofMillis(7), null)); | ||
|
|
||
| assertThat(doubleValue("delete-objects-requests-total")).isEqualTo(1.0); | ||
| assertThat(doubleValue("delete-objects-time-max")).isEqualTo(7.0); | ||
| } | ||
|
|
||
| @Test | ||
| void recordsErrorBothGloballyAndPerOperation() { | ||
| collector.publish(collection("DeleteObjects", Duration.ofMillis(1), SdkErrorType.THROTTLING)); | ||
|
|
||
| // Untagged global metric preserves existing behavior. | ||
| assertThat(doubleValue("throttling-errors-total")).isEqualTo(1.0); | ||
| // New per-operation variant attributes the throttle to DeleteObjects. | ||
| assertThat(doubleValue("throttling-errors-total", Map.of("operation", "DeleteObjects"))) | ||
| .isEqualTo(1.0); | ||
| // A different operation is not credited. | ||
| assertThat(taggedMetric("throttling-errors-total", Map.of("operation", "PutObject"))) | ||
| .isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void perOperationErrorsAreSeparatedByOperation() { | ||
| collector.publish(collection("DeleteObjects", Duration.ofMillis(1), SdkErrorType.THROTTLING)); | ||
| collector.publish(collection("GetObject", Duration.ofMillis(1), SdkErrorType.THROTTLING)); | ||
|
|
||
| assertThat(doubleValue("throttling-errors-total")).isEqualTo(2.0); | ||
| assertThat(doubleValue("throttling-errors-total", Map.of("operation", "DeleteObjects"))) | ||
| .isEqualTo(1.0); | ||
| assertThat(doubleValue("throttling-errors-total", Map.of("operation", "GetObject"))) | ||
| .isEqualTo(1.0); | ||
| } | ||
|
|
||
| @Test | ||
| void ambiguousOperationSkipsPerOperationButKeepsGlobal() { | ||
| // Two OPERATION_NAME values make the operation ambiguous; the global error is still recorded | ||
| // but no per-operation attribution is possible. | ||
| final software.amazon.awssdk.metrics.MetricCollector root = | ||
| software.amazon.awssdk.metrics.MetricCollector.create("ApiCall"); | ||
| root.reportMetric(CoreMetric.OPERATION_NAME, "DeleteObjects"); | ||
| root.reportMetric(CoreMetric.OPERATION_NAME, "GetObject"); | ||
| root.createChild("ApiCallAttempt").reportMetric(CoreMetric.ERROR_TYPE, SdkErrorType.THROTTLING.toString()); | ||
|
|
||
| collector.publish(root.collect()); | ||
|
|
||
| assertThat(doubleValue("throttling-errors-total")).isEqualTo(1.0); | ||
| assertThat(taggedMetric("throttling-errors-total", Map.of("operation", "DeleteObjects"))) | ||
| .isNull(); | ||
| } | ||
|
|
||
| private static MetricCollection collection(final String operation, | ||
| final Duration duration, | ||
| final SdkErrorType errorType) { | ||
| final software.amazon.awssdk.metrics.MetricCollector root = | ||
| software.amazon.awssdk.metrics.MetricCollector.create("ApiCall"); | ||
| root.reportMetric(CoreMetric.OPERATION_NAME, operation); | ||
| root.reportMetric(CoreMetric.API_CALL_DURATION, duration); | ||
| if (errorType != null) { | ||
| root.createChild("ApiCallAttempt").reportMetric(CoreMetric.ERROR_TYPE, errorType.toString()); | ||
| } | ||
| return root.collect(); | ||
| } | ||
|
|
||
| private double doubleValue(final String name) { | ||
| return (double) metrics.metric(metrics.metricName(name, GROUP)).metricValue(); | ||
| } | ||
|
|
||
| private double doubleValue(final String name, final Map<String, String> tags) { | ||
| return (double) taggedMetric(name, tags).metricValue(); | ||
| } | ||
|
|
||
| private KafkaMetric taggedMetric(final String name, final Map<String, String> tags) { | ||
| return metrics.metric(metrics.metricName(name, GROUP, "", tags)); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.