Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileResource usage metrics #997

Merged
merged 1 commit into from
Sep 25, 2024
Merged
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
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
Loading