-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(s3stream): add direct memory usage metrics (#947)
Signed-off-by: Shichao Nie <[email protected]>
- Loading branch information
Showing
7 changed files
with
117 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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 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
55 changes: 55 additions & 0 deletions
55
s3stream/src/main/java/com/automq/stream/s3/metrics/MultiAttributes.java
This file contains 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,55 @@ | ||
/* | ||
* 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 | ||
* | ||
* http://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 com.automq.stream.s3.metrics; | ||
|
||
import com.automq.stream.s3.metrics.wrapper.ConfigListener; | ||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.Attributes; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class MultiAttributes<K> implements ConfigListener { | ||
private final Map<K, Attributes> attributesMap = new ConcurrentHashMap<>(); | ||
private final AttributeKey<K> keyName; | ||
private Attributes baseAttributes; | ||
|
||
public MultiAttributes(Attributes baseAttributes, AttributeKey<K> keyName) { | ||
this.baseAttributes = baseAttributes; | ||
this.keyName = keyName; | ||
} | ||
|
||
public Attributes get(K key) { | ||
return attributesMap.computeIfAbsent(key, k -> buildAttributes(baseAttributes, Attributes.of(keyName, key))); | ||
} | ||
|
||
private Attributes buildAttributes(Attributes baseAttributes, Attributes attributes) { | ||
return Attributes.builder().putAll(baseAttributes).putAll(attributes).build(); | ||
} | ||
|
||
private void reBuildAttributes(Attributes baseAttributes) { | ||
for (Map.Entry<K, Attributes> entry : attributesMap.entrySet()) { | ||
attributesMap.replace(entry.getKey(), buildAttributes(baseAttributes, entry.getValue())); | ||
} | ||
} | ||
|
||
@Override | ||
public void onConfigChange(MetricsConfig metricsConfig) { | ||
this.baseAttributes = metricsConfig.getBaseAttributes(); | ||
reBuildAttributes(metricsConfig.getBaseAttributes()); | ||
} | ||
} |
This file contains 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 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
41 changes: 0 additions & 41 deletions
41
s3stream/src/main/java/com/automq/stream/s3/metrics/stats/ByteBufStats.java
This file was deleted.
Oops, something went wrong.
This file contains 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