Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ List<OmMultipartUpload> getMultipartUploadKeys(String volumeName,
Iterator<Map.Entry<CacheKey<String>, CacheValue<OmBucketInfo>>>
getBucketIterator();

Iterator<Map.Entry<CacheKey<String>, CacheValue<OmVolumeArgs>>>
getVolumeIterator();

TableIterator<String, ? extends Table.KeyValue<String, OmKeyInfo>>
getKeyIterator() throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
* Available metrics:
* <ul>
* <li>Bytes used in bucket.
* <li>Bucket quote in bytes.
* <li>Bucket quota in bytes.
* <li>Bucket quota in namespace.
* <li>Bucket used namespace (number of keys/directories in bucket).
* <li>Bucket available space. Calculated from difference between used bytes in bucket and bucket quota.
* If bucket quote is not set then this metric show -1 as value.
* If bucket quota is not set then this metric shows -1 as value.
* </ul>
*/
@InterfaceAudience.Private
Expand Down Expand Up @@ -87,6 +88,7 @@ public void getMetrics(MetricsCollector collector, boolean all) {
.addGauge(BucketMetricsInfo.BucketSnapshotUsedBytes, bucketInfo.getSnapshotUsedBytes())
.addGauge(BucketMetricsInfo.BucketQuotaBytes, bucketInfo.getQuotaInBytes())
.addGauge(BucketMetricsInfo.BucketQuotaNamespace, bucketInfo.getQuotaInNamespace())
.addGauge(BucketMetricsInfo.BucketUsedNamespace, bucketInfo.getUsedNamespace())
.addGauge(BucketMetricsInfo.BucketAvailableBytes, availableSpace);
}
}
Expand All @@ -103,6 +105,7 @@ enum BucketMetricsInfo implements MetricsInfo {
BucketQuotaBytes("Bucket quota in bytes"),
BucketSnapshotUsedBytes("Bucket quota bytes held in snapshots"),
BucketQuotaNamespace("Bucket quota in namespace."),
BucketUsedNamespace("Bucket used namespace."),
BucketAvailableBytes("Bucket available space.");

private final String desc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,12 @@ public List<OmBucketInfo> listBuckets(final String volumeName,
return bucketTable.cacheIterator();
}

@Override
public Iterator<Map.Entry<CacheKey<String>, CacheValue<OmVolumeArgs>>>
getVolumeIterator() {
return volumeTable.cacheIterator();
}

@Override
public TableIterator<String, ? extends KeyValue<String, OmKeyInfo>>
getKeyIterator() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
private final OzoneLockProvider ozoneLockProvider;
private final OMPerformanceMetrics perfMetrics;
private final BucketUtilizationMetrics bucketUtilizationMetrics;
private final VolumeUtilizationMetrics volumeUtilizationMetrics;

private boolean fsSnapshotEnabled;

Expand Down Expand Up @@ -761,6 +762,7 @@ private OzoneManager(OzoneConfiguration conf, StartupOption startupOption)
}

bucketUtilizationMetrics = BucketUtilizationMetrics.create(metadataManager);
volumeUtilizationMetrics = VolumeUtilizationMetrics.create(metadataManager);
omHostName = HddsUtils.getHostName(conf);
}

Expand Down Expand Up @@ -2485,6 +2487,10 @@ public boolean stop() {
bucketUtilizationMetrics.unRegister();
}

if (volumeUtilizationMetrics != null) {
volumeUtilizationMetrics.unRegister();
}

