Skip to content

Commit

Permalink
upstream: b=main,r=d55c5224aa2fb5615acba07367f7da5125d10003,t=2024-03…
Browse files Browse the repository at this point in the history
…-08-1342-44396
  • Loading branch information
sonatype-zion committed Mar 8, 2024
1 parent 999fced commit 26b9f71
Show file tree
Hide file tree
Showing 101 changed files with 701 additions and 582 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.annotation.Nullable;

import org.sonatype.goodies.lifecycle.Lifecycle;
import org.sonatype.nexus.blobstore.api.metrics.BlobStoreMetricsService;
import org.sonatype.nexus.transaction.TransactionalStore;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -196,6 +197,15 @@ default Blob makeBlobPermanent(final BlobId blobId, final Map<String, String> he
*/
boolean deleteHard(BlobId blobId);

/**
* Provides access to the blob store's metrics service instance
* <p>
* Note: this method may not be available for all the blob store implementations
* and, if not supported, expect a {@link UnsupportedOperationException}
* </p>
*/
BlobStoreMetricsService getMetricsService();

/**
* Provides an immutable snapshot of metrics about the BlobStore's usage.
*/
Expand Down Expand Up @@ -264,6 +274,7 @@ default Blob makeBlobPermanent(final BlobId blobId, final Map<String, String> he
/**
* Get {@link BlobAttributes} for the {@link BlobId} provided.
*/
@Nullable
BlobAttributes getBlobAttributes(BlobId blobId);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface BlobStoreMetricsService
void setBlobStore(BlobStore blobStore);

/**
* Record a new blob being added to the blobstore.
* Record a new blob being added to the blob store.
*
* @param size Size of the newly added blob in bytes.
*/
Expand All @@ -61,6 +61,11 @@ public interface BlobStoreMetricsService
*/
Map<OperationType, OperationMetrics> getOperationMetricsDelta();

/**
* Reset the total metrics (blob count / size)
*/
void clearCountMetrics();

/**
* Reset the operational metrics.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public interface BlobStoreMetricsStore
*/
void clearOperationMetrics(String blobStoreName);

/**
* Clear the summary metrics for the given blob store name.
* (total size , blob count)
*/
void clearCountMetrics(String blobStoreName);

/**
* Initialize the metrics for the given blobstore.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.sonatype.nexus.blobstore.api.OperationMetrics;
import org.sonatype.nexus.blobstore.api.OperationType;
import org.sonatype.nexus.blobstore.api.RawObjectAccess;
import org.sonatype.nexus.blobstore.api.metrics.BlobStoreMetricsService;
import org.sonatype.nexus.blobstore.file.internal.BlobCollisionException;
import org.sonatype.nexus.blobstore.file.internal.FileOperations;
import org.sonatype.nexus.blobstore.metrics.MonitoringBlobStoreMetrics;
Expand Down Expand Up @@ -165,7 +166,7 @@ public class FileBlobStore

private Path basedir;

private FileBlobStoreMetricsService metricsStore;
private FileBlobStoreMetricsService metricsService;

private LoadingCache<BlobId, FileBlob> liveBlobs;

Expand All @@ -190,7 +191,7 @@ public FileBlobStore(
final BlobIdLocationResolver blobIdLocationResolver,
final FileOperations fileOperations,
final ApplicationDirectories applicationDirectories,
final FileBlobStoreMetricsService metricsStore,
final FileBlobStoreMetricsService metricsService,
final NodeAccess nodeAccess,
final DryRunPrefix dryRunPrefix,
final BlobStoreReconciliationLogger reconciliationLogger,
Expand All @@ -201,7 +202,7 @@ public FileBlobStore(
super(blobIdLocationResolver, dryRunPrefix);
this.fileOperations = checkNotNull(fileOperations);
this.applicationDirectories = checkNotNull(applicationDirectories);
this.metricsStore = checkNotNull(metricsStore);
this.metricsService = checkNotNull(metricsService);
this.nodeAccess = checkNotNull(nodeAccess);
this.supportsHardLinkCopy = true;
this.supportsAtomicMove = true;
Expand All @@ -216,7 +217,7 @@ public FileBlobStore(
final Path contentDir, //NOSONAR
final BlobIdLocationResolver blobIdLocationResolver,
final FileOperations fileOperations,
final FileBlobStoreMetricsService metricsStore,
final FileBlobStoreMetricsService metricsService,
final BlobStoreConfiguration configuration,
final ApplicationDirectories directories,
final NodeAccess nodeAccess,
Expand All @@ -227,7 +228,7 @@ public FileBlobStore(
final FileBlobDeletionIndex blobDeletionIndex)

{
this(blobIdLocationResolver, fileOperations, directories, metricsStore, nodeAccess, dryRunPrefix,
this(blobIdLocationResolver, fileOperations, directories, metricsService, nodeAccess, dryRunPrefix,
reconciliationLogger, pruneEmptyDirectoryAge, blobStoreQuotaUsageChecker, blobDeletionIndex);
this.contentDir = checkNotNull(contentDir);
this.blobStoreConfiguration = checkNotNull(configuration);
Expand All @@ -251,9 +252,9 @@ protected void doStart() throws Exception {
}
liveBlobs = CacheBuilder.newBuilder().weakValues().build(from(FileBlob::new));
blobDeletionIndex.initIndex(metadata, this);
metricsStore.setStorageDir(storageDir);
metricsStore.setBlobStore(this);
metricsStore.start();
metricsService.setStorageDir(storageDir);
metricsService.setBlobStore(this);
metricsService.start();

blobStoreQuotaUsageChecker.setBlobStore(this);
blobStoreQuotaUsageChecker.start();
Expand Down Expand Up @@ -306,7 +307,7 @@ protected void doStop() throws Exception {
blobDeletionIndex.stopIndex();
}
finally {
metricsStore.stop();
metricsService.stop();
blobStoreQuotaUsageChecker.stop();
}
}
Expand Down Expand Up @@ -425,14 +426,14 @@ private Blob tryCreate(
if (existingSize != null) {
overwrite(temporaryBlobPath, blobPath);
overwrite(temporaryAttributePath, attributePath);
metricsStore.recordDeletion(existingSize);
metricsService.recordDeletion(existingSize);
}
else {
move(temporaryBlobPath, blobPath);
move(temporaryAttributePath, attributePath);
}

metricsStore.recordAddition(blobAttributes.getMetrics().getContentSize());
metricsService.recordAddition(blobAttributes.getMetrics().getContentSize());

return blob;
}
Expand Down Expand Up @@ -582,7 +583,7 @@ protected boolean doDeleteHard(final BlobId blobId) {
delete(attributePath);

if (blobDeleted && contentSize != null) {
metricsStore.recordDeletion(contentSize);
metricsService.recordDeletion(contentSize);
}

return blobDeleted;
Expand All @@ -604,25 +605,31 @@ private Long getContentSizeForDeletion(final BlobId blobId) {
.orElse(null);
}

@Override
@Guarded(by = STARTED)
public BlobStoreMetricsService getMetricsService() {
return metricsService;
}

@Override
@Guarded(by = STARTED)
public BlobStoreMetrics getMetrics() {
return metricsStore.getMetrics();
return metricsService.getMetrics();
}

@Override
public Map<OperationType, OperationMetrics> getOperationMetricsByType() {
return metricsStore.getOperationMetrics();
return metricsService.getOperationMetrics();
}

@Override
public Map<OperationType, OperationMetrics> getOperationMetricsDelta() {
return metricsStore.getOperationMetricsDelta();
return metricsService.getOperationMetricsDelta();
}

@Override
public void clearOperationMetrics() {
metricsStore.clearOperationMetrics();
metricsService.clearOperationMetrics();
}

@Override
Expand Down Expand Up @@ -824,7 +831,7 @@ private Path getConfiguredBlobStorePath() {
@Guarded(by = {NEW, STOPPED, FAILED, SHUTDOWN})
public void remove() {
try {
metricsStore.remove();
metricsService.remove();

Path blobDir = getAbsoluteBlobDir();
FileUtils.deleteDirectory(reconciliationLogDir.toFile());
Expand Down Expand Up @@ -1195,6 +1202,6 @@ public RawObjectAccess getRawObjectAccess() {
@Override
@VisibleForTesting
public void flushMetrics() throws IOException {
metricsStore.flush();
metricsService.flush();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.sonatype.nexus.blobstore.file.FileBlobStore;
import org.sonatype.nexus.blobstore.quota.BlobStoreQuotaService;
import org.sonatype.nexus.common.app.ApplicationDirectories;
import org.sonatype.nexus.common.upgrade.AvailabilityVersion;
import org.sonatype.nexus.formfields.FormField;
import org.sonatype.nexus.formfields.StringTextFormField;
import org.sonatype.nexus.rest.ValidationErrorsException;
Expand All @@ -49,7 +48,6 @@
*
* @since 3.6
*/
@AvailabilityVersion(from = "1.0")
@Named(FileBlobStore.TYPE)
public class FileBlobStoreDescriptor
extends BlobStoreDescriptorSupport
Expand Down
1 change: 1 addition & 0 deletions components/nexus-blobstore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus-blobstore-api</artifactId>
</dependency>

<dependency>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus-thread</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

/**
* Describes a blob store.
* Note: Do not inject Map<String, BlobStoreDescriptors> and instead opt to use BlobStoreDescriptorProvider
*
* @since 3.6
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ private void readProperties() {
}
}

@Override
public void clearCountMetrics() {
totalSize.set(0L);
blobCount.set(0L);
}

@Override
public void clearOperationMetrics() {
getOperationMetricsDelta().values().forEach(OperationMetrics::clear);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.sonatype.nexus.blobstore.api.OperationType;
import org.sonatype.nexus.blobstore.api.RawObjectAccess;
import org.sonatype.nexus.blobstore.api.UnimplementedRawObjectAccess;
import org.sonatype.nexus.blobstore.api.metrics.BlobStoreMetricsService;
import org.sonatype.nexus.blobstore.group.internal.BlobStoreGroupMetrics;
import org.sonatype.nexus.blobstore.group.internal.WriteToFirstMemberFillPolicy;
import org.sonatype.nexus.blobstore.metrics.MonitoringBlobStoreMetrics;
Expand Down Expand Up @@ -277,6 +278,12 @@ public boolean deleteHard(final BlobId blobId) {
}
}

@Override
@Guarded(by = STARTED)
public BlobStoreMetricsService getMetricsService() {
throw new UnsupportedOperationException("metrics service is not available at a group level");
}

@Override
@Guarded(by = STARTED)
public BlobStoreMetrics getMetrics() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.sonatype.nexus.blobstore.group.BlobStoreGroupService;
import org.sonatype.nexus.blobstore.group.FillPolicy;
import org.sonatype.nexus.blobstore.quota.BlobStoreQuotaService;
import org.sonatype.nexus.common.upgrade.AvailabilityVersion;
import org.sonatype.nexus.formfields.ComboboxFormField;
import org.sonatype.nexus.formfields.FormField;
import org.sonatype.nexus.formfields.ItemselectFormField;
Expand All @@ -58,7 +57,6 @@
*
* @since 3.14
*/
@AvailabilityVersion(from = "1.0")
@Named(BlobStoreGroup.TYPE)
public class BlobStoreGroupDescriptor
extends BlobStoreDescriptorSupport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public void flush() throws IOException {
blobStoreMetricsStore.updateMetrics(blobStoreMetricsEntity);
}

@Override
public void clearCountMetrics() {
blobStoreMetricsStore.clearCountMetrics(blobStore.getBlobStoreConfiguration().getName());
}

@Override
public void clearOperationMetrics() {
datastoreBlobStoreMetricsContainer.getOperationMetricsDelta().values().forEach(OperationMetrics::clear);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

/**
* Describes a capability (its type).
* Note: Do not inject List<BlobStoreDescriptors> and instead opt to use DefaultCapabilityDescriptorProvider
*/
public interface CapabilityDescriptor
{
Expand Down
Loading

0 comments on commit 26b9f71

Please sign in to comment.