Skip to content

Commit

Permalink
Merge pull request #997 from amvanbaren/assets-endpoint-metrics
Browse files Browse the repository at this point in the history
FileResource usage metrics
  • Loading branch information
amvanbaren committed Sep 25, 2024
2 parents 6548dbe + b72e656 commit 7e29166
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
package org.eclipse.openvsx;

import com.google.common.collect.Maps;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -216,6 +218,16 @@ public ResponseEntity<byte[]> getFile(String namespace, String extensionName, St
if (resource.getType().equals(DOWNLOAD))
storageUtil.increaseDownloadCount(resource);

var extVersion = resource.getExtension();
var extension = extVersion.getExtension();
Metrics.counter("ovsx.file", List.of(
Tag.of("namespace", extension.getNamespace().getName()),
Tag.of("extension", extension.getName()),
Tag.of("target", extVersion.getTargetPlatform()),
Tag.of("version", extVersion.getVersion()),
Tag.of("filename", resource.getName()),
Tag.of("type", resource.getType())
)).increment();
return storageUtil.getFileResponse(resource);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import io.micrometer.core.instrument.*;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.openvsx.entities.Extension;
import org.eclipse.openvsx.entities.ExtensionVersion;
Expand Down Expand Up @@ -290,11 +291,19 @@ public ResponseEntity<byte[]> getAsset(
throw new NotFoundException();
}

var tags = new ArrayList<>(List.of(
Tag.of("namespace", namespace.toLowerCase()),
Tag.of("extension", extensionName.toLowerCase()),
Tag.of("target", targetPlatform.toLowerCase()),
Tag.of("version", version.toLowerCase())
));
if(asset.equals(FILE_PUBLIC_KEY)) {
var publicId = repositories.findSignatureKeyPairPublicId(namespace, extensionName, targetPlatform, version);
if(publicId == null) {
throw new NotFoundException();
} else {
tags.add(Tag.of("type", "publicKey"));
Metrics.counter("vscode.assets", tags).increment();
return ResponseEntity
.status(HttpStatus.FOUND)
.location(URI.create(UrlUtil.getPublicKeyUrl(publicId)))
Expand Down Expand Up @@ -333,6 +342,10 @@ public ResponseEntity<byte[]> getAsset(
storageUtil.increaseDownloadCount(resource);
}

tags.add(Tag.of("type", resource.getType()));
tags.add(Tag.of("filename", resource.getName()));
Metrics.counter("vscode.assets", tags).increment();

return storageUtil.getFileResponse(resource);
}

Expand Down

0 comments on commit 7e29166

Please sign in to comment.