if (versionManager != null) {
versionManager.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* 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 org.apache.hadoop.ozone.om;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
import org.apache.hadoop.metrics2.MetricsCollector;
import org.apache.hadoop.metrics2.MetricsInfo;
import org.apache.hadoop.metrics2.MetricsSource;
import org.apache.hadoop.metrics2.MetricsSystem;
import org.apache.hadoop.metrics2.annotation.Metrics;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;

/**
* A class for collecting and reporting volume utilization metrics.
* <p>
* Available metrics:
* <ul>
* <li>Volume quota in bytes.
* <li>Volume used bytes (aggregated from all buckets in the volume).
* <li>Volume available bytes. Calculated from difference between volume quota and used bytes.
* If volume quota is not set then this metric shows -1 as value.
* <li>Volume quota in namespace (maximum number of buckets).
* <li>Volume used namespace (current number of buckets).
* </ul>
*/
@InterfaceAudience.Private
@Metrics(about = "Ozone Volume Utilization Metrics", context = OzoneConsts.OZONE)
public class VolumeUtilizationMetrics implements MetricsSource {

private static final String SOURCE = VolumeUtilizationMetrics.class.getSimpleName();

private final OMMetadataManager metadataManager;

public VolumeUtilizationMetrics(OMMetadataManager metadataManager) {
this.metadataManager = metadataManager;
}

public static VolumeUtilizationMetrics create(OMMetadataManager metadataManager) {
MetricsSystem ms = DefaultMetricsSystem.instance();
return ms.register(SOURCE, "Volume Utilization Metrics", new VolumeUtilizationMetrics(metadataManager));
}

@Override
public void getMetrics(MetricsCollector collector, boolean all) {
Map<String, OmVolumeArgs> volumes = new HashMap<>();
Iterator<Entry<CacheKey<String>, CacheValue<OmVolumeArgs>>> volumeIterator = metadataManager.getVolumeIterator();
while (volumeIterator.hasNext()) {
Entry<CacheKey<String>, CacheValue<OmVolumeArgs>> entry = volumeIterator.next();
OmVolumeArgs volumeArgs = entry.getValue().getCacheValue();
if (volumeArgs != null) {
volumes.put(volumeArgs.getVolume(), volumeArgs);
}
}

Map<String, Long> usedBytesPerVolume = new HashMap<>();
Iterator<Entry<CacheKey<String>, CacheValue<OmBucketInfo>>> bucketIterator = metadataManager.getBucketIterator();
while (bucketIterator.hasNext()) {
Entry<CacheKey<String>, CacheValue<OmBucketInfo>> entry = bucketIterator.next();
OmBucketInfo bucketInfo = entry.getValue().getCacheValue();
if (bucketInfo == null) {
continue;
}
usedBytesPerVolume.merge(bucketInfo.getVolumeName(), bucketInfo.getUsedBytes(), Long::sum);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding these metrics. Overall these look like good additions, I just have a concern with the volume used bytes. It is not directly tracked by Ozone because volumes don't have any connection to files, only buckets. Hence the used namespace tracked per volume is just a count of number of buckets and there is no used bytes for volumes.

I think this could be aggregated with promQL outside of Ozone if needed.

cc @sumitagrawl

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @errose28, Thanks for the feedback!
Removed the VolumeUsedBytes and VolumeAvailableBytes metrics along with the aggregation logic.


for (OmVolumeArgs volumeArgs : volumes.values()) {
long quotaInBytes = volumeArgs.getQuotaInBytes();
long usedBytes = usedBytesPerVolume.getOrDefault(volumeArgs.getVolume(), 0L);
long availableBytes;
if (quotaInBytes == -1) {
availableBytes = -1;
} else {
availableBytes = Math.max(quotaInBytes - usedBytes, 0);
}

collector.addRecord(SOURCE)
.setContext("Volume metrics")
.tag(VolumeMetricsInfo.VolumeName, volumeArgs.getVolume())
.addGauge(VolumeMetricsInfo.VolumeQuotaBytes, quotaInBytes)
.addGauge(VolumeMetricsInfo.VolumeUsedBytes, usedBytes)
.addGauge(VolumeMetricsInfo.VolumeAvailableBytes, availableBytes)
.addGauge(VolumeMetricsInfo.VolumeQuotaNamespace, volumeArgs.getQuotaInNamespace())
.addGauge(VolumeMetricsInfo.VolumeUsedNamespace, volumeArgs.getUsedNamespace());
}
}

public void unRegister() {
MetricsSystem ms = DefaultMetricsSystem.instance();
ms.unregisterSource(SOURCE);
}

enum VolumeMetricsInfo implements MetricsInfo {
VolumeName("Volume name."),
VolumeQuotaBytes("Volume quota in bytes."),
VolumeUsedBytes("Bytes used across all buckets in the volume."),
VolumeAvailableBytes("Volume available space."),
VolumeQuotaNamespace("Volume quota in namespace."),
VolumeUsedNamespace("Volume used namespace.");

private final String desc;

VolumeMetricsInfo(String desc) {
this.desc = desc;
}

@Override
public String description() {
return desc;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ public class TestBucketUtilizationMetrics {
private static final long QUOTA_IN_BYTES_2 = QUOTA_RESET;
private static final long QUOTA_IN_NAMESPACE_1 = 1;
private static final long QUOTA_IN_NAMESPACE_2 = 2;
private static final long USED_NAMESPACE_1 = 5;
private static final long USED_NAMESPACE_2 = 3;

@Test
void testBucketUtilizationMetrics() {
OMMetadataManager omMetadataManager = mock(OMMetadataManager.class);

Map.Entry<CacheKey<String>, CacheValue<OmBucketInfo>> entry1 = createMockEntry(VOLUME_NAME_1, BUCKET_NAME_1,
USED_BYTES_1, SNAPSHOT_USED_BYTES_1, QUOTA_IN_BYTES_1, QUOTA_IN_NAMESPACE_1);
USED_BYTES_1, SNAPSHOT_USED_BYTES_1, QUOTA_IN_BYTES_1, QUOTA_IN_NAMESPACE_1, USED_NAMESPACE_1);
Map.Entry<CacheKey<String>, CacheValue<OmBucketInfo>> entry2 = createMockEntry(VOLUME_NAME_2, BUCKET_NAME_2,
USED_BYTES_2, SNAPSHOT_USED_BYTES_2, QUOTA_IN_BYTES_2, QUOTA_IN_NAMESPACE_2);
USED_BYTES_2, SNAPSHOT_USED_BYTES_2, QUOTA_IN_BYTES_2, QUOTA_IN_NAMESPACE_2, USED_NAMESPACE_2);

Iterator<Map.Entry<CacheKey<String>, CacheValue<OmBucketInfo>>> bucketIterator = mock(Iterator.class);
when(bucketIterator.hasNext())
Expand Down Expand Up @@ -96,6 +98,7 @@ void testBucketUtilizationMetrics() {
verify(mb, times(1)).addGauge(BucketMetricsInfo.BucketSnapshotUsedBytes, SNAPSHOT_USED_BYTES_1);
verify(mb, times(1)).addGauge(BucketMetricsInfo.BucketQuotaBytes, QUOTA_IN_BYTES_1);
verify(mb, times(1)).addGauge(BucketMetricsInfo.BucketQuotaNamespace, QUOTA_IN_NAMESPACE_1);
verify(mb, times(1)).addGauge(BucketMetricsInfo.BucketUsedNamespace, USED_NAMESPACE_1);
verify(mb, times(1)).addGauge(BucketMetricsInfo.BucketAvailableBytes,
QUOTA_IN_BYTES_1 - USED_BYTES_1 - SNAPSHOT_USED_BYTES_1);

Expand All @@ -105,11 +108,13 @@ void testBucketUtilizationMetrics() {
verify(mb, times(1)).addGauge(BucketMetricsInfo.BucketSnapshotUsedBytes, SNAPSHOT_USED_BYTES_2);
verify(mb, times(1)).addGauge(BucketMetricsInfo.BucketQuotaBytes, QUOTA_IN_BYTES_2);
verify(mb, times(1)).addGauge(BucketMetricsInfo.BucketQuotaNamespace, QUOTA_IN_NAMESPACE_2);
verify(mb, times(1)).addGauge(BucketMetricsInfo.BucketUsedNamespace, USED_NAMESPACE_2);
verify(mb, times(1)).addGauge(BucketMetricsInfo.BucketAvailableBytes, QUOTA_RESET);
}

private static Map.Entry<CacheKey<String>, CacheValue<OmBucketInfo>> createMockEntry(String volumeName,
String bucketName, long usedBytes, long snapshotUsedBytes, long quotaInBytes, long quotaInNamespace) {
String bucketName, long usedBytes, long snapshotUsedBytes, long quotaInBytes, long quotaInNamespace,
long usedNamespace) {
Map.Entry<CacheKey<String>, CacheValue<OmBucketInfo>> entry = mock(Map.Entry.class);
CacheValue<OmBucketInfo> cacheValue = mock(CacheValue.class);
OmBucketInfo bucketInfo = mock(OmBucketInfo.class);
Expand All @@ -120,6 +125,7 @@ private static Map.Entry<CacheKey<String>, CacheValue<OmBucketInfo>> createMockE
when(bucketInfo.getSnapshotUsedBytes()).thenReturn(snapshotUsedBytes);
when(bucketInfo.getQuotaInBytes()).thenReturn(quotaInBytes);
when(bucketInfo.getQuotaInNamespace()).thenReturn(quotaInNamespace);
when(bucketInfo.getUsedNamespace()).thenReturn(usedNamespace);
when(bucketInfo.getTotalBucketSpace()).thenReturn(usedBytes + snapshotUsedBytes);

when(cacheValue.getCacheValue()).thenReturn(bucketInfo);
Expand Down
Loading