Skip to content

Commit d4537ae

Browse files
author
amvanbaren
committed
Observe publish endpoint and download count processing
Comment out download count observations
1 parent 876f0df commit d4537ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1167
-867
lines changed

server/src/main/java/org/eclipse/openvsx/ExtensionProcessor.java

Lines changed: 229 additions & 176 deletions
Large diffs are not rendered by default.

server/src/main/java/org/eclipse/openvsx/ExtensionService.java

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
********************************************************************************/
1010
package org.eclipse.openvsx;
1111

12+
import io.micrometer.observation.Observation;
13+
import io.micrometer.observation.ObservationRegistry;
1214
import jakarta.transaction.Transactional;
1315
import jakarta.transaction.Transactional.TxType;
1416
import org.apache.commons.lang3.StringUtils;
@@ -28,8 +30,10 @@
2830
import java.io.IOException;
2931
import java.io.InputStream;
3032
import java.nio.file.Files;
33+
import java.nio.file.StandardCopyOption;
3134
import java.time.LocalDateTime;
3235
import java.util.LinkedHashSet;
36+
import java.util.concurrent.atomic.AtomicLong;
3337

3438
@Component
3539
public class ExtensionService {
@@ -40,6 +44,7 @@ public class ExtensionService {
4044
private final SearchUtilService search;
4145
private final CacheService cache;
4246
private final PublishExtensionVersionHandler publishHandler;
47+
private final ObservationRegistry observations;
4348

4449
@Value("${ovsx.publishing.require-license:false}")
4550
boolean requireLicense;
@@ -48,12 +53,14 @@ public ExtensionService(
4853
RepositoryService repositories,
4954
SearchUtilService search,
5055
CacheService cache,
51-
PublishExtensionVersionHandler publishHandler
56+
PublishExtensionVersionHandler publishHandler,
57+
ObservationRegistry observations
5258
) {
5359
this.repositories = repositories;
5460
this.search = search;
5561
this.cache = cache;
5662
this.publishHandler = publishHandler;
63+
this.observations = observations;
5764
}
5865

5966
@Transactional
@@ -64,44 +71,50 @@ public ExtensionVersion mirrorVersion(TempFile extensionFile, String signatureNa
6471
}
6572

6673
public ExtensionVersion publishVersion(InputStream content, PersonalAccessToken token) {
67-
var extensionFile = createExtensionFile(content);
68-
var download = doPublish(extensionFile, null, token, TimeUtil.getCurrentUTC(), true);
69-
publishHandler.publishAsync(download, extensionFile, this);
70-
publishHandler.schedulePublicIdJob(download);
71-
return download.getExtension();
74+
return Observation.createNotStarted("ExtensionService#publishVersion", observations).observe(() -> {
75+
var extensionFile = createExtensionFile(content);
76+
var download = doPublish(extensionFile, null, token, TimeUtil.getCurrentUTC(), true);
77+
publishHandler.publishAsync(download, extensionFile, this);
78+
publishHandler.schedulePublicIdJob(download);
79+
return download.getExtension();
80+
});
7281
}
7382

7483
private FileResource doPublish(TempFile extensionFile, String binaryName, PersonalAccessToken token, LocalDateTime timestamp, boolean checkDependencies) {
75-
try (var processor = new ExtensionProcessor(extensionFile)) {
76-
var extVersion = publishHandler.createExtensionVersion(processor, token, timestamp, checkDependencies);
77-
if (requireLicense) {
78-
// Check the extension's license
79-
var license = processor.getLicense(extVersion);
80-
checkLicense(extVersion, license);
84+
return Observation.createNotStarted("ExtensionService#doPublish", observations).observe(() -> {
85+
try (var processor = new ExtensionProcessor(extensionFile, observations)) {
86+
var extVersion = publishHandler.createExtensionVersion(processor, token, timestamp, checkDependencies);
87+
if (requireLicense) {
88+
// Check the extension's license
89+
var license = processor.getLicense(extVersion);
90+
Observation.createNotStarted("ExtensionService#checkLicense", observations).observe(() -> checkLicense(extVersion, license));
91+
}
92+
93+
return processor.getBinary(extVersion, binaryName);
8194
}
82-
83-
return processor.getBinary(extVersion, binaryName);
84-
}
95+
});
8596
}
8697

8798
private TempFile createExtensionFile(InputStream content) {
88-
try (var input = new BufferedInputStream(content)) {
89-
input.mark(0);
90-
var skipped = input.skip(MAX_CONTENT_SIZE + 1);
91-
if (skipped > MAX_CONTENT_SIZE) {
92-
throw new ErrorResultException("The extension package exceeds the size limit of 512 MB.", HttpStatus.PAYLOAD_TOO_LARGE);
99+
return Observation.createNotStarted("ExtensionService#createExtensionFile", observations).observe(() -> {
100+
try (var input = new BufferedInputStream(content)) {
101+
input.mark(0);
102+
var skipped = input.skip(MAX_CONTENT_SIZE + 1);
103+
if (skipped > MAX_CONTENT_SIZE) {
104+
throw new ErrorResultException("The extension package exceeds the size limit of 512 MB.", HttpStatus.PAYLOAD_TOO_LARGE);
105+
}
106+
107+
var extensionFile = new TempFile("extension_", ".vsix");
108+
try(var out = Files.newOutputStream(extensionFile.getPath())) {
109+
input.reset();
110+
input.transferTo(out);
111+
}
112+
113+
return extensionFile;
114+
} catch (IOException e) {
115+
throw new ErrorResultException("Failed to read extension file", e);
93116
}
94-
95-
var extensionFile = new TempFile("extension_", ".vsix");
96-
try(var out = Files.newOutputStream(extensionFile.getPath())) {
97-
input.reset();
98-
input.transferTo(out);
99-
}
100-
101-
return extensionFile;
102-
} catch (IOException e) {
103-
throw new ErrorResultException("Failed to read extension file", e);
104-
}
117+
});
105118
}
106119

107120
private void checkLicense(ExtensionVersion extVersion, FileResource license) {

server/src/main/java/org/eclipse/openvsx/ExtensionValidator.java

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
********************************************************************************/
1010
package org.eclipse.openvsx;
1111

12+
import io.micrometer.observation.Observation;
13+
import io.micrometer.observation.ObservationRegistry;
1214
import org.apache.commons.lang3.StringUtils;
1315
import org.apache.tika.Tika;
1416
import org.apache.tika.mime.MediaType;
@@ -46,6 +48,11 @@ public class ExtensionValidator {
4648
private final static int GALLERY_COLOR_SIZE = 16;
4749

4850
private final Pattern namePattern = Pattern.compile("[\\w\\-\\+\\$~]+");
51+
private final ObservationRegistry observations;
52+
53+
public ExtensionValidator(ObservationRegistry observations) {
54+
this.observations = observations;
55+
}
4956

5057
public Optional<Issue> validateNamespace(String namespace) {
5158
if (StringUtils.isEmpty(namespace) || namespace.equals("-")) {
@@ -102,57 +109,63 @@ public List<Issue> validateNamespaceDetails(NamespaceDetailsJson json) {
102109
}
103110

104111
public Optional<Issue> validateExtensionName(String name) {
105-
if (StringUtils.isEmpty(name)) {
106-
return Optional.of(new Issue("Name must not be empty."));
107-
}
108-
if (!namePattern.matcher(name).matches()) {
109-
return Optional.of(new Issue("Invalid extension name: " + name));
110-
}
111-
if (name.length() > DEFAULT_STRING_SIZE) {
112-
return Optional.of(new Issue("The extension name exceeds the current limit of " + DEFAULT_STRING_SIZE + " characters."));
113-
}
114-
return Optional.empty();
112+
return Observation.createNotStarted("ExtensionValidator#validateExtensionName", observations).observe(() -> {
113+
if (StringUtils.isEmpty(name)) {
114+
return Optional.of(new Issue("Name must not be empty."));
115+
}
116+
if (!namePattern.matcher(name).matches()) {
117+
return Optional.of(new Issue("Invalid extension name: " + name));
118+
}
119+
if (name.length() > DEFAULT_STRING_SIZE) {
120+
return Optional.of(new Issue("The extension name exceeds the current limit of " + DEFAULT_STRING_SIZE + " characters."));
121+
}
122+
return Optional.empty();
123+
});
115124
}
116125

117126
public Optional<Issue> validateExtensionVersion(String version) {
118-
var issues = new ArrayList<Issue>();
119-
checkVersion(version, issues);
120-
return issues.isEmpty()
121-
? Optional.empty()
122-
: Optional.of(issues.get(0));
127+
return Observation.createNotStarted("ExtensionValidator#validateExtensionVersion", observations).observe(() -> {
128+
var issues = new ArrayList<Issue>();
129+
checkVersion(version, issues);
130+
return issues.isEmpty()
131+
? Optional.empty()
132+
: Optional.of(issues.get(0));
133+
});
123134
}
124135

125136
public List<Issue> validateMetadata(ExtensionVersion extVersion) {
126-
var issues = new ArrayList<Issue>();
127-
checkVersion(extVersion.getVersion(), issues);
128-
checkTargetPlatform(extVersion.getTargetPlatform(), issues);
129-
checkCharacters(extVersion.getDisplayName(), "displayName", issues);
130-
checkFieldSize(extVersion.getDisplayName(), DEFAULT_STRING_SIZE, "displayName", issues);
131-
checkCharacters(extVersion.getDescription(), "description", issues);
132-
checkFieldSize(extVersion.getDescription(), DESCRIPTION_SIZE, "description", issues);
133-
checkCharacters(extVersion.getCategories(), "categories", issues);
134-
checkFieldSize(extVersion.getCategories(), DEFAULT_STRING_SIZE, "categories", issues);
135-
checkCharacters(extVersion.getTags(), "keywords", issues);
136-
checkFieldSize(extVersion.getTags(), DEFAULT_STRING_SIZE, "keywords", issues);
137-
checkCharacters(extVersion.getLicense(), "license", issues);
138-
checkFieldSize(extVersion.getLicense(), DEFAULT_STRING_SIZE, "license", issues);
139-
checkURL(extVersion.getHomepage(), "homepage", issues);
140-
checkFieldSize(extVersion.getHomepage(), DEFAULT_STRING_SIZE, "homepage", issues);
141-
checkURL(extVersion.getRepository(), "repository", issues);
142-
checkFieldSize(extVersion.getRepository(), DEFAULT_STRING_SIZE, "repository", issues);
143-
checkURL(extVersion.getBugs(), "bugs", issues);
144-
checkFieldSize(extVersion.getBugs(), DEFAULT_STRING_SIZE, "bugs", issues);
145-
checkInvalid(extVersion.getMarkdown(), s -> !MARKDOWN_VALUES.contains(s), "markdown", issues,
146-
MARKDOWN_VALUES.toString());
147-
checkCharacters(extVersion.getGalleryColor(), "galleryBanner.color", issues);
148-
checkFieldSize(extVersion.getGalleryColor(), GALLERY_COLOR_SIZE, "galleryBanner.color", issues);
149-
checkInvalid(extVersion.getGalleryTheme(), s -> !GALLERY_THEME_VALUES.contains(s), "galleryBanner.theme", issues,
150-
GALLERY_THEME_VALUES.toString());
151-
checkFieldSize(extVersion.getLocalizedLanguages(), DEFAULT_STRING_SIZE, "localizedLanguages", issues);
152-
checkInvalid(extVersion.getQna(), s -> !QNA_VALUES.contains(s) && isInvalidURL(s), "qna", issues,
153-
QNA_VALUES.toString() + " or a URL");
154-
checkFieldSize(extVersion.getQna(), DEFAULT_STRING_SIZE, "qna", issues);
155-
return issues;
137+
return Observation.createNotStarted("ExtensionValidator#validateMetadata", observations).observe(() -> {
138+
var issues = new ArrayList<Issue>();
139+
checkVersion(extVersion.getVersion(), issues);
140+
checkTargetPlatform(extVersion.getTargetPlatform(), issues);
141+
checkCharacters(extVersion.getDisplayName(), "displayName", issues);
142+
checkFieldSize(extVersion.getDisplayName(), DEFAULT_STRING_SIZE, "displayName", issues);
143+
checkCharacters(extVersion.getDescription(), "description", issues);
144+
checkFieldSize(extVersion.getDescription(), DESCRIPTION_SIZE, "description", issues);
145+
checkCharacters(extVersion.getCategories(), "categories", issues);
146+
checkFieldSize(extVersion.getCategories(), DEFAULT_STRING_SIZE, "categories", issues);
147+
checkCharacters(extVersion.getTags(), "keywords", issues);
148+
checkFieldSize(extVersion.getTags(), DEFAULT_STRING_SIZE, "keywords", issues);
149+
checkCharacters(extVersion.getLicense(), "license", issues);
150+
checkFieldSize(extVersion.getLicense(), DEFAULT_STRING_SIZE, "license", issues);
151+
checkURL(extVersion.getHomepage(), "homepage", issues);
152+
checkFieldSize(extVersion.getHomepage(), DEFAULT_STRING_SIZE, "homepage", issues);
153+
checkURL(extVersion.getRepository(), "repository", issues);
154+
checkFieldSize(extVersion.getRepository(), DEFAULT_STRING_SIZE, "repository", issues);
155+
checkURL(extVersion.getBugs(), "bugs", issues);
156+
checkFieldSize(extVersion.getBugs(), DEFAULT_STRING_SIZE, "bugs", issues);
157+
checkInvalid(extVersion.getMarkdown(), s -> !MARKDOWN_VALUES.contains(s), "markdown", issues,
158+
MARKDOWN_VALUES.toString());
159+
checkCharacters(extVersion.getGalleryColor(), "galleryBanner.color", issues);
160+
checkFieldSize(extVersion.getGalleryColor(), GALLERY_COLOR_SIZE, "galleryBanner.color", issues);
161+
checkInvalid(extVersion.getGalleryTheme(), s -> !GALLERY_THEME_VALUES.contains(s), "galleryBanner.theme", issues,
162+
GALLERY_THEME_VALUES.toString());
163+
checkFieldSize(extVersion.getLocalizedLanguages(), DEFAULT_STRING_SIZE, "localizedLanguages", issues);
164+
checkInvalid(extVersion.getQna(), s -> !QNA_VALUES.contains(s) && isInvalidURL(s), "qna", issues,
165+
QNA_VALUES.toString() + " or a URL");
166+
checkFieldSize(extVersion.getQna(), DEFAULT_STRING_SIZE, "qna", issues);
167+
return issues;
168+
});
156169
}
157170

158171
private void checkVersion(String version, List<Issue> issues) {
@@ -163,11 +176,14 @@ private void checkVersion(String version, List<Issue> issues) {
163176
if (version.equals(VersionAlias.LATEST) || version.equals(VersionAlias.PRE_RELEASE) || version.equals("reviews")) {
164177
issues.add(new Issue("The version string '" + version + "' is reserved."));
165178
}
166-
try {
167-
SemanticVersion.parse(version);
168-
} catch (RuntimeException e) {
169-
issues.add(new Issue(e.getMessage()));
170-
}
179+
180+
Observation.createNotStarted("SemanticVersion#parse", observations).observe(() -> {
181+
try {
182+
SemanticVersion.parse(version);
183+
} catch (RuntimeException e) {
184+
issues.add(new Issue(e.getMessage()));
185+
}
186+
});
171187
}
172188

173189
private void checkTargetPlatform(String targetPlatform, List<Issue> issues) {

server/src/main/java/org/eclipse/openvsx/IExtensionRegistry.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
********************************************************************************/
1010
package org.eclipse.openvsx;
1111

12-
import io.micrometer.observation.annotation.Observed;
1312
import org.eclipse.openvsx.json.*;
1413
import org.eclipse.openvsx.search.ISearchService;
1514
import org.springframework.http.ResponseEntity;
@@ -39,7 +38,6 @@ public interface IExtensionRegistry {
3938

4039
QueryResultJson queryV2(QueryRequestV2 request);
4140

42-
@Observed
4341
NamespaceDetailsJson getNamespaceDetails(String namespace);
4442

4543
ResponseEntity<byte[]> getNamespaceLogo(String namespaceName, String fileName);

0 commit comments

Comments
 (0)