Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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 @@ -43,6 +43,8 @@ public final class StorageLocationReport implements StorageLocationReportMXBean
private final StorageType storageType;
private final String storageLocation;
private final long reserved;
private final long fsCapacity;
private final long fsAvailable;

private StorageLocationReport(Builder builder) {
this.id = builder.id;
Expand All @@ -55,6 +57,8 @@ private StorageLocationReport(Builder builder) {
this.storageType = builder.storageType;
this.storageLocation = builder.storageLocation;
this.reserved = builder.reserved;
this.fsCapacity = builder.fsCapacity;
this.fsAvailable = builder.fsAvailable;
}

public long getUsableSpace() {
Expand Down Expand Up @@ -143,6 +147,14 @@ public long getReserved() {
return reserved;
}

public long getFsCapacity() {
return fsCapacity;
}

public long getFsAvailable() {
return fsAvailable;
}

private static StorageType getStorageType(StorageTypeProto proto) throws
IOException {
StorageType storageType;
Expand Down Expand Up @@ -186,6 +198,8 @@ public StorageReportProto getProtoBufMessage() throws IOException {
.setFailed(isFailed())
.setFreeSpaceToSpare(getFreeSpaceToSpare())
.setReserved(getReserved())
.setFsCapacity(getFsCapacity())
.setFsAvailable(getFsAvailable())
.build();
}

Expand Down Expand Up @@ -240,6 +254,12 @@ public static StorageLocationReport getFromProtobuf(StorageReportProto report)
if (report.hasReserved()) {
builder.setReserved(report.getReserved());
}
if (report.hasFsCapacity()) {
builder.setFsCapacity(report.getFsCapacity());
}
if (report.hasFsAvailable()) {
builder.setFsAvailable(report.getFsAvailable());
}
return builder.build();
}

Expand All @@ -254,11 +274,16 @@ public String toString() {
if (failed) {
sb.append(" failed");
} else {
sb.append(" capacity=").append(capacity)
.append(" used=").append(scmUsed)
.append(" available=").append(remaining)
long fsUsed = fsCapacity - fsAvailable;
sb.append(" ozoneCapacity=").append(capacity)
.append(" ozoneUsed=").append(scmUsed)
.append(" ozoneAvailable=").append(remaining)
.append(" minFree=").append(freeSpaceToSpare)
.append(" committed=").append(committed);
.append(" committed=").append(committed)
.append(" reserved=").append(reserved)
.append(" fsCapacity=").append(fsCapacity)
.append(" fsAvailable=").append(fsAvailable)
.append(" fsUsed=").append(fsUsed);
}

return sb.append(" }").toString();
Expand Down Expand Up @@ -287,6 +312,8 @@ public static class Builder {
private StorageType storageType;
private String storageLocation;
private long reserved;
private long fsCapacity;
private long fsAvailable;

/**
* Sets the storageId.
Expand Down Expand Up @@ -405,6 +432,16 @@ public long getReserved() {
return reserved;
}

public Builder setFsCapacity(long fsCapacity) {
this.fsCapacity = fsCapacity;
return this;
}

public Builder setFsAvailable(long fsAvailable) {
this.fsAvailable = fsAvailable;
return this;
}

/**
* Builds and returns StorageLocationReport instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,14 @@ protected StorageLocationReport.Builder reportBuilder() {
.setStorageType(storageType);

if (!builder.isFailed()) {
SpaceUsageSource usage = volumeUsage.getCurrentUsage();
SpaceUsageSource.Fixed fsUsage = volumeUsage.realUsage();
SpaceUsageSource usage = volumeUsage.getCurrentUsage(fsUsage);
builder.setCapacity(usage.getCapacity())
.setRemaining(usage.getAvailable())
.setScmUsed(usage.getUsedSpace())
.setReserved(volumeUsage.getReservedInBytes());
.setReserved(volumeUsage.getReservedInBytes())
.setFsCapacity(fsUsage.getCapacity())
.setFsAvailable(fsUsage.getAvailable());
}

return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,21 @@ public class VolumeInfoMetrics implements MetricsSource {
VolumeInfoMetrics.class.getSimpleName();

private static final MetricsInfo CAPACITY =
Interns.info("Capacity", "Capacity");
Interns.info("OzoneCapacity", "Ozone usable capacity (after reserved space adjustment)");
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though the new naming conventions make more sense, this is a breaking change for existing metrics consumers. They will need to update their usage (for example, from Capacity to OzoneCapacity).

How are such breaking changes tracked and communicated? Is there any documentation or process to notify consumers that they need to make updates? For example, if system tests depend on these metrics, how do we ensure these changes are identified and handled?

private static final MetricsInfo AVAILABLE =
Interns.info("Available", "Available Space");
Interns.info("OzoneAvailable", "Ozone available space (after reserved space adjustment)");
private static final MetricsInfo USED =
Interns.info("Used", "Used Space");
Interns.info("OzoneUsed", "Ozone used space");
private static final MetricsInfo RESERVED =
Interns.info("Reserved", "Reserved Space");
private static final MetricsInfo TOTAL_CAPACITY =
Interns.info("TotalCapacity", "Total Capacity");
Interns.info("TotalCapacity", "Ozone capacity + reserved space");
private static final MetricsInfo FS_CAPACITY =
Interns.info("FilesystemCapacity", "Filesystem capacity as reported by the local filesystem");
private static final MetricsInfo FS_AVAILABLE =
Interns.info("FilesystemAvailable", "Filesystem available space as reported by the local filesystem");
private static final MetricsInfo FS_USED =
Interns.info("FilesystemUsed", "Filesystem used space (FilesystemCapacity - FilesystemAvailable)");

private final MetricsRegistry registry;
private final String metricsSourceName;
Expand Down Expand Up @@ -185,14 +191,18 @@ public void getMetrics(MetricsCollector collector, boolean all) {
registry.snapshot(builder, all);
VolumeUsage volumeUsage = volume.getVolumeUsage();
if (volumeUsage != null) {
SpaceUsageSource usage = volumeUsage.getCurrentUsage();
SpaceUsageSource.Fixed fsUsage = volumeUsage.realUsage();
SpaceUsageSource usage = volumeUsage.getCurrentUsage(fsUsage);
long reserved = volumeUsage.getReservedInBytes();
builder
.addGauge(CAPACITY, usage.getCapacity())
.addGauge(AVAILABLE, usage.getAvailable())
.addGauge(USED, usage.getUsedSpace())
.addGauge(RESERVED, reserved)
.addGauge(TOTAL_CAPACITY, usage.getCapacity() + reserved);
.addGauge(TOTAL_CAPACITY, usage.getCapacity() + reserved)
.addGauge(FS_CAPACITY, fsUsage.getCapacity())
.addGauge(FS_AVAILABLE, fsUsage.getAvailable())
.addGauge(FS_USED, fsUsage.getUsedSpace());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ SpaceUsageSource.Fixed realUsage() {
* B) avail = fsAvail - Max(reserved - other, 0);
*/
public SpaceUsageSource.Fixed getCurrentUsage() {
final SpaceUsageSource.Fixed real = realUsage();
return getCurrentUsage(realUsage());
}

// use this variant if real usage values are also needed at the caller
public SpaceUsageSource.Fixed getCurrentUsage(SpaceUsageSource.Fixed real) {
return reservedInBytes == 0
? real
: new SpaceUsageSource.Fixed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ <h2>Volume Information</h2>
<th>Directory</th>
<th>Storage Type</th>
<th>Volume Type</th>
<th>Used Space</th>
<th>Available Space</th>
<th>Ozone Capacity</th>
<th>Ozone Used</th>
<th>Ozone Available</th>
<th>Reserved</th>
<th>Total Capacity</th>
<th>Total Capacity (Ozone Capacity + Reserved)</th>
<th>Filesystem Capacity</th>
<th>Filesystem Available</th>
<th>Filesystem Used</th>
<th>Containers</th>
<th>State</th>
</tr>
Expand All @@ -66,10 +70,14 @@ <h2>Volume Information</h2>
<td>{{volumeInfo["tag.StorageDirectory"]}}</td>
<td>{{volumeInfo["tag.StorageType"]}}</td>
<td>{{volumeInfo["tag.VolumeType"]}}</td>
<td>{{volumeInfo.Used}}</td>
<td>{{volumeInfo.Available}}</td>
<td>{{volumeInfo.OzoneCapacity}}</td>
<td>{{volumeInfo.OzoneUsed}}</td>
<td>{{volumeInfo.OzoneAvailable}}</td>
<td>{{volumeInfo.Reserved}}</td>
<td>{{volumeInfo.TotalCapacity}}</td>
<td>{{volumeInfo.FilesystemCapacity}}</td>
<td>{{volumeInfo.FilesystemAvailable}}</td>
<td>{{volumeInfo.FilesystemUsed}}</td>
<td>{{volumeInfo.Containers}}</td>
<td>{{volumeInfo["tag.VolumeState"]}}</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@
.then(function (result) {
ctrl.dnmetrics = result.data.beans;
ctrl.dnmetrics.forEach(volume => {
volume.Used = transform(volume.Used);
volume.Available = transform(volume.Available);
volume.OzoneCapacity = transform(volume.OzoneCapacity);
volume.OzoneUsed = transform(volume.OzoneUsed);
volume.OzoneAvailable = transform(volume.OzoneAvailable);
volume.Reserved = transform(volume.Reserved);
volume.TotalCapacity = transform(volume.TotalCapacity);
volume.FilesystemCapacity = transform(volume.FilesystemCapacity);
volume.FilesystemAvailable = transform(volume.FilesystemAvailable);
volume.FilesystemUsed = transform(volume.FilesystemUsed);
})
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.container.common.impl;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.StorageReportProto;
import org.junit.jupiter.api.Test;

class TestStorageLocationReport {

@Test
void testStorageReportProtoIncludesFilesystemFieldsAndRoundTrips() throws IOException {
StorageLocationReport report = StorageLocationReport.newBuilder()
.setId("vol-1")
.setStorageLocation("/data/hdds/vol-1")
.setStorageType(StorageType.DISK)
.setCapacity(1000L)
.setScmUsed(100L)
.setRemaining(900L)
.setCommitted(10L)
.setFreeSpaceToSpare(5L)
.setReserved(50L)
.setFsCapacity(2000L)
.setFsAvailable(1500L)
.build();

StorageReportProto proto = report.getProtoBufMessage();
assertThat(proto.hasFsCapacity()).isTrue();
assertThat(proto.hasFsAvailable()).isTrue();
assertThat(proto.getFsCapacity()).isEqualTo(2000L);
assertThat(proto.getFsAvailable()).isEqualTo(1500L);

StorageLocationReport parsed = StorageLocationReport.getFromProtobuf(proto);
assertThat(parsed.getCapacity()).isEqualTo(1000L);
assertThat(parsed.getScmUsed()).isEqualTo(100L);
assertThat(parsed.getRemaining()).isEqualTo(900L);
assertThat(parsed.getReserved()).isEqualTo(50L);
assertThat(parsed.getFsCapacity()).isEqualTo(2000L);
assertThat(parsed.getFsAvailable()).isEqualTo(1500L);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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.container.common.volume;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.File;
import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.hdds.fs.SpaceUsageSource;
import org.apache.hadoop.metrics2.AbstractMetric;
import org.apache.hadoop.metrics2.impl.MetricsCollectorImpl;
import org.apache.hadoop.metrics2.impl.MetricsRecordImpl;
import org.junit.jupiter.api.Test;

class TestVolumeInfoMetrics {

@Test
void testVolumeInfoMetricsExposeOzoneAndFilesystemGauges() {
HddsVolume volume = mock(HddsVolume.class);
when(volume.getStorageType()).thenReturn(StorageType.DISK);
when(volume.getStorageDir()).thenReturn(new File("/tmp/vol-1"));
when(volume.getDatanodeUuid()).thenReturn("dn-1");
when(volume.getLayoutVersion()).thenReturn(1);
when(volume.getStorageState()).thenReturn(HddsVolume.VolumeState.NORMAL);
when(volume.getType()).thenReturn(HddsVolume.VolumeType.DATA_VOLUME);
when(volume.getCommittedBytes()).thenReturn(10L);
when(volume.getContainers()).thenReturn(3L);

VolumeUsage volumeUsage = mock(VolumeUsage.class);
when(volume.getVolumeUsage()).thenReturn(volumeUsage);

// Ozone-usable usage and reserved
when(volumeUsage.getCurrentUsage(any())).thenReturn(new SpaceUsageSource.Fixed(
1000L,
900L,
100L
));
when(volumeUsage.getReservedInBytes()).thenReturn(50L);

// Raw filesystem stats
when(volumeUsage.realUsage()).thenReturn(new SpaceUsageSource.Fixed(2000L, 1500L, 500L));

VolumeInfoMetrics metrics = new VolumeInfoMetrics("test-vol-1", volume);
try {
MetricsCollectorImpl collector = new MetricsCollectorImpl();
metrics.getMetrics(collector, true);
assertThat(collector.getRecords()).hasSize(1);

MetricsRecordImpl rec = collector.getRecords().get(0);
Iterable<AbstractMetric> all = rec.metrics();

assertThat(findMetric(all, "OzoneCapacity")).isEqualTo(1000L);
assertThat(findMetric(all, "OzoneAvailable")).isEqualTo(900L);
assertThat(findMetric(all, "OzoneUsed")).isEqualTo(100L);

assertThat(findMetric(all, "FilesystemCapacity")).isEqualTo(2000L);
assertThat(findMetric(all, "FilesystemAvailable")).isEqualTo(1500L);
assertThat(findMetric(all, "FilesystemUsed")).isEqualTo(500L);
} finally {
metrics.unregister();
}
}

private static long findMetric(Iterable<AbstractMetric> metrics, String name) {
for (AbstractMetric m : metrics) {
if (name.equals(m.name())) {
return m.value().longValue();
}
}
throw new AssertionError("Missing metric: " + name);
}
}

Loading