From 05152c35f3d055ab20b759858f26bb2aef114f2f Mon Sep 17 00:00:00 2001 From: amvanbaren Date: Wed, 25 Sep 2024 18:40:49 +0300 Subject: [PATCH] Remove unused observations Enable download count observations --- .../eclipse/openvsx/ExtensionProcessor.java | 400 ++++++++---------- .../org/eclipse/openvsx/ExtensionService.java | 73 ++-- .../eclipse/openvsx/ExtensionValidator.java | 115 +++-- .../eclipse/openvsx/LocalRegistryService.java | 195 ++++----- .../java/org/eclipse/openvsx/RegistryAPI.java | 63 ++- .../java/org/eclipse/openvsx/UserService.java | 76 ++-- .../eclipse/openvsx/cache/CacheService.java | 76 ++-- .../openvsx/eclipse/EclipseService.java | 53 +-- ...allyMaliciousExtensionVersionsService.java | 3 +- .../ExtractResourcesJobRequestHandler.java | 3 +- ...ExtractVsixManifestsJobRequestHandler.java | 3 +- .../FixTargetPlatformsJobRequestHandler.java | 3 +- ...nerateSha256ChecksumJobRequestHandler.java | 3 +- .../migration/SetPreReleaseJobService.java | 3 +- .../PublishExtensionVersionHandler.java | 197 ++++----- .../ExtensionVersionJooqRepository.java | 2 - .../repositories/RepositoryService.java | 41 +- .../openvsx/search/SearchUtilService.java | 11 +- .../storage/AzureDownloadCountProcessor.java | 24 +- .../storage/AzureDownloadCountService.java | 48 +-- .../openvsx/storage/LocalStorageService.java | 2 - .../openvsx/storage/StorageUtilService.java | 34 +- .../org/eclipse/openvsx/util/ArchiveUtil.java | 38 +- .../openvsx/ExtensionProcessorTest.java | 9 +- .../openvsx/ExtensionValidatorTest.java | 10 +- .../org/eclipse/openvsx/RegistryAPITest.java | 33 +- .../java/org/eclipse/openvsx/UserAPITest.java | 6 - .../openvsx/adapter/VSCodeAPITest.java | 17 +- .../eclipse/openvsx/admin/AdminAPITest.java | 27 +- .../openvsx/cache/CacheServiceTest.java | 5 +- .../openvsx/eclipse/EclipseServiceTest.java | 26 +- .../ExtensionVersionIntegrityServiceTest.java | 7 +- .../search/DatabaseSearchServiceTest.java | 6 - .../search/ElasticSearchServiceTest.java | 6 - .../eclipse/openvsx/util/ArchiveUtilTest.java | 5 +- 35 files changed, 679 insertions(+), 944 deletions(-) diff --git a/server/src/main/java/org/eclipse/openvsx/ExtensionProcessor.java b/server/src/main/java/org/eclipse/openvsx/ExtensionProcessor.java index 0d24f5708..374b827c9 100644 --- a/server/src/main/java/org/eclipse/openvsx/ExtensionProcessor.java +++ b/server/src/main/java/org/eclipse/openvsx/ExtensionProcessor.java @@ -14,8 +14,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.MissingNode; import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.openvsx.adapter.ExtensionQueryResult; @@ -51,15 +49,13 @@ public class ExtensionProcessor implements AutoCloseable { protected final Logger logger = LoggerFactory.getLogger(ExtensionProcessor.class); private final TempFile extensionFile; - private final ObservationRegistry observations; private ZipFile zipFile; private JsonNode packageJson; private JsonNode vsixManifest; - public ExtensionProcessor(TempFile extensionFile, ObservationRegistry observations) { + public ExtensionProcessor(TempFile extensionFile) { this.extensionFile = extensionFile; - this.observations = observations; } @Override @@ -74,68 +70,62 @@ public void close() { } private void readInputStream() { - Observation.createNotStarted("ExtensionProcessor#readInputStream", observations).observe(() -> { - if (zipFile != null) { - return; - } - try { - zipFile = new ZipFile(extensionFile.getPath().toFile()); - } catch (ZipException exc) { - throw new ErrorResultException("Could not read zip file: " + exc.getMessage()); - } catch (EOFException exc) { - throw new ErrorResultException("Could not read from input stream: " + exc.getMessage()); - } catch (IOException exc) { - throw new RuntimeException(exc); - } - }); + if (zipFile != null) { + return; + } + try { + zipFile = new ZipFile(extensionFile.getPath().toFile()); + } catch (ZipException exc) { + throw new ErrorResultException("Could not read zip file: " + exc.getMessage()); + } catch (EOFException exc) { + throw new ErrorResultException("Could not read from input stream: " + exc.getMessage()); + } catch (IOException exc) { + throw new RuntimeException(exc); + } } private void loadPackageJson() { - Observation.createNotStarted("ExtensionProcessor#loadPackageJson", observations).observe(() -> { - if (packageJson != null) { - return; - } - readInputStream(); + if (packageJson != null) { + return; + } + readInputStream(); - // Read package.json - var bytes = ArchiveUtil.readEntry(zipFile, PACKAGE_JSON, observations); - if (bytes == null) - throw new ErrorResultException("Entry not found: " + PACKAGE_JSON); - try { - var mapper = new ObjectMapper(); - packageJson = mapper.readTree(bytes); - } catch (JsonParseException exc) { - throw new ErrorResultException("Invalid JSON format in " + PACKAGE_JSON - + ": " + exc.getMessage()); - } catch (IOException exc) { - throw new RuntimeException(exc); - } - }); + // Read package.json + var bytes = ArchiveUtil.readEntry(zipFile, PACKAGE_JSON); + if (bytes == null) + throw new ErrorResultException("Entry not found: " + PACKAGE_JSON); + try { + var mapper = new ObjectMapper(); + packageJson = mapper.readTree(bytes); + } catch (JsonParseException exc) { + throw new ErrorResultException("Invalid JSON format in " + PACKAGE_JSON + + ": " + exc.getMessage()); + } catch (IOException exc) { + throw new RuntimeException(exc); + } } private void loadVsixManifest() { - Observation.createNotStarted("ExtensionProcessor#loadVsixManifest", observations).observe(() -> { - if (vsixManifest != null) { - return; - } - - readInputStream(); + if (vsixManifest != null) { + return; + } - // Read extension.vsixmanifest - var bytes = ArchiveUtil.readEntry(zipFile, VSIX_MANIFEST, observations); - if (bytes == null) - throw new ErrorResultException("Entry not found: " + VSIX_MANIFEST); + readInputStream(); - try { - var mapper = new XmlMapper(); - vsixManifest = mapper.readTree(bytes); - } catch (JsonParseException exc) { - throw new ErrorResultException("Invalid JSON format in " + VSIX_MANIFEST - + ": " + exc.getMessage()); - } catch (IOException exc) { - throw new RuntimeException(exc); - } - }); + // Read extension.vsixmanifest + var bytes = ArchiveUtil.readEntry(zipFile, VSIX_MANIFEST); + if (bytes == null) + throw new ErrorResultException("Entry not found: " + VSIX_MANIFEST); + + try { + var mapper = new XmlMapper(); + vsixManifest = mapper.readTree(bytes); + } catch (JsonParseException exc) { + throw new ErrorResultException("Invalid JSON format in " + VSIX_MANIFEST + + ": " + exc.getMessage()); + } catch (IOException exc) { + throw new RuntimeException(exc); + } } private JsonNode findByIdInArray(Iterable iter, String id) { @@ -149,197 +139,157 @@ private JsonNode findByIdInArray(Iterable iter, String id) { } public String getExtensionName() { - return Observation.createNotStarted("ExtensionProcessor#getExtensionName", observations).observe(() -> { - loadVsixManifest(); - return vsixManifest.path("Metadata").path("Identity").path("Id").asText(); - }); + loadVsixManifest(); + return vsixManifest.path("Metadata").path("Identity").path("Id").asText(); } public String getNamespace() { - return Observation.createNotStarted("ExtensionProcessor#getNamespace", observations).observe(() -> { - loadVsixManifest(); - return vsixManifest.path("Metadata").path("Identity").path("Publisher").asText(); - }); + loadVsixManifest(); + return vsixManifest.path("Metadata").path("Identity").path("Publisher").asText(); } public List getExtensionDependencies() { - return Observation.createNotStarted("ExtensionProcessor#getExtensionDependencies", observations).observe(() -> { - loadVsixManifest(); - var extDepenNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.ExtensionDependencies"); - return asStringList(extDepenNode.path("Value").asText(), ","); - }); + loadVsixManifest(); + var extDepenNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.ExtensionDependencies"); + return asStringList(extDepenNode.path("Value").asText(), ","); } public List getBundledExtensions() { - return Observation.createNotStarted("ExtensionProcessor#getBundledExtensions", observations).observe(() -> { - loadVsixManifest(); - var extPackNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.ExtensionPack"); - return asStringList(extPackNode.path("Value").asText(), ","); - }); + loadVsixManifest(); + var extPackNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.ExtensionPack"); + return asStringList(extPackNode.path("Value").asText(), ","); } public List getExtensionKinds() { - return Observation.createNotStarted("ExtensionProcessor#getExtensionKinds", observations).observe(() -> { - loadVsixManifest(); - var extKindNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.ExtensionKind"); - return asStringList(extKindNode.path("Value").asText(), ","); - }); + loadVsixManifest(); + var extKindNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.ExtensionKind"); + return asStringList(extKindNode.path("Value").asText(), ","); } public String getHomepage() { - return Observation.createNotStarted("ExtensionProcessor#getHomepage", observations).observe(() -> { - loadVsixManifest(); - var extKindNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Services.Links.Learn"); - return extKindNode.path("Value").asText(); - }); + loadVsixManifest(); + var extKindNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Services.Links.Learn"); + return extKindNode.path("Value").asText(); } public String getRepository() { - return Observation.createNotStarted("ExtensionProcessor#getRepository", observations).observe(() -> { - loadVsixManifest(); - var sourceNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Services.Links.Source"); - return sourceNode.path("Value").asText(); - }); + loadVsixManifest(); + var sourceNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Services.Links.Source"); + return sourceNode.path("Value").asText(); } public String getBugs() { - return Observation.createNotStarted("ExtensionProcessor#getBugs", observations).observe(() -> { - loadVsixManifest(); - var supportNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Services.Links.Support"); - return supportNode.path("Value").asText(); - }); + loadVsixManifest(); + var supportNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Services.Links.Support"); + return supportNode.path("Value").asText(); } public String getGalleryColor() { - return Observation.createNotStarted("ExtensionProcessor#getGalleryColor", observations).observe(() -> { - loadVsixManifest(); - var colorNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Services.Branding.Color"); - return colorNode.path("Value").asText(); - }); + loadVsixManifest(); + var colorNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Services.Branding.Color"); + return colorNode.path("Value").asText(); } public String getGalleryTheme() { - return Observation.createNotStarted("ExtensionProcessor#getGalleryTheme", observations).observe(() -> { - loadVsixManifest(); - var themeNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Services.Branding.Theme"); - return themeNode.path("Value").asText(); - }); + loadVsixManifest(); + var themeNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Services.Branding.Theme"); + return themeNode.path("Value").asText(); } public List getLocalizedLanguages() { - return Observation.createNotStarted("ExtensionProcessor#getLocalizedLanguages", observations).observe(() -> { - loadVsixManifest(); - var languagesNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.LocalizedLanguages"); - return asStringList(languagesNode.path("Value").asText(), ","); - }); + loadVsixManifest(); + var languagesNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.LocalizedLanguages"); + return asStringList(languagesNode.path("Value").asText(), ","); } public boolean isPreview() { - return Observation.createNotStarted("ExtensionProcessor#isPreview", observations).observe(() -> { - loadVsixManifest(); - var galleryFlags = vsixManifest.path("Metadata").path("GalleryFlags"); - return asStringList(galleryFlags.asText(), " ").contains("Preview"); - }); + loadVsixManifest(); + var galleryFlags = vsixManifest.path("Metadata").path("GalleryFlags"); + return asStringList(galleryFlags.asText(), " ").contains("Preview"); } public boolean isPreRelease() { - return Observation.createNotStarted("ExtensionProcessor#isPreRelease", observations).observe(() -> { - loadVsixManifest(); - var preReleaseNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.PreRelease"); - return preReleaseNode.path("Value").asBoolean(false); - }); + loadVsixManifest(); + var preReleaseNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.PreRelease"); + return preReleaseNode.path("Value").asBoolean(false); } public String getSponsorLink() { - return Observation.createNotStarted("ExtensionProcessor#getSponsorLink", observations).observe(() -> { - loadVsixManifest(); - var sponsorLinkNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.SponsorLink"); - return sponsorLinkNode.path("Value").asText(); - }); + loadVsixManifest(); + var sponsorLinkNode = findByIdInArray(vsixManifest.path("Metadata").path("Properties").path("Property"), "Microsoft.VisualStudio.Code.SponsorLink"); + return sponsorLinkNode.path("Value").asText(); } public ExtensionVersion getMetadata() { - return Observation.createNotStarted("ExtensionProcessor#getMetadata", observations).observe(() -> { - loadPackageJson(); - loadVsixManifest(); - var extVersion = new ExtensionVersion(); - extVersion.setVersion(getVersion()); - extVersion.setTargetPlatform(getTargetPlatform()); - extVersion.setPreview(isPreview()); - extVersion.setPreRelease(isPreRelease()); - extVersion.setDisplayName(vsixManifest.path("Metadata").path("DisplayName").asText()); - extVersion.setDescription(vsixManifest.path("Metadata").path("Description").path("").asText()); - extVersion.setEngines(getEngines(packageJson.path("engines"))); - extVersion.setCategories(asStringList(vsixManifest.path("Metadata").path("Categories").asText(), ",")); - extVersion.setExtensionKind(getExtensionKinds()); - extVersion.setTags(getTags()); - extVersion.setLicense(packageJson.path("license").textValue()); - extVersion.setHomepage(getHomepage()); - extVersion.setRepository(getRepository()); - extVersion.setSponsorLink(getSponsorLink()); - extVersion.setBugs(getBugs()); - extVersion.setMarkdown(packageJson.path("markdown").textValue()); - extVersion.setGalleryColor(getGalleryColor()); - extVersion.setGalleryTheme(getGalleryTheme()); - extVersion.setLocalizedLanguages(getLocalizedLanguages()); - extVersion.setQna(packageJson.path("qna").textValue()); - - return extVersion; - }); + loadPackageJson(); + loadVsixManifest(); + var extVersion = new ExtensionVersion(); + extVersion.setVersion(getVersion()); + extVersion.setTargetPlatform(getTargetPlatform()); + extVersion.setPreview(isPreview()); + extVersion.setPreRelease(isPreRelease()); + extVersion.setDisplayName(vsixManifest.path("Metadata").path("DisplayName").asText()); + extVersion.setDescription(vsixManifest.path("Metadata").path("Description").path("").asText()); + extVersion.setEngines(getEngines(packageJson.path("engines"))); + extVersion.setCategories(asStringList(vsixManifest.path("Metadata").path("Categories").asText(), ",")); + extVersion.setExtensionKind(getExtensionKinds()); + extVersion.setTags(getTags()); + extVersion.setLicense(packageJson.path("license").textValue()); + extVersion.setHomepage(getHomepage()); + extVersion.setRepository(getRepository()); + extVersion.setSponsorLink(getSponsorLink()); + extVersion.setBugs(getBugs()); + extVersion.setMarkdown(packageJson.path("markdown").textValue()); + extVersion.setGalleryColor(getGalleryColor()); + extVersion.setGalleryTheme(getGalleryTheme()); + extVersion.setLocalizedLanguages(getLocalizedLanguages()); + extVersion.setQna(packageJson.path("qna").textValue()); + + return extVersion; } public String getVersion() { - return Observation.createNotStarted("ExtensionProcessor#getVersion", observations).observe(() -> { - return vsixManifest.path("Metadata").path("Identity").path("Version").asText(); - }); + return vsixManifest.path("Metadata").path("Identity").path("Version").asText(); } private String getTargetPlatform() { - return Observation.createNotStarted("ExtensionProcessor#getTargetPlatform", observations).observe(() -> { - var targetPlatform = vsixManifest.path("Metadata").path("Identity").path("TargetPlatform").asText(); - if (targetPlatform.isEmpty()) { - targetPlatform = TargetPlatform.NAME_UNIVERSAL; - } + var targetPlatform = vsixManifest.path("Metadata").path("Identity").path("TargetPlatform").asText(); + if (targetPlatform.isEmpty()) { + targetPlatform = TargetPlatform.NAME_UNIVERSAL; + } - return targetPlatform; - }); + return targetPlatform; } private List getTags() { - return Observation.createNotStarted("ExtensionProcessor#getTags", observations).observe(() -> { - var tags = vsixManifest.path("Metadata").path("Tags").asText(); - return asStringList(tags, ",").stream() - .collect(Collectors.groupingBy(String::toLowerCase)) - .entrySet().stream() - .sorted(Map.Entry.comparingByKey()) - .map(e -> e.getValue().get(0)) - .collect(Collectors.toList()); - }); + var tags = vsixManifest.path("Metadata").path("Tags").asText(); + return asStringList(tags, ",").stream() + .collect(Collectors.groupingBy(String::toLowerCase)) + .entrySet().stream() + .sorted(Map.Entry.comparingByKey()) + .map(e -> e.getValue().get(0)) + .collect(Collectors.toList()); } private List asStringList(String value, String sep){ - return Observation.createNotStarted("ExtensionProcessor#asStringList", observations).observe(() -> { - if (StringUtils.isEmpty(value)) { - return new ArrayList<>(); - } + if (StringUtils.isEmpty(value)) { + return new ArrayList<>(); + } - return Arrays.asList(value.split(sep)); - }); + return Arrays.asList(value.split(sep)); } private List getEngines(JsonNode node) { - return Observation.createNotStarted("ExtensionProcessor#getEngines", observations).observe(() -> { - if (node.isObject()) { - var result = new ArrayList(); - var fieldIter = node.fields(); - while (fieldIter.hasNext()) { - var entry = fieldIter.next(); - result.add(entry.getKey() + "@" + entry.getValue().textValue()); - } - return result; + if (node.isObject()) { + var result = new ArrayList(); + var fieldIter = node.fields(); + while (fieldIter.hasNext()) { + var entry = fieldIter.next(); + result.add(entry.getKey() + "@" + entry.getValue().textValue()); } - return null; - }); + return result; + } + return null; } public List getFileResources(ExtensionVersion extVersion) { @@ -359,7 +309,7 @@ public void processEachResource(ExtensionVersion extVersion, Consumer { byte[] bytes; try { - bytes = ArchiveUtil.readEntry(zipFile, zipEntry, ObservationRegistry.NOOP); + bytes = ArchiveUtil.readEntry(zipFile, zipEntry); } catch(ErrorResultException exc) { logger.warn(exc.getMessage()); bytes = null; @@ -379,14 +329,12 @@ public void processEachResource(ExtensionVersion extVersion, Consumer { - var binary = new FileResource(); - binary.setExtension(extVersion); - binary.setName(Optional.ofNullable(binaryName).orElse(NamingUtil.toFileFormat(extVersion, ".vsix"))); - binary.setType(FileResource.DOWNLOAD); - binary.setContent(null); - return binary; - }); + var binary = new FileResource(); + binary.setExtension(extVersion); + binary.setName(Optional.ofNullable(binaryName).orElse(NamingUtil.toFileFormat(extVersion, ".vsix"))); + binary.setType(FileResource.DOWNLOAD); + binary.setContent(null); + return binary; } public FileResource generateSha256Checksum(ExtensionVersion extVersion) { @@ -411,7 +359,7 @@ public FileResource generateSha256Checksum(ExtensionVersion extVersion) { protected FileResource getManifest(ExtensionVersion extVersion) { readInputStream(); - var bytes = ArchiveUtil.readEntry(zipFile, PACKAGE_JSON, ObservationRegistry.NOOP); + var bytes = ArchiveUtil.readEntry(zipFile, PACKAGE_JSON); if (bytes == null) { return null; } @@ -452,31 +400,29 @@ public FileResource getChangelog(ExtensionVersion extVersion) { } public FileResource getLicense(ExtensionVersion extVersion) { - return Observation.createNotStarted("ExtensionProcessor#getLicense", observations).observe(() -> { - readInputStream(); - var license = new FileResource(); - license.setExtension(extVersion); - license.setType(FileResource.LICENSE); - - var assetPath = tryGetLicensePath(); - if (StringUtils.isNotEmpty(assetPath)) { - var bytes = ArchiveUtil.readEntry(zipFile, assetPath, observations); - var lastSegmentIndex = assetPath.lastIndexOf('/'); - var lastSegment = assetPath.substring(lastSegmentIndex + 1); - - license.setName(lastSegment); - license.setContent(bytes); - return license; - } + readInputStream(); + var license = new FileResource(); + license.setExtension(extVersion); + license.setType(FileResource.LICENSE); - return null; - }); + var assetPath = tryGetLicensePath(); + if (StringUtils.isNotEmpty(assetPath)) { + var bytes = ArchiveUtil.readEntry(zipFile, assetPath); + var lastSegmentIndex = assetPath.lastIndexOf('/'); + var lastSegment = assetPath.substring(lastSegmentIndex + 1); + + license.setName(lastSegment); + license.setContent(bytes); + return license; + } + + return null; } private Pair readFromVsixPackage(String assetType, String[] alternateNames) { var assetPath = tryGetAssetPath(assetType); if(StringUtils.isNotEmpty(assetPath)) { - var bytes = ArchiveUtil.readEntry(zipFile, assetPath, ObservationRegistry.NOOP); + var bytes = ArchiveUtil.readEntry(zipFile, assetPath); var lastSegmentIndex = assetPath.lastIndexOf('/'); var lastSegment = assetPath.substring(lastSegmentIndex + 1); return Pair.of(bytes, lastSegment); @@ -490,7 +436,7 @@ private Pair readFromAlternateNames(String[] names) { for (var name : names) { var entry = ArchiveUtil.getEntryIgnoreCase(zipFile, name); if (entry != null) { - var bytes = ArchiveUtil.readEntry(zipFile, entry, ObservationRegistry.NOOP); + var bytes = ArchiveUtil.readEntry(zipFile, entry); var lastSegmentIndex = entry.getName().lastIndexOf('/'); var lastSegment = entry.getName().substring(lastSegmentIndex + 1); return Pair.of(bytes, lastSegment); @@ -500,13 +446,11 @@ private Pair readFromAlternateNames(String[] names) { } private String tryGetLicensePath() { - return Observation.createNotStarted("ExtensionProcessor#tryGetLicensePath", observations).observe(() -> { - loadVsixManifest(); - var licensePath = vsixManifest.path("Metadata").path("License").asText(); - return licensePath.isEmpty() - ? tryGetAssetPath(ExtensionQueryResult.ExtensionFile.FILE_LICENSE) - : licensePath; - }); + loadVsixManifest(); + var licensePath = vsixManifest.path("Metadata").path("License").asText(); + return licensePath.isEmpty() + ? tryGetAssetPath(ExtensionQueryResult.ExtensionFile.FILE_LICENSE) + : licensePath; } private String tryGetAssetPath(String type) { @@ -536,7 +480,7 @@ protected FileResource getIcon(ExtensionVersion extVersion) { return null; } - var bytes = ArchiveUtil.readEntry(zipFile, iconPath, ObservationRegistry.NOOP); + var bytes = ArchiveUtil.readEntry(zipFile, iconPath); if (bytes == null) { return null; } @@ -560,7 +504,7 @@ public FileResource getVsixManifest(ExtensionVersion extVersion) { vsixManifest.setExtension(extVersion); vsixManifest.setName(VSIX_MANIFEST); vsixManifest.setType(FileResource.VSIXMANIFEST); - vsixManifest.setContent(ArchiveUtil.readEntry(zipFile, VSIX_MANIFEST, ObservationRegistry.NOOP)); + vsixManifest.setContent(ArchiveUtil.readEntry(zipFile, VSIX_MANIFEST)); return vsixManifest; } diff --git a/server/src/main/java/org/eclipse/openvsx/ExtensionService.java b/server/src/main/java/org/eclipse/openvsx/ExtensionService.java index fb05fb473..1932f07a0 100644 --- a/server/src/main/java/org/eclipse/openvsx/ExtensionService.java +++ b/server/src/main/java/org/eclipse/openvsx/ExtensionService.java @@ -9,8 +9,6 @@ ********************************************************************************/ package org.eclipse.openvsx; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; import jakarta.transaction.Transactional; import jakarta.transaction.Transactional.TxType; import org.apache.commons.lang3.StringUtils; @@ -42,7 +40,6 @@ public class ExtensionService { private final SearchUtilService search; private final CacheService cache; private final PublishExtensionVersionHandler publishHandler; - private final ObservationRegistry observations; @Value("${ovsx.publishing.require-license:false}") boolean requireLicense; @@ -51,14 +48,12 @@ public ExtensionService( RepositoryService repositories, SearchUtilService search, CacheService cache, - PublishExtensionVersionHandler publishHandler, - ObservationRegistry observations + PublishExtensionVersionHandler publishHandler ) { this.repositories = repositories; this.search = search; this.cache = cache; this.publishHandler = publishHandler; - this.observations = observations; } @Transactional @@ -69,50 +64,44 @@ public ExtensionVersion mirrorVersion(TempFile extensionFile, String signatureNa } public ExtensionVersion publishVersion(InputStream content, PersonalAccessToken token) throws ErrorResultException { - return Observation.createNotStarted("ExtensionService#publishVersion", observations).observe(() -> { - var extensionFile = createExtensionFile(content); - var download = doPublish(extensionFile, null, token, TimeUtil.getCurrentUTC(), true); - publishHandler.publishAsync(download, extensionFile, this); - publishHandler.schedulePublicIdJob(download); - return download.getExtension(); - }); + var extensionFile = createExtensionFile(content); + var download = doPublish(extensionFile, null, token, TimeUtil.getCurrentUTC(), true); + publishHandler.publishAsync(download, extensionFile, this); + publishHandler.schedulePublicIdJob(download); + return download.getExtension(); } private FileResource doPublish(TempFile extensionFile, String binaryName, PersonalAccessToken token, LocalDateTime timestamp, boolean checkDependencies) { - return Observation.createNotStarted("ExtensionService#doPublish", observations).observe(() -> { - try (var processor = new ExtensionProcessor(extensionFile, observations)) { - var extVersion = publishHandler.createExtensionVersion(processor, token, timestamp, checkDependencies); - if (requireLicense) { - // Check the extension's license - var license = processor.getLicense(extVersion); - Observation.createNotStarted("ExtensionService#checkLicense", observations).observe(() -> checkLicense(extVersion, license)); - } - - return processor.getBinary(extVersion, binaryName); + try (var processor = new ExtensionProcessor(extensionFile)) { + var extVersion = publishHandler.createExtensionVersion(processor, token, timestamp, checkDependencies); + if (requireLicense) { + // Check the extension's license + var license = processor.getLicense(extVersion); + checkLicense(extVersion, license); } - }); + + return processor.getBinary(extVersion, binaryName); + } } private TempFile createExtensionFile(InputStream content) { - return Observation.createNotStarted("ExtensionService#createExtensionFile", observations).observe(() -> { - try (var input = new BufferedInputStream(content)) { - input.mark(0); - var skipped = input.skip(MAX_CONTENT_SIZE + 1); - if (skipped > MAX_CONTENT_SIZE) { - throw new ErrorResultException("The extension package exceeds the size limit of 512 MB.", HttpStatus.PAYLOAD_TOO_LARGE); - } - - var extensionFile = new TempFile("extension_", ".vsix"); - try(var out = Files.newOutputStream(extensionFile.getPath())) { - input.reset(); - input.transferTo(out); - } - - return extensionFile; - } catch (IOException e) { - throw new ErrorResultException("Failed to read extension file", e); + try (var input = new BufferedInputStream(content)) { + input.mark(0); + var skipped = input.skip(MAX_CONTENT_SIZE + 1); + if (skipped > MAX_CONTENT_SIZE) { + throw new ErrorResultException("The extension package exceeds the size limit of 512 MB.", HttpStatus.PAYLOAD_TOO_LARGE); } - }); + + var extensionFile = new TempFile("extension_", ".vsix"); + try(var out = Files.newOutputStream(extensionFile.getPath())) { + input.reset(); + input.transferTo(out); + } + + return extensionFile; + } catch (IOException e) { + throw new ErrorResultException("Failed to read extension file", e); + } } private void checkLicense(ExtensionVersion extVersion, FileResource license) { diff --git a/server/src/main/java/org/eclipse/openvsx/ExtensionValidator.java b/server/src/main/java/org/eclipse/openvsx/ExtensionValidator.java index 2c16e9b76..ff1b4f868 100644 --- a/server/src/main/java/org/eclipse/openvsx/ExtensionValidator.java +++ b/server/src/main/java/org/eclipse/openvsx/ExtensionValidator.java @@ -9,8 +9,6 @@ ********************************************************************************/ package org.eclipse.openvsx; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; import org.apache.commons.lang3.StringUtils; import org.apache.tika.Tika; import org.apache.tika.mime.MediaType; @@ -48,11 +46,6 @@ public class ExtensionValidator { private final static int GALLERY_COLOR_SIZE = 16; private final Pattern namePattern = Pattern.compile("[\\w\\-\\+\\$~]+"); - private final ObservationRegistry observations; - - public ExtensionValidator(ObservationRegistry observations) { - this.observations = observations; - } public Optional validateNamespace(String namespace) { if (StringUtils.isEmpty(namespace) || namespace.equals("-")) { @@ -109,63 +102,57 @@ public List validateNamespaceDetails(NamespaceDetailsJson json) { } public Optional validateExtensionName(String name) { - return Observation.createNotStarted("ExtensionValidator#validateExtensionName", observations).observe(() -> { - if (StringUtils.isEmpty(name)) { - return Optional.of(new Issue("Name must not be empty.")); - } - if (!namePattern.matcher(name).matches()) { - return Optional.of(new Issue("Invalid extension name: " + name)); - } - if (name.length() > DEFAULT_STRING_SIZE) { - return Optional.of(new Issue("The extension name exceeds the current limit of " + DEFAULT_STRING_SIZE + " characters.")); - } - return Optional.empty(); - }); + if (StringUtils.isEmpty(name)) { + return Optional.of(new Issue("Name must not be empty.")); + } + if (!namePattern.matcher(name).matches()) { + return Optional.of(new Issue("Invalid extension name: " + name)); + } + if (name.length() > DEFAULT_STRING_SIZE) { + return Optional.of(new Issue("The extension name exceeds the current limit of " + DEFAULT_STRING_SIZE + " characters.")); + } + return Optional.empty(); } public Optional validateExtensionVersion(String version) { - return Observation.createNotStarted("ExtensionValidator#validateExtensionVersion", observations).observe(() -> { - var issues = new ArrayList(); - checkVersion(version, issues); - return issues.isEmpty() - ? Optional.empty() - : Optional.of(issues.get(0)); - }); + var issues = new ArrayList(); + checkVersion(version, issues); + return issues.isEmpty() + ? Optional.empty() + : Optional.of(issues.get(0)); } public List validateMetadata(ExtensionVersion extVersion) { - return Observation.createNotStarted("ExtensionValidator#validateMetadata", observations).observe(() -> { - var issues = new ArrayList(); - checkVersion(extVersion.getVersion(), issues); - checkTargetPlatform(extVersion.getTargetPlatform(), issues); - checkCharacters(extVersion.getDisplayName(), "displayName", issues); - checkFieldSize(extVersion.getDisplayName(), DEFAULT_STRING_SIZE, "displayName", issues); - checkCharacters(extVersion.getDescription(), "description", issues); - checkFieldSize(extVersion.getDescription(), DESCRIPTION_SIZE, "description", issues); - checkCharacters(extVersion.getCategories(), "categories", issues); - checkFieldSize(extVersion.getCategories(), DEFAULT_STRING_SIZE, "categories", issues); - checkCharacters(extVersion.getTags(), "keywords", issues); - checkFieldSize(extVersion.getTags(), DEFAULT_STRING_SIZE, "keywords", issues); - checkCharacters(extVersion.getLicense(), "license", issues); - checkFieldSize(extVersion.getLicense(), DEFAULT_STRING_SIZE, "license", issues); - checkURL(extVersion.getHomepage(), "homepage", issues); - checkFieldSize(extVersion.getHomepage(), DEFAULT_STRING_SIZE, "homepage", issues); - checkURL(extVersion.getRepository(), "repository", issues); - checkFieldSize(extVersion.getRepository(), DEFAULT_STRING_SIZE, "repository", issues); - checkURL(extVersion.getBugs(), "bugs", issues); - checkFieldSize(extVersion.getBugs(), DEFAULT_STRING_SIZE, "bugs", issues); - checkInvalid(extVersion.getMarkdown(), s -> !MARKDOWN_VALUES.contains(s), "markdown", issues, - MARKDOWN_VALUES.toString()); - checkCharacters(extVersion.getGalleryColor(), "galleryBanner.color", issues); - checkFieldSize(extVersion.getGalleryColor(), GALLERY_COLOR_SIZE, "galleryBanner.color", issues); - checkInvalid(extVersion.getGalleryTheme(), s -> !GALLERY_THEME_VALUES.contains(s), "galleryBanner.theme", issues, - GALLERY_THEME_VALUES.toString()); - checkFieldSize(extVersion.getLocalizedLanguages(), DEFAULT_STRING_SIZE, "localizedLanguages", issues); - checkInvalid(extVersion.getQna(), s -> !QNA_VALUES.contains(s) && isInvalidURL(s), "qna", issues, - QNA_VALUES.toString() + " or a URL"); - checkFieldSize(extVersion.getQna(), DEFAULT_STRING_SIZE, "qna", issues); - return issues; - }); + var issues = new ArrayList(); + checkVersion(extVersion.getVersion(), issues); + checkTargetPlatform(extVersion.getTargetPlatform(), issues); + checkCharacters(extVersion.getDisplayName(), "displayName", issues); + checkFieldSize(extVersion.getDisplayName(), DEFAULT_STRING_SIZE, "displayName", issues); + checkCharacters(extVersion.getDescription(), "description", issues); + checkFieldSize(extVersion.getDescription(), DESCRIPTION_SIZE, "description", issues); + checkCharacters(extVersion.getCategories(), "categories", issues); + checkFieldSize(extVersion.getCategories(), DEFAULT_STRING_SIZE, "categories", issues); + checkCharacters(extVersion.getTags(), "keywords", issues); + checkFieldSize(extVersion.getTags(), DEFAULT_STRING_SIZE, "keywords", issues); + checkCharacters(extVersion.getLicense(), "license", issues); + checkFieldSize(extVersion.getLicense(), DEFAULT_STRING_SIZE, "license", issues); + checkURL(extVersion.getHomepage(), "homepage", issues); + checkFieldSize(extVersion.getHomepage(), DEFAULT_STRING_SIZE, "homepage", issues); + checkURL(extVersion.getRepository(), "repository", issues); + checkFieldSize(extVersion.getRepository(), DEFAULT_STRING_SIZE, "repository", issues); + checkURL(extVersion.getBugs(), "bugs", issues); + checkFieldSize(extVersion.getBugs(), DEFAULT_STRING_SIZE, "bugs", issues); + checkInvalid(extVersion.getMarkdown(), s -> !MARKDOWN_VALUES.contains(s), "markdown", issues, + MARKDOWN_VALUES.toString()); + checkCharacters(extVersion.getGalleryColor(), "galleryBanner.color", issues); + checkFieldSize(extVersion.getGalleryColor(), GALLERY_COLOR_SIZE, "galleryBanner.color", issues); + checkInvalid(extVersion.getGalleryTheme(), s -> !GALLERY_THEME_VALUES.contains(s), "galleryBanner.theme", issues, + GALLERY_THEME_VALUES.toString()); + checkFieldSize(extVersion.getLocalizedLanguages(), DEFAULT_STRING_SIZE, "localizedLanguages", issues); + checkInvalid(extVersion.getQna(), s -> !QNA_VALUES.contains(s) && isInvalidURL(s), "qna", issues, + QNA_VALUES.toString() + " or a URL"); + checkFieldSize(extVersion.getQna(), DEFAULT_STRING_SIZE, "qna", issues); + return issues; } private void checkVersion(String version, List issues) { @@ -177,13 +164,11 @@ private void checkVersion(String version, List issues) { issues.add(new Issue("The version string '" + version + "' is reserved.")); } - Observation.createNotStarted("SemanticVersion#parse", observations).observe(() -> { - try { - SemanticVersion.parse(version); - } catch (RuntimeException e) { - issues.add(new Issue(e.getMessage())); - } - }); + try { + SemanticVersion.parse(version); + } catch (RuntimeException e) { + issues.add(new Issue(e.getMessage())); + } } private void checkTargetPlatform(String targetPlatform, List issues) { diff --git a/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java b/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java index f78027bf0..5db35190c 100644 --- a/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java +++ b/server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java @@ -10,8 +10,6 @@ package org.eclipse.openvsx; import com.google.common.collect.Maps; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; import org.apache.commons.lang3.StringUtils; @@ -62,7 +60,6 @@ public class LocalRegistryService implements IExtensionRegistry { private final EclipseService eclipse; private final CacheService cache; private final ExtensionVersionIntegrityService integrityService; - private final ObservationRegistry observations; public LocalRegistryService( EntityManager entityManager, @@ -75,8 +72,7 @@ public LocalRegistryService( StorageUtilService storageUtil, EclipseService eclipse, CacheService cache, - ExtensionVersionIntegrityService integrityService, - ObservationRegistry observations + ExtensionVersionIntegrityService integrityService ) { this.entityManager = entityManager; this.repositories = repositories; @@ -89,7 +85,6 @@ public LocalRegistryService( this.eclipse = eclipse; this.cache = cache; this.integrityService = integrityService; - this.observations = observations; } @Value("${ovsx.webui.url:}") @@ -597,41 +592,37 @@ public ResultJson verifyToken(String namespaceName, String tokenValue) { } public ExtensionJson publish(InputStream content, UserData user) throws ErrorResultException { - return Observation.createNotStarted("LocalRegistryService#publish", observations).observe(() -> { - var token = users.createAccessToken(user, "One time use publish token"); - var json = publish(content, token.value); - users.deleteAccessToken(user, token.id); - return json; - }); + var token = users.createAccessToken(user, "One time use publish token"); + var json = publish(content, token.value); + users.deleteAccessToken(user, token.id); + return json; } public ExtensionJson publish(InputStream content, String tokenValue) throws ErrorResultException { - return Observation.createNotStarted("LocalRegistryService#publish", observations).observe(() -> { - var token = users.useAccessToken(tokenValue); - if (token == null || token.getUser() == null) { - throw new ErrorResultException("Invalid access token."); - } + var token = users.useAccessToken(tokenValue); + if (token == null || token.getUser() == null) { + throw new ErrorResultException("Invalid access token."); + } - // Check whether the user has a valid publisher agreement - eclipse.checkPublisherAgreement(token.getUser()); + // Check whether the user has a valid publisher agreement + eclipse.checkPublisherAgreement(token.getUser()); - var extVersion = extensions.publishVersion(content, token); - var json = toExtensionVersionJson(extVersion, null, true); - json.success = "It can take a couple minutes before the extension version is available"; + var extVersion = extensions.publishVersion(content, token); + var json = toExtensionVersionJson(extVersion, null, true); + json.success = "It can take a couple minutes before the extension version is available"; - if(repositories.hasSameVersion(extVersion)) { - var existingRelease = extVersion.isPreRelease() ? "stable release" : "pre-release"; - var thisRelease = extVersion.isPreRelease() ? "pre-release" : "stable release"; - var extension = extVersion.getExtension(); - var semver = extVersion.getSemanticVersion(); - var newVersion = String.join(".", String.valueOf(semver.getMajor()), String.valueOf(semver.getMinor() + 1), "0"); + if(repositories.hasSameVersion(extVersion)) { + var existingRelease = extVersion.isPreRelease() ? "stable release" : "pre-release"; + var thisRelease = extVersion.isPreRelease() ? "pre-release" : "stable release"; + var extension = extVersion.getExtension(); + var semver = extVersion.getSemanticVersion(); + var newVersion = String.join(".", String.valueOf(semver.getMajor()), String.valueOf(semver.getMinor() + 1), "0"); - json.warning = "A " + existingRelease + " already exists for " + NamingUtil.toLogFormat(extension.getNamespace().getName(), extension.getName(), extVersion.getVersion()) + ".\n" + - "To prevent update conflicts, we recommend that this " + thisRelease + " uses " + newVersion + " as its version instead."; - } + json.warning = "A " + existingRelease + " already exists for " + NamingUtil.toLogFormat(extension.getNamespace().getName(), extension.getName(), extVersion.getVersion()) + ".\n" + + "To prevent update conflicts, we recommend that this " + thisRelease + " uses " + newVersion + " as its version instead."; + } - return json; - }); + return json; } @Transactional(rollbackOn = ResponseStatusException.class) @@ -784,69 +775,67 @@ private List getAllVersionReferences( } public ExtensionJson toExtensionVersionJson(ExtensionVersion extVersion, String targetPlatform, boolean onlyActive) { - return Observation.createNotStarted("LocalRegistryService#toExtensionVersionJson", observations).observe(() -> { - var extension = extVersion.getExtension(); - var latest = repositories.findLatestVersionForAllUrls(extension, targetPlatform, false, onlyActive); - var latestPreRelease = repositories.findLatestVersionForAllUrls(extension, targetPlatform, true, onlyActive); - - var json = extVersion.toExtensionJson(); - if(extension.getReplacement() != null) { - var replacementId = extension.getReplacement().getId(); - var replacement = repositories.findLatestReplacement(replacementId, targetPlatform, false, onlyActive); - if(replacement != null) { - json.replacement = new ExtensionReplacementJson(); - json.replacement.url = UrlUtil.createApiUrl(webuiUrl, "extension", replacement.getExtension().getNamespace().getName(), replacement.getExtension().getName()); - json.replacement.displayName = StringUtils.isNotEmpty(replacement.getDisplayName()) - ? replacement.getDisplayName() - : replacement.getExtension().getName(); - } - } + var extension = extVersion.getExtension(); + var latest = repositories.findLatestVersionForAllUrls(extension, targetPlatform, false, onlyActive); + var latestPreRelease = repositories.findLatestVersionForAllUrls(extension, targetPlatform, true, onlyActive); - json.preview = latest != null && latest.isPreview(); - json.versionAlias = new ArrayList<>(2); - if (latest != null && extVersion.getVersion().equals(latest.getVersion())) - json.versionAlias.add(VersionAlias.LATEST); - if (latestPreRelease != null && extVersion.getVersion().equals(latestPreRelease.getVersion())) - json.versionAlias.add(VersionAlias.PRE_RELEASE); - json.verified = isVerified(extVersion); - json.namespaceAccess = "restricted"; - json.unrelatedPublisher = !json.verified; - json.reviewCount = Optional.ofNullable(extension.getReviewCount()).orElse(0L); - var serverUrl = UrlUtil.getBaseUrl(); - json.namespaceUrl = createApiUrl(serverUrl, "api", json.namespace); - json.reviewsUrl = createApiUrl(serverUrl, "api", json.namespace, json.name, "reviews"); - - var allVersions = new ArrayList(); - if (latest != null) - allVersions.add(VersionAlias.LATEST); - if (latestPreRelease != null) - allVersions.add(VersionAlias.PRE_RELEASE); - - var versionBaseUrl = UrlUtil.createApiVersionBaseUrl(serverUrl, json.namespace, json.name, targetPlatform); - allVersions.addAll(repositories.findVersionStringsSorted(extension, targetPlatform, onlyActive)); - json.allVersionsUrl = UrlUtil.createAllVersionsUrl(json.namespace, json.name, targetPlatform, "versions"); - json.allVersions = Maps.newLinkedHashMapWithExpectedSize(allVersions.size()); - for (var version : allVersions) { - json.allVersions.put(version, createApiUrl(versionBaseUrl, version)); + var json = extVersion.toExtensionJson(); + if(extension.getReplacement() != null) { + var replacementId = extension.getReplacement().getId(); + var replacement = repositories.findLatestReplacement(replacementId, targetPlatform, false, onlyActive); + if(replacement != null) { + json.replacement = new ExtensionReplacementJson(); + json.replacement.url = UrlUtil.createApiUrl(webuiUrl, "extension", replacement.getExtension().getNamespace().getName(), replacement.getExtension().getName()); + json.replacement.displayName = StringUtils.isNotEmpty(replacement.getDisplayName()) + ? replacement.getDisplayName() + : replacement.getExtension().getName(); } + } - var fileUrls = storageUtil.getFileUrls(List.of(extVersion), serverUrl, withFileTypes(DOWNLOAD, MANIFEST, ICON, README, LICENSE, CHANGELOG, VSIXMANIFEST)); - json.files = fileUrls.get(extVersion.getId()); - if (json.files.containsKey(DOWNLOAD_SIG)) { - json.files.put(PUBLIC_KEY, UrlUtil.getPublicKeyUrl(extVersion)); - } - if (json.dependencies != null) { - json.dependencies.forEach(ref -> { - ref.url = createApiUrl(serverUrl, "api", ref.namespace, ref.extension); - }); - } - if (json.bundledExtensions != null) { - json.bundledExtensions.forEach(ref -> { - ref.url = createApiUrl(serverUrl, "api", ref.namespace, ref.extension); - }); - } - return json; - }); + json.preview = latest != null && latest.isPreview(); + json.versionAlias = new ArrayList<>(2); + if (latest != null && extVersion.getVersion().equals(latest.getVersion())) + json.versionAlias.add(VersionAlias.LATEST); + if (latestPreRelease != null && extVersion.getVersion().equals(latestPreRelease.getVersion())) + json.versionAlias.add(VersionAlias.PRE_RELEASE); + json.verified = isVerified(extVersion); + json.namespaceAccess = "restricted"; + json.unrelatedPublisher = !json.verified; + json.reviewCount = Optional.ofNullable(extension.getReviewCount()).orElse(0L); + var serverUrl = UrlUtil.getBaseUrl(); + json.namespaceUrl = createApiUrl(serverUrl, "api", json.namespace); + json.reviewsUrl = createApiUrl(serverUrl, "api", json.namespace, json.name, "reviews"); + + var allVersions = new ArrayList(); + if (latest != null) + allVersions.add(VersionAlias.LATEST); + if (latestPreRelease != null) + allVersions.add(VersionAlias.PRE_RELEASE); + + var versionBaseUrl = UrlUtil.createApiVersionBaseUrl(serverUrl, json.namespace, json.name, targetPlatform); + allVersions.addAll(repositories.findVersionStringsSorted(extension, targetPlatform, onlyActive)); + json.allVersionsUrl = UrlUtil.createAllVersionsUrl(json.namespace, json.name, targetPlatform, "versions"); + json.allVersions = Maps.newLinkedHashMapWithExpectedSize(allVersions.size()); + for (var version : allVersions) { + json.allVersions.put(version, createApiUrl(versionBaseUrl, version)); + } + + var fileUrls = storageUtil.getFileUrls(List.of(extVersion), serverUrl, withFileTypes(DOWNLOAD, MANIFEST, ICON, README, LICENSE, CHANGELOG, VSIXMANIFEST)); + json.files = fileUrls.get(extVersion.getId()); + if (json.files.containsKey(DOWNLOAD_SIG)) { + json.files.put(PUBLIC_KEY, UrlUtil.getPublicKeyUrl(extVersion)); + } + if (json.dependencies != null) { + json.dependencies.forEach(ref -> { + ref.url = createApiUrl(serverUrl, "api", ref.namespace, ref.extension); + }); + } + if (json.bundledExtensions != null) { + json.bundledExtensions.forEach(ref -> { + ref.url = createApiUrl(serverUrl, "api", ref.namespace, ref.extension); + }); + } + return json; } public ExtensionJson toExtensionVersionJson( @@ -1021,19 +1010,17 @@ public ExtensionJson toExtensionVersionJsonV2( } private boolean isVerified(ExtensionVersion extVersion) { - return Observation.createNotStarted("LocalRegistryService#isVerified", observations).observe(() -> { - if (extVersion.getPublishedWith() == null) { - return false; - } + if (extVersion.getPublishedWith() == null) { + return false; + } - var user = extVersion.getPublishedWith().getUser(); - if (UserData.ROLE_PRIVILEGED.equals(user.getRole())) { - return true; - } + var user = extVersion.getPublishedWith().getUser(); + if (UserData.ROLE_PRIVILEGED.equals(user.getRole())) { + return true; + } - var namespace = extVersion.getExtension().getNamespace(); - return repositories.isVerified(namespace, user); - }); + var namespace = extVersion.getExtension().getNamespace(); + return repositories.isVerified(namespace, user); } private boolean isVerified(ExtensionVersion extVersion, Map> membershipsByNamespaceId) { diff --git a/server/src/main/java/org/eclipse/openvsx/RegistryAPI.java b/server/src/main/java/org/eclipse/openvsx/RegistryAPI.java index d910ffa5d..a4b4dfb95 100644 --- a/server/src/main/java/org/eclipse/openvsx/RegistryAPI.java +++ b/server/src/main/java/org/eclipse/openvsx/RegistryAPI.java @@ -10,8 +10,6 @@ package org.eclipse.openvsx; import com.google.common.collect.Iterables; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.headers.Header; @@ -54,18 +52,15 @@ public class RegistryAPI { private final LocalRegistryService local; private final UpstreamRegistryService upstream; private final UserService users; - private final ObservationRegistry observations; public RegistryAPI( LocalRegistryService local, UpstreamRegistryService upstream, - UserService users, - ObservationRegistry observations + UserService users ) { this.local = local; this.upstream = upstream; this.users = users; - this.observations = observations; } protected Iterable getRegistries() { @@ -1543,19 +1538,17 @@ public ResponseEntity publish( InputStream content, @RequestParam @Parameter(description = "A personal access token") String token ) { - return Observation.createNotStarted("RegistryAPI#publish", observations).observe(() -> { - try { - var json = local.publish(content, token); - var serverUrl = UrlUtil.getBaseUrl(); - var url = UrlUtil.createApiVersionUrl(serverUrl, json); - return ResponseEntity.status(HttpStatus.CREATED) - .location(URI.create(url)) - .body(json); - } catch (ErrorResultException exc) { - logger.warn("Failed to publish extension", exc); - return exc.toResponseEntity(ExtensionJson.class); - } - }); + try { + var json = local.publish(content, token); + var serverUrl = UrlUtil.getBaseUrl(); + var url = UrlUtil.createApiVersionUrl(serverUrl, json); + return ResponseEntity.status(HttpStatus.CREATED) + .location(URI.create(url)) + .body(json); + } catch (ErrorResultException exc) { + logger.warn("Failed to publish extension", exc); + return exc.toResponseEntity(ExtensionJson.class); + } } @PostMapping( @@ -1612,24 +1605,22 @@ public ResponseEntity publish( ) }) public ResponseEntity publish(InputStream content) { - return Observation.createNotStarted("RegistryAPI#publish", observations).observe(() -> { - try { - var user = users.findLoggedInUser(); - if (user == null) { - throw new ResponseStatusException(HttpStatus.FORBIDDEN); - } - - var json = local.publish(content, user); - var serverUrl = UrlUtil.getBaseUrl(); - var url = UrlUtil.createApiUrl(serverUrl, "api", json.namespace, json.name, json.version); - return ResponseEntity.status(HttpStatus.CREATED) - .location(URI.create(url)) - .body(json); - } catch (ErrorResultException exc) { - logger.warn("Failed to publish extension", exc); - return exc.toResponseEntity(ExtensionJson.class); + try { + var user = users.findLoggedInUser(); + if (user == null) { + throw new ResponseStatusException(HttpStatus.FORBIDDEN); } - }); + + var json = local.publish(content, user); + var serverUrl = UrlUtil.getBaseUrl(); + var url = UrlUtil.createApiUrl(serverUrl, "api", json.namespace, json.name, json.version); + return ResponseEntity.status(HttpStatus.CREATED) + .location(URI.create(url)) + .body(json); + } catch (ErrorResultException exc) { + logger.warn("Failed to publish extension", exc); + return exc.toResponseEntity(ExtensionJson.class); + } } @PostMapping( diff --git a/server/src/main/java/org/eclipse/openvsx/UserService.java b/server/src/main/java/org/eclipse/openvsx/UserService.java index 5117762ba..70fa4687b 100644 --- a/server/src/main/java/org/eclipse/openvsx/UserService.java +++ b/server/src/main/java/org/eclipse/openvsx/UserService.java @@ -10,8 +10,6 @@ package org.eclipse.openvsx; import com.google.common.base.Joiner; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; import org.eclipse.openvsx.cache.CacheService; @@ -45,35 +43,30 @@ public class UserService { private final StorageUtilService storageUtil; private final CacheService cache; private final ExtensionValidator validator; - private final ObservationRegistry observations; public UserService( EntityManager entityManager, RepositoryService repositories, StorageUtilService storageUtil, CacheService cache, - ExtensionValidator validator, - ObservationRegistry observations + ExtensionValidator validator ) { this.entityManager = entityManager; this.repositories = repositories; this.storageUtil = storageUtil; this.cache = cache; this.validator = validator; - this.observations = observations; } public UserData findLoggedInUser() { - return Observation.createNotStarted("UserService#findLoggedInUser", observations).observe(() -> { - var authentication = SecurityContextHolder.getContext().getAuthentication(); - if (authentication != null) { - if (authentication.getPrincipal() instanceof IdPrincipal) { - var principal = (IdPrincipal) authentication.getPrincipal(); - return entityManager.find(UserData.class, principal.getId()); - } + var authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication != null) { + if (authentication.getPrincipal() instanceof IdPrincipal) { + var principal = (IdPrincipal) authentication.getPrincipal(); + return entityManager.find(UserData.class, principal.getId()); } - return null; - }); + } + return null; } @Transactional @@ -128,14 +121,12 @@ public UserData updateExistingUser(UserData user, OAuth2User oauth2User) { @Transactional public PersonalAccessToken useAccessToken(String tokenValue) { - return Observation.createNotStarted("UserService#useAccessToken", observations).observe(() -> { - var token = repositories.findAccessToken(tokenValue); - if (token == null || !token.isActive()) { - return null; - } - token.setAccessedTimestamp(TimeUtil.getCurrentUTC()); - return token; - }); + var token = repositories.findAccessToken(tokenValue); + if (token == null || !token.isActive()) { + return null; + } + token.setAccessedTimestamp(TimeUtil.getCurrentUTC()); + return token; } public String generateTokenValue() { @@ -147,15 +138,12 @@ public String generateTokenValue() { } public boolean hasPublishPermission(UserData user, Namespace namespace) { - return Observation.createNotStarted("UserService#hasPublishPermission", observations).observe(() -> { - - if (UserData.ROLE_PRIVILEGED.equals(user.getRole())) { - // Privileged users can publish to every namespace. - return true; - } + if (UserData.ROLE_PRIVILEGED.equals(user.getRole())) { + // Privileged users can publish to every namespace. + return true; + } - return repositories.canPublishInNamespace(user, namespace); - }); + return repositories.canPublishInNamespace(user, namespace); } @Transactional(rollbackOn = ErrorResultException.class) @@ -276,21 +264,19 @@ private void storeNamespaceLogo(Namespace namespace) { } @Transactional public AccessTokenJson createAccessToken(UserData user, String description) { - return Observation.createNotStarted("UserService#createAccessToken", observations).observe(() -> { - var token = new PersonalAccessToken(); - token.setUser(user); - token.setValue(generateTokenValue()); - token.setActive(true); - token.setCreatedTimestamp(TimeUtil.getCurrentUTC()); - token.setDescription(description); - entityManager.persist(token); - var json = token.toAccessTokenJson(); - // Include the token value after creation so the user can copy it - json.value = token.getValue(); - json.deleteTokenUrl = createApiUrl(UrlUtil.getBaseUrl(), "user", "token", "delete", Long.toString(token.getId())); + var token = new PersonalAccessToken(); + token.setUser(user); + token.setValue(generateTokenValue()); + token.setActive(true); + token.setCreatedTimestamp(TimeUtil.getCurrentUTC()); + token.setDescription(description); + entityManager.persist(token); + var json = token.toAccessTokenJson(); + // Include the token value after creation so the user can copy it + json.value = token.getValue(); + json.deleteTokenUrl = createApiUrl(UrlUtil.getBaseUrl(), "user", "token", "delete", Long.toString(token.getId())); - return json; - }); + return json; } @Transactional diff --git a/server/src/main/java/org/eclipse/openvsx/cache/CacheService.java b/server/src/main/java/org/eclipse/openvsx/cache/CacheService.java index 3a84d6f0a..0a31945b4 100644 --- a/server/src/main/java/org/eclipse/openvsx/cache/CacheService.java +++ b/server/src/main/java/org/eclipse/openvsx/cache/CacheService.java @@ -9,7 +9,6 @@ * ****************************************************************************** */ package org.eclipse.openvsx.cache; -import io.micrometer.observation.ObservationRegistry; import org.eclipse.openvsx.entities.Extension; import org.eclipse.openvsx.entities.ExtensionVersion; import org.eclipse.openvsx.entities.UserData; @@ -40,20 +39,17 @@ public class CacheService { private final RepositoryService repositories; private final ExtensionJsonCacheKeyGenerator extensionJsonCacheKey; private final LatestExtensionVersionCacheKeyGenerator latestExtensionVersionCacheKey; - private final ObservationRegistry observations; public CacheService( CacheManager cacheManager, RepositoryService repositories, ExtensionJsonCacheKeyGenerator extensionJsonCacheKey, - LatestExtensionVersionCacheKeyGenerator latestExtensionVersionCacheKey, - ObservationRegistry observations + LatestExtensionVersionCacheKeyGenerator latestExtensionVersionCacheKey ) { this.cacheManager = cacheManager; this.repositories = repositories; this.extensionJsonCacheKey = extensionJsonCacheKey; this.latestExtensionVersionCacheKey = latestExtensionVersionCacheKey; - this.observations = observations; } public void evictNamespaceDetails() { @@ -79,30 +75,28 @@ public void evictExtensionJsons(UserData user) { } public void evictExtensionJsons(Extension extension) { -// Observation.createNotStarted("CacheService#evictExtensionJsons", observations).observe(() -> { - var cache = cacheManager.getCache(CACHE_EXTENSION_JSON); - if (cache == null) { - return; // cache is not created - } - if (extension.getVersions() == null) { - return; - } + var cache = cacheManager.getCache(CACHE_EXTENSION_JSON); + if (cache == null) { + return; // cache is not created + } + if (extension.getVersions() == null) { + return; + } - var versions = new ArrayList<>(VersionAlias.ALIAS_NAMES); - extension.getVersions().stream() - .map(ExtensionVersion::getVersion) - .forEach(versions::add); - - var namespaceName = extension.getNamespace().getName(); - var extensionName = extension.getName(); - var targetPlatforms = new ArrayList<>(TargetPlatform.TARGET_PLATFORM_NAMES); - targetPlatforms.add("null"); - for (var version : versions) { - for (var targetPlatform : targetPlatforms) { - cache.evictIfPresent(extensionJsonCacheKey.generate(namespaceName, extensionName, targetPlatform, version)); - } + var versions = new ArrayList<>(VersionAlias.ALIAS_NAMES); + extension.getVersions().stream() + .map(ExtensionVersion::getVersion) + .forEach(versions::add); + + var namespaceName = extension.getNamespace().getName(); + var extensionName = extension.getName(); + var targetPlatforms = new ArrayList<>(TargetPlatform.TARGET_PLATFORM_NAMES); + targetPlatforms.add("null"); + for (var version : versions) { + for (var targetPlatform : targetPlatforms) { + cache.evictIfPresent(extensionJsonCacheKey.generate(namespaceName, extensionName, targetPlatform, version)); } -// }); + } } public void evictExtensionJsons(ExtensionVersion extVersion) { @@ -130,25 +124,23 @@ public void evictLatestExtensionVersions() { } public void evictLatestExtensionVersion(Extension extension) { -// Observation.createNotStarted("CacheService#evictLatestExtensionVersion", observations).observe(() -> { - var cache = cacheManager.getCache(CACHE_LATEST_EXTENSION_VERSION); - if(cache == null) { - return; - } + var cache = cacheManager.getCache(CACHE_LATEST_EXTENSION_VERSION); + if(cache == null) { + return; + } - var targetPlatforms = new ArrayList<>(TargetPlatform.TARGET_PLATFORM_NAMES); - targetPlatforms.add(null); - for (var targetPlatform : targetPlatforms) { - for (var preRelease : List.of(true, false)) { - for (var onlyActive : List.of(true, false)) { - for(var type : ExtensionVersion.Type.values()) { - var key = latestExtensionVersionCacheKey.generate(extension, targetPlatform, preRelease, onlyActive, type); - cache.evictIfPresent(key); - } + var targetPlatforms = new ArrayList<>(TargetPlatform.TARGET_PLATFORM_NAMES); + targetPlatforms.add(null); + for (var targetPlatform : targetPlatforms) { + for (var preRelease : List.of(true, false)) { + for (var onlyActive : List.of(true, false)) { + for(var type : ExtensionVersion.Type.values()) { + var key = latestExtensionVersionCacheKey.generate(extension, targetPlatform, preRelease, onlyActive, type); + cache.evictIfPresent(key); } } } -// }); + } } private void invalidateCache(String cacheName) { diff --git a/server/src/main/java/org/eclipse/openvsx/eclipse/EclipseService.java b/server/src/main/java/org/eclipse/openvsx/eclipse/EclipseService.java index 95a1e65f5..9e2b0ada5 100644 --- a/server/src/main/java/org/eclipse/openvsx/eclipse/EclipseService.java +++ b/server/src/main/java/org/eclipse/openvsx/eclipse/EclipseService.java @@ -14,8 +14,6 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Lists; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; import org.apache.commons.lang3.StringUtils; @@ -68,7 +66,6 @@ public class EclipseService { private final EntityManager entityManager; private final RestTemplate restTemplate; private final ObjectMapper objectMapper; - private final ObservationRegistry observations; @Value("${ovsx.eclipse.base-url:}") String eclipseApiUrl; @@ -80,8 +77,7 @@ public EclipseService( TokenService tokens, ExtensionService extensions, EntityManager entityManager, - RestTemplate restTemplate, - ObservationRegistry observations + RestTemplate restTemplate ) { this.tokens = tokens; this.extensions = extensions; @@ -89,7 +85,6 @@ public EclipseService( this.restTemplate = restTemplate; this.objectMapper = new ObjectMapper(); this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - this.observations = observations; } public boolean isActive() { @@ -101,30 +96,28 @@ public boolean isActive() { * @throws ErrorResultException if the user has no active agreement */ public void checkPublisherAgreement(UserData user) { - Observation.createNotStarted("EclipseService#checkPublisherAgreement", observations).observe(() -> { - if (!isActive()) { - return; - } - // Users without authentication provider have been created directly in the DB, - // so we skip the agreement check in this case. - if (user.getProvider() == null) { - return; - } - var personId = user.getEclipsePersonId(); - if (personId == null) { - throw new ErrorResultException("You must log in with an Eclipse Foundation account and sign a Publisher Agreement before publishing any extension."); - } - var profile = getPublicProfile(personId); - if (profile.publisherAgreements == null || profile.publisherAgreements.openVsx == null - || profile.publisherAgreements.openVsx.version == null) { - throw new ErrorResultException("You must sign a Publisher Agreement with the Eclipse Foundation before publishing any extension."); - } - if (!publisherAgreementVersion.equals(profile.publisherAgreements.openVsx.version)) { - throw new ErrorResultException("Your Publisher Agreement with the Eclipse Foundation is outdated (version " - + profile.publisherAgreements.openVsx.version + "). The current version is " - + publisherAgreementVersion + "."); - } - }); + if (!isActive()) { + return; + } + // Users without authentication provider have been created directly in the DB, + // so we skip the agreement check in this case. + if (user.getProvider() == null) { + return; + } + var personId = user.getEclipsePersonId(); + if (personId == null) { + throw new ErrorResultException("You must log in with an Eclipse Foundation account and sign a Publisher Agreement before publishing any extension."); + } + var profile = getPublicProfile(personId); + if (profile.publisherAgreements == null || profile.publisherAgreements.openVsx == null + || profile.publisherAgreements.openVsx.version == null) { + throw new ErrorResultException("You must sign a Publisher Agreement with the Eclipse Foundation before publishing any extension."); + } + if (!publisherAgreementVersion.equals(profile.publisherAgreements.openVsx.version)) { + throw new ErrorResultException("Your Publisher Agreement with the Eclipse Foundation is outdated (version " + + profile.publisherAgreements.openVsx.version + "). The current version is " + + publisherAgreementVersion + "."); + } } /** diff --git a/server/src/main/java/org/eclipse/openvsx/migration/CheckPotentiallyMaliciousExtensionVersionsService.java b/server/src/main/java/org/eclipse/openvsx/migration/CheckPotentiallyMaliciousExtensionVersionsService.java index 71500c8d3..5632a16d3 100644 --- a/server/src/main/java/org/eclipse/openvsx/migration/CheckPotentiallyMaliciousExtensionVersionsService.java +++ b/server/src/main/java/org/eclipse/openvsx/migration/CheckPotentiallyMaliciousExtensionVersionsService.java @@ -9,7 +9,6 @@ ********************************************************************************/ package org.eclipse.openvsx.migration; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; import org.jobrunr.jobs.context.JobRunrDashboardLogger; @@ -34,7 +33,7 @@ public CheckPotentiallyMaliciousExtensionVersionsService(EntityManager entityMan @Transactional public void checkPotentiallyMaliciousExtensionVersion(ExtensionVersion extVersion, TempFile extensionFile) { - try(var extProcessor = new ExtensionProcessor(extensionFile, ObservationRegistry.NOOP)) { + try(var extProcessor = new ExtensionProcessor(extensionFile)) { boolean isMalicious = extProcessor.isPotentiallyMalicious(); extVersion.setPotentiallyMalicious(isMalicious); if (isMalicious) { diff --git a/server/src/main/java/org/eclipse/openvsx/migration/ExtractResourcesJobRequestHandler.java b/server/src/main/java/org/eclipse/openvsx/migration/ExtractResourcesJobRequestHandler.java index 443b06e2a..58cab8120 100644 --- a/server/src/main/java/org/eclipse/openvsx/migration/ExtractResourcesJobRequestHandler.java +++ b/server/src/main/java/org/eclipse/openvsx/migration/ExtractResourcesJobRequestHandler.java @@ -9,7 +9,6 @@ * ****************************************************************************** */ package org.eclipse.openvsx.migration; -import io.micrometer.observation.ObservationRegistry; import org.eclipse.openvsx.ExtensionProcessor; import org.eclipse.openvsx.util.NamingUtil; import org.jobrunr.jobs.annotations.Job; @@ -53,7 +52,7 @@ public void run(MigrationJobRequest jobRequest) throws Exception { if(Files.size(extensionFile.getPath()) == 0) { return; } - try (var extProcessor = new ExtensionProcessor(extensionFile, ObservationRegistry.NOOP)) { + try (var extProcessor = new ExtensionProcessor(extensionFile)) { extProcessor.processEachResource(download.getExtension(), (resource) -> { resource.setStorageType(download.getStorageType()); migrations.uploadFileResource(resource); diff --git a/server/src/main/java/org/eclipse/openvsx/migration/ExtractVsixManifestsJobRequestHandler.java b/server/src/main/java/org/eclipse/openvsx/migration/ExtractVsixManifestsJobRequestHandler.java index adbf3f56f..aba57f31d 100644 --- a/server/src/main/java/org/eclipse/openvsx/migration/ExtractVsixManifestsJobRequestHandler.java +++ b/server/src/main/java/org/eclipse/openvsx/migration/ExtractVsixManifestsJobRequestHandler.java @@ -9,7 +9,6 @@ * ****************************************************************************** */ package org.eclipse.openvsx.migration; -import io.micrometer.observation.ObservationRegistry; import org.eclipse.openvsx.ExtensionProcessor; import org.eclipse.openvsx.entities.FileResource; import org.eclipse.openvsx.util.NamingUtil; @@ -55,7 +54,7 @@ public void run(MigrationJobRequest jobRequest) throws Exception { if(Files.size(extensionFile.getPath()) == 0) { return; } - try (var extProcessor = new ExtensionProcessor(extensionFile, ObservationRegistry.NOOP)) { + try (var extProcessor = new ExtensionProcessor(extensionFile)) { var vsixManifest = extProcessor.getVsixManifest(extVersion); vsixManifest.setStorageType(download.getStorageType()); migrations.uploadFileResource(vsixManifest); diff --git a/server/src/main/java/org/eclipse/openvsx/migration/FixTargetPlatformsJobRequestHandler.java b/server/src/main/java/org/eclipse/openvsx/migration/FixTargetPlatformsJobRequestHandler.java index 79913648f..f4fb58ad6 100644 --- a/server/src/main/java/org/eclipse/openvsx/migration/FixTargetPlatformsJobRequestHandler.java +++ b/server/src/main/java/org/eclipse/openvsx/migration/FixTargetPlatformsJobRequestHandler.java @@ -9,7 +9,6 @@ * ****************************************************************************** */ package org.eclipse.openvsx.migration; -import io.micrometer.observation.ObservationRegistry; import org.eclipse.openvsx.ExtensionProcessor; import org.eclipse.openvsx.ExtensionService; import org.eclipse.openvsx.admin.AdminService; @@ -61,7 +60,7 @@ public void run(MigrationJobRequest jobRequest) throws Exception { } boolean fixTargetPlatform; - try (var extProcessor = new ExtensionProcessor(extensionFile, ObservationRegistry.NOOP)) { + try (var extProcessor = new ExtensionProcessor(extensionFile)) { fixTargetPlatform = !extProcessor.getMetadata().getTargetPlatform().equals(extVersion.getTargetPlatform()); } diff --git a/server/src/main/java/org/eclipse/openvsx/migration/GenerateSha256ChecksumJobRequestHandler.java b/server/src/main/java/org/eclipse/openvsx/migration/GenerateSha256ChecksumJobRequestHandler.java index 47bb814bc..52f1e4048 100644 --- a/server/src/main/java/org/eclipse/openvsx/migration/GenerateSha256ChecksumJobRequestHandler.java +++ b/server/src/main/java/org/eclipse/openvsx/migration/GenerateSha256ChecksumJobRequestHandler.java @@ -9,7 +9,6 @@ * ****************************************************************************** */ package org.eclipse.openvsx.migration; -import io.micrometer.observation.ObservationRegistry; import org.eclipse.openvsx.ExtensionProcessor; import org.eclipse.openvsx.entities.FileResource; import org.eclipse.openvsx.util.NamingUtil; @@ -53,7 +52,7 @@ public void run(MigrationJobRequest jobRequest) throws Exception { if(Files.size(extensionFile.getPath()) == 0) { return; } - try (var extProcessor = new ExtensionProcessor(extensionFile, ObservationRegistry.NOOP)) { + try (var extProcessor = new ExtensionProcessor(extensionFile)) { var checksum = extProcessor.generateSha256Checksum(extVersion); checksum.setStorageType(download.getStorageType()); migrations.uploadFileResource(checksum); diff --git a/server/src/main/java/org/eclipse/openvsx/migration/SetPreReleaseJobService.java b/server/src/main/java/org/eclipse/openvsx/migration/SetPreReleaseJobService.java index bda24f5d8..3e87dc0bf 100644 --- a/server/src/main/java/org/eclipse/openvsx/migration/SetPreReleaseJobService.java +++ b/server/src/main/java/org/eclipse/openvsx/migration/SetPreReleaseJobService.java @@ -9,7 +9,6 @@ * ****************************************************************************** */ package org.eclipse.openvsx.migration; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; import org.eclipse.openvsx.ExtensionProcessor; @@ -40,7 +39,7 @@ public List getExtensionVersions(MigrationJobRequest jobReques @Transactional public void updatePreviewAndPreRelease(ExtensionVersion extVersion, TempFile extensionFile) { - try(var extProcessor = new ExtensionProcessor(extensionFile, ObservationRegistry.NOOP)) { + try(var extProcessor = new ExtensionProcessor(extensionFile)) { extVersion.setPreRelease(extProcessor.isPreRelease()); extVersion.setPreview(extProcessor.isPreview()); } diff --git a/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionHandler.java b/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionHandler.java index 28536c7f9..b53f34508 100644 --- a/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionHandler.java +++ b/server/src/main/java/org/eclipse/openvsx/publish/PublishExtensionVersionHandler.java @@ -10,8 +10,6 @@ package org.eclipse.openvsx.publish; import com.google.common.base.Joiner; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; import org.apache.commons.lang3.StringUtils; @@ -52,7 +50,6 @@ public class PublishExtensionVersionHandler { private final UserService users; private final ExtensionValidator validator; private final ExtensionControlService extensionControl; - private final ObservationRegistry observations; public PublishExtensionVersionHandler( PublishExtensionVersionService service, @@ -62,8 +59,7 @@ public PublishExtensionVersionHandler( JobRequestScheduler scheduler, UserService users, ExtensionValidator validator, - ExtensionControlService extensionControl, - ObservationRegistry observations + ExtensionControlService extensionControl ) { this.service = service; this.integrityService = integrityService; @@ -73,109 +69,104 @@ public PublishExtensionVersionHandler( this.users = users; this.validator = validator; this.extensionControl = extensionControl; - this.observations = observations; } @Transactional(rollbackOn = ErrorResultException.class) public ExtensionVersion createExtensionVersion(ExtensionProcessor processor, PersonalAccessToken token, LocalDateTime timestamp, boolean checkDependencies) { - return Observation.createNotStarted("PublishExtensionVersionHandler#createExtensionVersion", observations).observe(() -> { - // Extract extension metadata from its manifest - var extVersion = createExtensionVersion(processor, token.getUser(), token, timestamp); - var dependencies = processor.getExtensionDependencies(); - var bundledExtensions = processor.getBundledExtensions(); - if (checkDependencies) { - var parsedDependencies = dependencies.stream() - .map(id -> parseExtensionId(id, "extensionDependencies")) - .toList(); - - if(!parsedDependencies.isEmpty()) { - checkDependencies(parsedDependencies); - } - bundledExtensions.forEach(id -> parseExtensionId(id, "extensionPack")); + // Extract extension metadata from its manifest + var extVersion = createExtensionVersion(processor, token.getUser(), token, timestamp); + var dependencies = processor.getExtensionDependencies(); + var bundledExtensions = processor.getBundledExtensions(); + if (checkDependencies) { + var parsedDependencies = dependencies.stream() + .map(id -> parseExtensionId(id, "extensionDependencies")) + .toList(); + + if(!parsedDependencies.isEmpty()) { + checkDependencies(parsedDependencies); } + bundledExtensions.forEach(id -> parseExtensionId(id, "extensionPack")); + } - extVersion.setDependencies(dependencies); - extVersion.setBundledExtensions(bundledExtensions); - if(integrityService.isEnabled()) { - extVersion.setSignatureKeyPair(repositories.findActiveKeyPair()); - } + extVersion.setDependencies(dependencies); + extVersion.setBundledExtensions(bundledExtensions); + if(integrityService.isEnabled()) { + extVersion.setSignatureKeyPair(repositories.findActiveKeyPair()); + } - return extVersion; - }); + return extVersion; } private ExtensionVersion createExtensionVersion(ExtensionProcessor processor, UserData user, PersonalAccessToken token, LocalDateTime timestamp) { - return Observation.createNotStarted("PublishExtensionVersionHandler#createExtensionVersion", observations).observe(() -> { - var namespaceName = processor.getNamespace(); - var namespace = repositories.findNamespace(namespaceName); - if (namespace == null) { - throw new ErrorResultException("Unknown publisher: " + namespaceName - + "\nUse the 'create-namespace' command to create a namespace corresponding to your publisher name."); - } - if (!users.hasPublishPermission(user, namespace)) { - throw new ErrorResultException("Insufficient access rights for publisher: " + namespace.getName()); - } + var namespaceName = processor.getNamespace(); + var namespace = repositories.findNamespace(namespaceName); + if (namespace == null) { + throw new ErrorResultException("Unknown publisher: " + namespaceName + + "\nUse the 'create-namespace' command to create a namespace corresponding to your publisher name."); + } + if (!users.hasPublishPermission(user, namespace)) { + throw new ErrorResultException("Insufficient access rights for publisher: " + namespace.getName()); + } - var extensionName = processor.getExtensionName(); - var nameIssue = validator.validateExtensionName(extensionName); - if (nameIssue.isPresent()) { - throw new ErrorResultException(nameIssue.get().toString()); - } - if(isMalicious(namespaceName, extensionName)) { - throw new ErrorResultException(NamingUtil.toExtensionId(namespaceName, extensionName) + " is a known malicious extension"); - } + var extensionName = processor.getExtensionName(); + var nameIssue = validator.validateExtensionName(extensionName); + if (nameIssue.isPresent()) { + throw new ErrorResultException(nameIssue.get().toString()); + } + if(isMalicious(namespaceName, extensionName)) { + throw new ErrorResultException(NamingUtil.toExtensionId(namespaceName, extensionName) + " is a known malicious extension"); + } - var version = processor.getVersion(); - var versionIssue = validator.validateExtensionVersion(version); - if (versionIssue.isPresent()) { - throw new ErrorResultException(versionIssue.get().toString()); - } + var version = processor.getVersion(); + var versionIssue = validator.validateExtensionVersion(version); + if (versionIssue.isPresent()) { + throw new ErrorResultException(versionIssue.get().toString()); + } - var extVersion = processor.getMetadata(); - if (extVersion.getDisplayName() != null && extVersion.getDisplayName().trim().isEmpty()) { - extVersion.setDisplayName(null); - } - extVersion.setTimestamp(timestamp); - extVersion.setPublishedWith(token); - extVersion.setActive(false); - - var extension = repositories.findExtension(extensionName, namespace); - if (extension == null) { - extension = new Extension(); - extension.setActive(false); - extension.setName(extensionName); - extension.setNamespace(namespace); - extension.setPublishedDate(extVersion.getTimestamp()); - extension.setDeprecated(false); - extension.setDownloadable(true); - - entityManager.persist(extension); - } else { - var existingVersion = repositories.findVersion(extVersion.getVersion(), extVersion.getTargetPlatform(), extension); - if (existingVersion != null) { - var extVersionId = NamingUtil.toLogFormat(namespaceName, extensionName, extVersion.getTargetPlatform(), extVersion.getVersion()); - var message = "Extension " + extVersionId + " is already published"; - message += existingVersion.isActive() ? "." : ", but currently isn't active and therefore not visible."; - throw new ErrorResultException(message); - } + var extVersion = processor.getMetadata(); + if (extVersion.getDisplayName() != null && extVersion.getDisplayName().trim().isEmpty()) { + extVersion.setDisplayName(null); + } + extVersion.setTimestamp(timestamp); + extVersion.setPublishedWith(token); + extVersion.setActive(false); + + var extension = repositories.findExtension(extensionName, namespace); + if (extension == null) { + extension = new Extension(); + extension.setActive(false); + extension.setName(extensionName); + extension.setNamespace(namespace); + extension.setPublishedDate(extVersion.getTimestamp()); + extension.setDeprecated(false); + extension.setDownloadable(true); + + entityManager.persist(extension); + } else { + var existingVersion = repositories.findVersion(extVersion.getVersion(), extVersion.getTargetPlatform(), extension); + if (existingVersion != null) { + var extVersionId = NamingUtil.toLogFormat(namespaceName, extensionName, extVersion.getTargetPlatform(), extVersion.getVersion()); + var message = "Extension " + extVersionId + " is already published"; + message += existingVersion.isActive() ? "." : ", but currently isn't active and therefore not visible."; + throw new ErrorResultException(message); } + } - extension.setLastUpdatedDate(extVersion.getTimestamp()); - extension.getVersions().add(extVersion); - extVersion.setExtension(extension); + extension.setLastUpdatedDate(extVersion.getTimestamp()); + extension.getVersions().add(extVersion); + extVersion.setExtension(extension); - var metadataIssues = validator.validateMetadata(extVersion); - if (!metadataIssues.isEmpty()) { - if (metadataIssues.size() == 1) { - throw new ErrorResultException(metadataIssues.get(0).toString()); - } - throw new ErrorResultException("Multiple issues were found in the extension metadata:\n" - + Joiner.on("\n").join(metadataIssues)); + var metadataIssues = validator.validateMetadata(extVersion); + if (!metadataIssues.isEmpty()) { + if (metadataIssues.size() == 1) { + throw new ErrorResultException(metadataIssues.get(0).toString()); } + throw new ErrorResultException("Multiple issues were found in the extension metadata:\n" + + Joiner.on("\n").join(metadataIssues)); + } - entityManager.persist(extVersion); - return extVersion; - }); + entityManager.persist(extVersion); + return extVersion; } private boolean isMalicious(String namespace, String extension) { @@ -189,12 +180,10 @@ private boolean isMalicious(String namespace, String extension) { } private void checkDependencies(List dependencies) { - Observation.createNotStarted("PublishExtensionVersionHandler#checkDependencies", observations).observe(() -> { - var unresolvedDependency = repositories.findFirstUnresolvedDependency(dependencies); - if (unresolvedDependency != null) { - throw new ErrorResultException("Cannot resolve dependency: " + unresolvedDependency); - } - }); + var unresolvedDependency = repositories.findFirstUnresolvedDependency(dependencies); + if (unresolvedDependency != null) { + throw new ErrorResultException("Cannot resolve dependency: " + unresolvedDependency); + } } private ExtensionId parseExtensionId(String extensionIdText, String formatType) { @@ -217,7 +206,7 @@ public void publishAsync(FileResource download, TempFile extensionFile, Extensio service.storeDownload(download, extensionFile); service.persistResource(download); - try(var processor = new ExtensionProcessor(extensionFile, ObservationRegistry.NOOP)) { + try(var processor = new ExtensionProcessor(extensionFile)) { extVersion.setPotentiallyMalicious(processor.isPotentiallyMalicious()); if (extVersion.isPotentiallyMalicious()) { logger.warn("Extension version is potentially malicious: {}", NamingUtil.toLogFormat(extVersion)); @@ -262,7 +251,7 @@ public void mirror(FileResource download, TempFile extensionFile, String signatu if(signatureName != null) { service.mirrorResource(getSignatureResource(signatureName, extVersion)); } - try(var processor = new ExtensionProcessor(extensionFile, ObservationRegistry.NOOP)) { + try(var processor = new ExtensionProcessor(extensionFile)) { processor.getFileResources(extVersion).forEach(service::mirrorResource); service.mirrorResource(processor.generateSha256Checksum(extVersion)); // don't store file resources, they can be generated on the fly to avoid traversing entire zip file @@ -278,12 +267,10 @@ private FileResource getSignatureResource(String signatureName, ExtensionVersion } public void schedulePublicIdJob(FileResource download) { - Observation.createNotStarted("PublishExtensionVersionHandler#schedulePublicIdJob", observations).observe(() -> { - var extension = download.getExtension().getExtension(); - if (StringUtils.isEmpty(extension.getPublicId())) { - var namespace = extension.getNamespace(); - scheduler.enqueue(new VSCodeIdNewExtensionJobRequest(namespace.getName(), extension.getName())); - } - }); + var extension = download.getExtension().getExtension(); + if (StringUtils.isEmpty(extension.getPublicId())) { + var namespace = extension.getNamespace(); + scheduler.enqueue(new VSCodeIdNewExtensionJobRequest(namespace.getName(), extension.getName())); + } } } diff --git a/server/src/main/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepository.java b/server/src/main/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepository.java index 2631f9588..50165de99 100644 --- a/server/src/main/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepository.java +++ b/server/src/main/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepository.java @@ -9,7 +9,6 @@ * ****************************************************************************** */ package org.eclipse.openvsx.repositories; -import io.micrometer.observation.annotation.Observed; import org.apache.commons.lang3.StringUtils; import org.eclipse.openvsx.entities.*; import org.eclipse.openvsx.json.QueryRequest; @@ -705,7 +704,6 @@ public ExtensionVersion findLatest( return query.fetchOne((record) -> toExtensionVersionFull(record, extension, null)); } - @Observed public ExtensionVersion findLatest( String namespaceName, String extensionName, diff --git a/server/src/main/java/org/eclipse/openvsx/repositories/RepositoryService.java b/server/src/main/java/org/eclipse/openvsx/repositories/RepositoryService.java index ee45de867..853c1edad 100644 --- a/server/src/main/java/org/eclipse/openvsx/repositories/RepositoryService.java +++ b/server/src/main/java/org/eclipse/openvsx/repositories/RepositoryService.java @@ -9,8 +9,6 @@ ********************************************************************************/ package org.eclipse.openvsx.repositories; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; import org.eclipse.openvsx.entities.*; import org.eclipse.openvsx.json.QueryRequest; import org.eclipse.openvsx.json.VersionTargetPlatformsJson; @@ -41,7 +39,6 @@ public class RepositoryService { .and(Sort.by(Sort.Direction.ASC, "targetPlatform")) .and(Sort.by(Sort.Direction.DESC, "timestamp")); - private final ObservationRegistry observations; private final NamespaceRepository namespaceRepo; private final NamespaceJooqRepository namespaceJooqRepo; private final ExtensionRepository extensionRepo; @@ -66,7 +63,6 @@ public class RepositoryService { private final SignatureKeyPairJooqRepository signatureKeyPairJooqRepo; public RepositoryService( - ObservationRegistry observations, NamespaceRepository namespaceRepo, NamespaceJooqRepository namespaceJooqRepo, ExtensionRepository extensionRepo, @@ -90,7 +86,6 @@ public RepositoryService( SignatureKeyPairRepository signatureKeyPairRepo, SignatureKeyPairJooqRepository signatureKeyPairJooqRepo ) { - this.observations = observations; this.namespaceRepo = namespaceRepo; this.namespaceJooqRepo = namespaceJooqRepo; this.extensionRepo = extensionRepo; @@ -116,7 +111,7 @@ public RepositoryService( } public Namespace findNamespace(String name) { - return Observation.createNotStarted("RepositoryService#findNamespace", observations).observe(() -> namespaceRepo.findByNameIgnoreCase(name)); + return namespaceRepo.findByNameIgnoreCase(name); } public String findNamespaceName(String name) { @@ -132,7 +127,7 @@ public long countNamespaces() { } public Extension findExtension(String name, Namespace namespace) { - return Observation.createNotStarted("RepositoryService#findExtension", observations).observe(() -> extensionRepo.findByNameIgnoreCaseAndNamespace(name, namespace)); + return extensionRepo.findByNameIgnoreCaseAndNamespace(name, namespace); } public Extension findExtension(String name, String namespace) { @@ -148,9 +143,7 @@ public Streamable findActiveExtensions(Namespace namespace) { } public Streamable findExtensions(Collection extensionIds) { -// return Observation.createNotStarted("RepositoryService#findExtensions", observations).observe(() -> { - return extensionRepo.findByIdIn(extensionIds); -// }); + return extensionRepo.findByIdIn(extensionIds); } public Streamable findExtensions(Namespace namespace) { @@ -178,7 +171,7 @@ public int getMaxExtensionDownloadCount() { } public ExtensionVersion findVersion(String version, String targetPlatform, Extension extension) { - return Observation.createNotStarted("RepositoryService#findVersion", observations).observe(() -> extensionVersionRepo.findByVersionAndTargetPlatformAndExtension(version, targetPlatform, extension)); + return extensionVersionRepo.findByVersionAndTargetPlatformAndExtension(version, targetPlatform, extension); } public ExtensionVersion findVersion(String version, String targetPlatform, String extensionName, String namespace) { @@ -190,7 +183,7 @@ public Streamable findVersions(Extension extension) { } public Streamable findVersions(String version, Extension extension) { - return Observation.createNotStarted("RepositoryService#findVersions", observations).observe(() -> extensionVersionRepo.findByVersionAndExtension(version, extension)); + return extensionVersionRepo.findByVersionAndExtension(version, extension); } public Streamable findActiveVersions(Extension extension) { @@ -210,7 +203,7 @@ public Page findActiveVersionStringsSorted(String namespace, String exte } public List findVersionStringsSorted(Extension extension, String targetPlatform, boolean onlyActive) { - return Observation.createNotStarted("RepositoryService#findVersionStringsSorted", observations).observe(() -> extensionVersionJooqRepo.findVersionStringsSorted(extension.getId(), targetPlatform, onlyActive, MAX_VERSIONS)); + return extensionVersionJooqRepo.findVersionStringsSorted(extension.getId(), targetPlatform, onlyActive, MAX_VERSIONS); } public Map> findActiveVersionStringsSorted(Collection extensionIds, String targetPlatform) { @@ -266,9 +259,7 @@ public FileResource findFileByTypeAndName(String namespace, String extension, St } public Streamable findDownloadsByStorageTypeAndName(String storageType, Collection names) { -// return Observation.createNotStarted("RepositoryService#findDownloadsByStorageTypeAndName", observations).observe(() -> { - return fileResourceRepo.findByTypeAndStorageTypeAndNameIgnoreCaseIn(DOWNLOAD, storageType, names); -// }); + return fileResourceRepo.findByTypeAndStorageTypeAndNameIgnoreCaseIn(DOWNLOAD, storageType, names); } public Streamable findFilesByType(String type) { @@ -292,7 +283,7 @@ public FileResource findFileByType(String namespace, String extension, String ta } public List findFilesByType(Collection extVersions, Collection types) { - return Observation.createNotStarted("RepositoryService#findFilesByType", observations).observe(() -> fileResourceJooqRepo.findByType(extVersions, types)); + return fileResourceJooqRepo.findByType(extVersions, types); } public Streamable findActiveReviews(Extension extension) { @@ -324,7 +315,7 @@ public long countUsers() { } public NamespaceMembership findMembership(UserData user, Namespace namespace) { - return Observation.createNotStarted("RepositoryService#findMembership", observations).observe(() -> membershipRepo.findByUserAndNamespace(user, namespace)); + return membershipRepo.findByUserAndNamespace(user, namespace); } public boolean hasMembership(UserData user, Namespace namespace) { @@ -332,7 +323,7 @@ public boolean hasMembership(UserData user, Namespace namespace) { } public boolean isVerified(Namespace namespace, UserData user) { - return Observation.createNotStarted("RepositoryService#isVerified", observations).observe(() -> membershipJooqRepo.isVerified(namespace, user)); + return membershipJooqRepo.isVerified(namespace, user); } public Streamable findMemberships(Namespace namespace, String role) { @@ -372,7 +363,7 @@ public long countActiveAccessTokens(UserData user) { } public PersonalAccessToken findAccessToken(String value) { - return Observation.createNotStarted("RepositoryService#findAccessToken", observations).observe(() -> tokenRepo.findByValue(value)); + return tokenRepo.findByValue(value); } public boolean isAdminToken(String value) { @@ -392,9 +383,7 @@ public Streamable findPersistedLogsAfter(LocalDateTime dateTime) { } public List findAllSucceededAzureDownloadCountProcessedItemsByNameIn(List names) { -// return Observation.createNotStarted("RepositoryService#findAllSucceededAzureDownloadCountProcessedItemsByNameIn", observations).observe(() -> { - return downloadCountRepo.findAllSucceededAzureDownloadCountProcessedItemsByNameIn(names); -// }); + return downloadCountRepo.findAllSucceededAzureDownloadCountProcessedItemsByNameIn(names); } public List findActiveExtensionsByPublicId(Collection publicIds, String... namespacesToExclude) { @@ -538,7 +527,7 @@ public Streamable findFileResources(Namespace namespace) { } public SignatureKeyPair findActiveKeyPair() { - return Observation.createNotStarted("RepositoryService#findActiveKeyPair", observations).observe(() -> signatureKeyPairRepo.findByActiveTrue()); + return signatureKeyPairRepo.findByActiveTrue(); } public Streamable findVersions() { @@ -615,9 +604,7 @@ public ExtensionVersion findExtensionVersion(String namespace, String extension, } public ExtensionVersion findLatestVersionForAllUrls(Extension extension, String targetPlatform, boolean onlyPreRelease, boolean onlyActive) { - return Observation.createNotStarted("RepositoryService#findLatestVersionForAllUrls", observations).observe(() -> { - return extensionVersionJooqRepo.findLatestForAllUrls(extension, targetPlatform, onlyPreRelease, onlyActive); - }); + return extensionVersionJooqRepo.findLatestForAllUrls(extension, targetPlatform, onlyPreRelease, onlyActive); } public ExtensionVersion findLatestVersion(Extension extension, String targetPlatform, boolean onlyPreRelease, boolean onlyActive) { diff --git a/server/src/main/java/org/eclipse/openvsx/search/SearchUtilService.java b/server/src/main/java/org/eclipse/openvsx/search/SearchUtilService.java index 3b668a68e..16d99971c 100644 --- a/server/src/main/java/org/eclipse/openvsx/search/SearchUtilService.java +++ b/server/src/main/java/org/eclipse/openvsx/search/SearchUtilService.java @@ -10,8 +10,6 @@ package org.eclipse.openvsx.search; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; import org.eclipse.openvsx.entities.Extension; import org.springframework.data.elasticsearch.core.SearchHits; import org.springframework.stereotype.Component; @@ -28,16 +26,13 @@ public class SearchUtilService implements ISearchService { private final DatabaseSearchService databaseSearchService; private final ElasticSearchService elasticSearchService; - private final ObservationRegistry observations; public SearchUtilService( DatabaseSearchService databaseSearchService, - ElasticSearchService elasticSearchService, - ObservationRegistry observations + ElasticSearchService elasticSearchService ) { this.databaseSearchService = databaseSearchService; this.elasticSearchService = elasticSearchService; - this.observations = observations; } public boolean isEnabled() { @@ -79,9 +74,7 @@ public void updateSearchEntries(List extensions) { @Override public void updateSearchEntriesAsync(List extensions) { -// Observation.createNotStarted("SearchUtilService#updateSearchEntriesAsync", observations).observe(() -> { - getImplementation().updateSearchEntriesAsync(extensions); -// }); + getImplementation().updateSearchEntriesAsync(extensions); } @Override diff --git a/server/src/main/java/org/eclipse/openvsx/storage/AzureDownloadCountProcessor.java b/server/src/main/java/org/eclipse/openvsx/storage/AzureDownloadCountProcessor.java index b4eb1f4e2..a03a14799 100644 --- a/server/src/main/java/org/eclipse/openvsx/storage/AzureDownloadCountProcessor.java +++ b/server/src/main/java/org/eclipse/openvsx/storage/AzureDownloadCountProcessor.java @@ -58,30 +58,30 @@ public AzureDownloadCountProcessor( @Transactional public void persistProcessedItem(String name, LocalDateTime processedOn, int executionTime, boolean success) { -// Observation.createNotStarted("AzureDownloadCountProcessor#persistProcessedItem", observations).observe(() -> { + Observation.createNotStarted("AzureDownloadCountProcessor#persistProcessedItem", observations).observe(() -> { var processedItem = new AzureDownloadCountProcessedItem(); processedItem.setName(name); processedItem.setProcessedOn(processedOn); processedItem.setExecutionTime(executionTime); processedItem.setSuccess(success); entityManager.persist(processedItem); -// }); + }); } public Map processDownloadCounts(Map files) { -// return Observation.createNotStarted("AzureDownloadCountProcessor#processDownloadCounts", observations).observe(() -> { + return Observation.createNotStarted("AzureDownloadCountProcessor#processDownloadCounts", observations).observe(() -> { return repositories.findDownloadsByStorageTypeAndName(STORAGE_AZURE, files.keySet()).stream() .map(fileResource -> new AbstractMap.SimpleEntry<>(fileResource, files.get(fileResource.getName().toUpperCase()))) .collect(Collectors.groupingBy( e -> e.getKey().getExtension().getExtension().getId(), Collectors.summingInt(Map.Entry::getValue) )); -// }); + }); } @Transactional public List increaseDownloadCounts(Map extensionDownloads) { -// return Observation.createNotStarted("AzureDownloadCountProcessor#increaseDownloadCounts", observations).observe(() -> { + return Observation.createNotStarted("AzureDownloadCountProcessor#increaseDownloadCounts", observations).observe(() -> { var extensions = repositories.findExtensions(extensionDownloads.keySet()).toList(); extensions.forEach(extension -> { var downloads = extensionDownloads.get(extension.getId()); @@ -89,22 +89,22 @@ public List increaseDownloadCounts(Map extensionDownlo }); return extensions; -// }); + }); } @Transactional //needs transaction for lazy-loading versions public void evictCaches(List extensions) { -// Observation.createNotStarted("AzureDownloadCountProcessor#evictCaches", observations).observe(() -> { + Observation.createNotStarted("AzureDownloadCountProcessor#evictCaches", observations).observe(() -> { extensions.forEach(extension -> { extension = entityManager.merge(extension); cache.evictExtensionJsons(extension); cache.evictLatestExtensionVersion(extension); }); -// }); + }); } public void updateSearchEntries(List extensions) { -// Observation.createNotStarted("AzureDownloadCountProcessor#updateSearchEntries", observations).observe(() -> { + Observation.createNotStarted("AzureDownloadCountProcessor#updateSearchEntries", observations).observe(() -> { logger.info(">> updateSearchEntries"); var activeExtensions = extensions.stream() .filter(Extension::isActive) @@ -116,12 +116,12 @@ public void updateSearchEntries(List extensions) { parts.forEach(search::updateSearchEntriesAsync); logger.info("<< updateSearchEntries"); -// }); + }); } public List processedItems(List blobNames) { -// return Observation.createNotStarted("AzureDownloadCountProcessor#processedItems", observations).observe(() -> { + return Observation.createNotStarted("AzureDownloadCountProcessor#processedItems", observations).observe(() -> { return repositories.findAllSucceededAzureDownloadCountProcessedItemsByNameIn(blobNames); -// }); + }); } } diff --git a/server/src/main/java/org/eclipse/openvsx/storage/AzureDownloadCountService.java b/server/src/main/java/org/eclipse/openvsx/storage/AzureDownloadCountService.java index 8f762e994..e46bfe225 100644 --- a/server/src/main/java/org/eclipse/openvsx/storage/AzureDownloadCountService.java +++ b/server/src/main/java/org/eclipse/openvsx/storage/AzureDownloadCountService.java @@ -88,7 +88,7 @@ public AzureDownloadCountService( * Indicates whether the download service is enabled by application config. */ public boolean isEnabled() { -// return Observation.createNotStarted("AzureDownloadCountService#isEnabled", observations).observe(() -> { + return Observation.createNotStarted("AzureDownloadCountService#isEnabled", observations).observe(() -> { var logsEnabled = !StringUtils.isEmpty(logsServiceEndpoint); var storageEnabled = !StringUtils.isEmpty(storageServiceEndpoint); if (logsEnabled && !storageEnabled) { @@ -96,7 +96,7 @@ public boolean isEnabled() { } return logsEnabled && storageEnabled; -// }); + }); } /** @@ -105,7 +105,7 @@ public boolean isEnabled() { @Job(name = "Update Download Counts", retries = 0) @Recurring(id = "update-download-counts", cron = "0 5 * * * *", zoneId = "UTC") public void updateDownloadCounts() { -// Observation.createNotStarted("AzureDownloadCountService#updateDownloadCounts", observations).observe(() -> { + Observation.createNotStarted("AzureDownloadCountService#updateDownloadCounts", observations).observe(() -> { if (!isEnabled()) { return; } @@ -153,9 +153,9 @@ public void updateDownloadCounts() { stopWatch.stop(); var executionTime = (int) stopWatch.getLastTaskTimeMillis(); processor.persistProcessedItem(name, processedOn, executionTime, success); -// if(success) { -// deleteBlob(name); -// } + if(success) { + deleteBlob(name); + } } } @@ -164,7 +164,7 @@ public void updateDownloadCounts() { } logger.info("<< updateDownloadCounts"); -// }); + }); } private void deleteBlob(String blobName) { @@ -180,7 +180,7 @@ private void deleteBlob(String blobName) { } private Map processBlobItem(String blobName) { -// return Observation.createNotStarted("AzureDownloadCountService#processBlobItem", observations).observe(() -> { + return Observation.createNotStarted("AzureDownloadCountService#processBlobItem", observations).observe(() -> { try ( var downloadsTempFile = downloadBlobItem(blobName); var reader = Files.newBufferedReader(downloadsTempFile.getPath()) @@ -213,26 +213,26 @@ private Map processBlobItem(String blobName) { } catch (IOException e) { throw new RuntimeException(e); } -// }); + }); } - private TempFile downloadBlobItem(String blobName) throws IOException { -// return Observation.createNotStarted("AzureDownloadCountService#downloadBlobItem", observations).observe(() -> { -// TempFile downloadsTempFile = null; -// try { - var downloadsTempFile = new TempFile("azure-downloads-", ".json"); -// } catch (IOException e) { -// // TODO add `throws IOException` to `downloadBlobItem` method signature when reverting Observations -// // TODO remove try catch around `downloadsTempFile` -// throw new RuntimeException(e); -// } + private TempFile downloadBlobItem(String blobName) /*throws IOException*/ { + return Observation.createNotStarted("AzureDownloadCountService#downloadBlobItem", observations).observe(() -> { + TempFile downloadsTempFile; + try { + downloadsTempFile = new TempFile("azure-downloads-", ".json"); + } catch (IOException e) { + // TODO add `throws IOException` to `downloadBlobItem` method signature when reverting Observations + // TODO remove try catch around `downloadsTempFile` + throw new RuntimeException(e); + } getContainerClient().getBlobClient(blobName).downloadToFile(downloadsTempFile.getPath().toAbsolutePath().toString(), true); return downloadsTempFile; -// }); + }); } private List getBlobNames(List items) { -// return Observation.createNotStarted("AzureDownloadCountService#getBlobNames", observations).observe(() -> { + return Observation.createNotStarted("AzureDownloadCountService#getBlobNames", observations).observe(() -> { var blobNames = new ArrayList(); for (var item : items) { var name = item.getName(); @@ -242,11 +242,11 @@ private List getBlobNames(List items) { } return blobNames; -// }); + }); } private PagedIterable listBlobs() { -// return Observation.createNotStarted("AzureDownloadCountService#listBlobs", observations).observe(() -> { + return Observation.createNotStarted("AzureDownloadCountService#listBlobs", observations).observe(() -> { var details = new BlobListDetails() .setRetrieveCopy(false) .setRetrieveMetadata(false) @@ -258,7 +258,7 @@ private PagedIterable listBlobs() { var options = new ListBlobsOptions().setMaxResultsPerPage(100).setDetails(details); return getContainerClient().listBlobs(options, Duration.ofMinutes(5)); -// }); + }); } private BlobContainerClient getContainerClient() { diff --git a/server/src/main/java/org/eclipse/openvsx/storage/LocalStorageService.java b/server/src/main/java/org/eclipse/openvsx/storage/LocalStorageService.java index 9b9c0cc99..31cc5acf9 100644 --- a/server/src/main/java/org/eclipse/openvsx/storage/LocalStorageService.java +++ b/server/src/main/java/org/eclipse/openvsx/storage/LocalStorageService.java @@ -9,7 +9,6 @@ * ****************************************************************************** */ package org.eclipse.openvsx.storage; -import io.micrometer.observation.annotation.Observed; import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; import org.eclipse.openvsx.entities.FileResource; @@ -38,7 +37,6 @@ public URI getLocation(FileResource resource) { return URI.create(UrlUtil.createApiFileUrl(UrlUtil.getBaseUrl(), resource.getExtension(), resource.getName())); } - @Observed public URI getNamespaceLogoLocation(Namespace namespace) { return URI.create(UrlUtil.createApiUrl(UrlUtil.getBaseUrl(), "api", namespace.getName(), "logo", namespace.getLogoName())); } diff --git a/server/src/main/java/org/eclipse/openvsx/storage/StorageUtilService.java b/server/src/main/java/org/eclipse/openvsx/storage/StorageUtilService.java index 4832da9ad..04149aeea 100644 --- a/server/src/main/java/org/eclipse/openvsx/storage/StorageUtilService.java +++ b/server/src/main/java/org/eclipse/openvsx/storage/StorageUtilService.java @@ -10,8 +10,6 @@ package org.eclipse.openvsx.storage; import com.google.common.collect.Maps; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; import org.apache.commons.lang3.StringUtils; @@ -22,7 +20,6 @@ import org.eclipse.openvsx.repositories.RepositoryService; import org.eclipse.openvsx.search.SearchUtilService; import org.eclipse.openvsx.util.TempFile; -import org.eclipse.openvsx.util.UrlUtil; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.util.Pair; import org.springframework.http.CacheControl; @@ -31,9 +28,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; -import java.io.IOException; import java.net.URI; -import java.nio.file.Files; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -56,7 +51,6 @@ public class StorageUtilService implements IStorageService { private final SearchUtilService search; private final CacheService cache; private final EntityManager entityManager; - private final ObservationRegistry observations; /** Determines which external storage service to use in case multiple services are configured. */ @Value("${ovsx.storage.primary-service:}") @@ -74,8 +68,7 @@ public StorageUtilService( LocalStorageService localStorage, SearchUtilService search, CacheService cache, - EntityManager entityManager, - ObservationRegistry observations + EntityManager entityManager ) { this.repositories = repositories; this.googleStorage = googleStorage; @@ -85,7 +78,6 @@ public StorageUtilService( this.search = search; this.cache = cache; this.entityManager = entityManager; - this.observations = observations; } public boolean shouldStoreExternally(FileResource resource) { @@ -239,19 +231,17 @@ public URI getNamespaceLogoLocation(Namespace namespace) { * Returns URLs for the given file types as a map of ExtensionVersion.id by a map of type by file URL, to be used in JSON response data. */ public Map> getFileUrls(Collection extVersions, String serverUrl, String... types) { - return Observation.createNotStarted("StorageUtilService#getFileUrls", observations).observe(() -> { - var type2Url = extVersions.stream() - .map(ev -> new AbstractMap.SimpleEntry>(ev.getId(), Maps.newLinkedHashMapWithExpectedSize(types.length))) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - - var resources = repositories.findFilesByType(extVersions, Arrays.asList(types)); - for (var resource : resources) { - var extVersion = resource.getExtension(); - type2Url.get(extVersion.getId()).put(resource.getType(), createApiFileUrl(serverUrl, extVersion, resource.getName())); - } - - return type2Url; - }); + var type2Url = extVersions.stream() + .map(ev -> new AbstractMap.SimpleEntry>(ev.getId(), Maps.newLinkedHashMapWithExpectedSize(types.length))) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + var resources = repositories.findFilesByType(extVersions, Arrays.asList(types)); + for (var resource : resources) { + var extVersion = resource.getExtension(); + type2Url.get(extVersion.getId()).put(resource.getType(), createApiFileUrl(serverUrl, extVersion, resource.getName())); + } + + return type2Url; } @Transactional diff --git a/server/src/main/java/org/eclipse/openvsx/util/ArchiveUtil.java b/server/src/main/java/org/eclipse/openvsx/util/ArchiveUtil.java index d553bc288..79a5e418e 100644 --- a/server/src/main/java/org/eclipse/openvsx/util/ArchiveUtil.java +++ b/server/src/main/java/org/eclipse/openvsx/util/ArchiveUtil.java @@ -9,9 +9,6 @@ ********************************************************************************/ package org.eclipse.openvsx.util; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; - import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipException; @@ -31,27 +28,22 @@ public static ZipEntry getEntryIgnoreCase(ZipFile archive, String entryName) { .orElse(null); } - public static byte[] readEntry(ZipFile archive, String entryName, ObservationRegistry observations) { - return Observation.createNotStarted("ArchiveUtil#readEntry", observations).observe(() -> { - var entry = archive.getEntry(entryName); - if (entry == null) - return null; - return readEntry(archive, entry, observations); - }); + public static byte[] readEntry(ZipFile archive, String entryName) { + var entry = archive.getEntry(entryName); + if (entry == null) + return null; + return readEntry(archive, entry); } - public static byte[] readEntry(ZipFile archive, ZipEntry entry, ObservationRegistry observations) { - return Observation.createNotStarted("ArchiveUtil#readEntry", observations).observe(() -> { - try { - if (entry.getSize() > MAX_ENTRY_SIZE) - throw new ErrorResultException("The file " + entry.getName() + " exceeds the size limit of 32 MB."); - return archive.getInputStream(entry).readAllBytes(); - } catch (ZipException exc) { - throw new ErrorResultException("Could not read zip file: " + exc.getMessage(), exc); - } catch (IOException exc) { - throw new RuntimeException(exc); - } - }); + public static byte[] readEntry(ZipFile archive, ZipEntry entry) { + try { + if (entry.getSize() > MAX_ENTRY_SIZE) + throw new ErrorResultException("The file " + entry.getName() + " exceeds the size limit of 32 MB."); + return archive.getInputStream(entry).readAllBytes(); + } catch (ZipException exc) { + throw new ErrorResultException("Could not read zip file: " + exc.getMessage(), exc); + } catch (IOException exc) { + throw new RuntimeException(exc); + } } - } \ No newline at end of file diff --git a/server/src/test/java/org/eclipse/openvsx/ExtensionProcessorTest.java b/server/src/test/java/org/eclipse/openvsx/ExtensionProcessorTest.java index de3f9dcec..cdff3e6e3 100644 --- a/server/src/test/java/org/eclipse/openvsx/ExtensionProcessorTest.java +++ b/server/src/test/java/org/eclipse/openvsx/ExtensionProcessorTest.java @@ -9,7 +9,6 @@ ********************************************************************************/ package org.eclipse.openvsx; -import io.micrometer.observation.ObservationRegistry; import org.eclipse.openvsx.entities.FileResource; import org.eclipse.openvsx.util.TempFile; import org.junit.jupiter.api.Test; @@ -26,7 +25,7 @@ class ExtensionProcessorTest { void testTodoTree() throws Exception { try ( var file = writeToTempFile("util/todo-tree.zip"); - var processor = new ExtensionProcessor(file, ObservationRegistry.NOOP) + var processor = new ExtensionProcessor(file) ) { assertThat(processor.getNamespace()).isEqualTo("Gruntfuggly"); assertThat(processor.getExtensionName()).isEqualTo("todo-tree"); @@ -51,7 +50,7 @@ void testTodoTree() throws Exception { void testChangelog() throws Exception { try ( var file = writeToTempFile("util/changelog.zip"); - var processor = new ExtensionProcessor(file, ObservationRegistry.NOOP) + var processor = new ExtensionProcessor(file) ) { checkResource(processor, FileResource.CHANGELOG, "CHANGELOG.md"); } @@ -61,7 +60,7 @@ void testChangelog() throws Exception { void testCapitalizedCaseForResources() throws Exception { try ( var file = writeToTempFile("util/with-capitalized-case.zip"); - var processor = new ExtensionProcessor(file, ObservationRegistry.NOOP) + var processor = new ExtensionProcessor(file) ) { checkResource(processor, FileResource.CHANGELOG, "Changelog.md"); checkResource(processor, FileResource.README, "Readme.md"); @@ -73,7 +72,7 @@ void testCapitalizedCaseForResources() throws Exception { void testMinorCaseForResources() throws Exception { try ( var file = writeToTempFile("util/with-minor-case.zip"); - var processor = new ExtensionProcessor(file, ObservationRegistry.NOOP) + var processor = new ExtensionProcessor(file) ) { checkResource(processor, FileResource.CHANGELOG, "changelog.md"); checkResource(processor, FileResource.README, "readme.md"); diff --git a/server/src/test/java/org/eclipse/openvsx/ExtensionValidatorTest.java b/server/src/test/java/org/eclipse/openvsx/ExtensionValidatorTest.java index 876dd4ae9..ff1b7c210 100644 --- a/server/src/test/java/org/eclipse/openvsx/ExtensionValidatorTest.java +++ b/server/src/test/java/org/eclipse/openvsx/ExtensionValidatorTest.java @@ -9,7 +9,6 @@ ********************************************************************************/ package org.eclipse.openvsx; -import io.micrometer.observation.ObservationRegistry; import org.eclipse.openvsx.entities.ExtensionVersion; import org.eclipse.openvsx.util.TargetPlatform; import org.junit.jupiter.api.Test; @@ -113,13 +112,8 @@ public void testGitProtocol() { @TestConfiguration static class TestConfig { @Bean - ExtensionValidator extensionValidator(ObservationRegistry observations) { - return new ExtensionValidator(observations); - } - - @Bean - ObservationRegistry observationRegistry() { - return ObservationRegistry.NOOP; + ExtensionValidator extensionValidator() { + return new ExtensionValidator(); } } } \ No newline at end of file diff --git a/server/src/test/java/org/eclipse/openvsx/RegistryAPITest.java b/server/src/test/java/org/eclipse/openvsx/RegistryAPITest.java index dd2e424dc..b7db9cd77 100644 --- a/server/src/test/java/org/eclipse/openvsx/RegistryAPITest.java +++ b/server/src/test/java/org/eclipse/openvsx/RegistryAPITest.java @@ -12,7 +12,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import org.eclipse.openvsx.adapter.VSCodeIdService; import org.eclipse.openvsx.cache.CacheService; @@ -2332,8 +2331,7 @@ LocalRegistryService localRegistryService( StorageUtilService storageUtil, EclipseService eclipse, CacheService cache, - ExtensionVersionIntegrityService integrityService, - ObservationRegistry observations + ExtensionVersionIntegrityService integrityService ) { return new LocalRegistryService( entityManager, @@ -2346,8 +2344,7 @@ LocalRegistryService localRegistryService( storageUtil, eclipse, cache, - integrityService, - observations + integrityService ); } @@ -2356,15 +2353,14 @@ ExtensionService extensionService( RepositoryService repositories, SearchUtilService search, CacheService cache, - PublishExtensionVersionHandler publishHandler, - ObservationRegistry observations + PublishExtensionVersionHandler publishHandler ) { - return new ExtensionService(repositories, search, cache, publishHandler, observations); + return new ExtensionService(repositories, search, cache, publishHandler); } @Bean - ExtensionValidator extensionValidator(ObservationRegistry observations) { - return new ExtensionValidator(observations); + ExtensionValidator extensionValidator() { + return new ExtensionValidator(); } @Bean @@ -2376,8 +2372,7 @@ StorageUtilService storageUtilService( AzureDownloadCountService azureDownloadCountService, SearchUtilService search, CacheService cache, - EntityManager entityManager, - ObservationRegistry observations + EntityManager entityManager ) { return new StorageUtilService( repositories, @@ -2387,8 +2382,7 @@ StorageUtilService storageUtilService( localStorage, search, cache, - entityManager, - observations + entityManager ); } @@ -2410,11 +2404,6 @@ LatestExtensionVersionCacheKeyGenerator latestExtensionVersionCacheKeyGenerator( return new LatestExtensionVersionCacheKeyGenerator(); } - @Bean - ObservationRegistry observationRegistry() { - return ObservationRegistry.NOOP; - } - @Bean PublishExtensionVersionHandler publishExtensionVersionHandler( PublishExtensionVersionService service, @@ -2424,8 +2413,7 @@ PublishExtensionVersionHandler publishExtensionVersionHandler( JobRequestScheduler scheduler, UserService users, ExtensionValidator validator, - ExtensionControlService extensionControl, - ObservationRegistry observations + ExtensionControlService extensionControl ) { return new PublishExtensionVersionHandler( service, @@ -2435,8 +2423,7 @@ PublishExtensionVersionHandler publishExtensionVersionHandler( scheduler, users, validator, - extensionControl, - observations + extensionControl ); } } diff --git a/server/src/test/java/org/eclipse/openvsx/UserAPITest.java b/server/src/test/java/org/eclipse/openvsx/UserAPITest.java index 7988c64a9..fd4580343 100644 --- a/server/src/test/java/org/eclipse/openvsx/UserAPITest.java +++ b/server/src/test/java/org/eclipse/openvsx/UserAPITest.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.function.Consumer; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import org.eclipse.openvsx.cache.CacheService; @@ -588,11 +587,6 @@ TokenService tokenService( LatestExtensionVersionCacheKeyGenerator latestExtensionVersionCacheKeyGenerator() { return new LatestExtensionVersionCacheKeyGenerator(); } - - @Bean - ObservationRegistry observationRegistry() { - return ObservationRegistry.NOOP; - } } } \ No newline at end of file diff --git a/server/src/test/java/org/eclipse/openvsx/adapter/VSCodeAPITest.java b/server/src/test/java/org/eclipse/openvsx/adapter/VSCodeAPITest.java index 047e362aa..0587a37a7 100644 --- a/server/src/test/java/org/eclipse/openvsx/adapter/VSCodeAPITest.java +++ b/server/src/test/java/org/eclipse/openvsx/adapter/VSCodeAPITest.java @@ -14,7 +14,6 @@ import com.google.common.collect.Lists; import com.google.common.io.CharStreams; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import org.eclipse.openvsx.ExtensionValidator; import org.eclipse.openvsx.MockTransactionTemplate; @@ -946,10 +945,9 @@ UserService userService( RepositoryService repositories, StorageUtilService storageUtil, CacheService cache, - ExtensionValidator validator, - ObservationRegistry observations + ExtensionValidator validator ) { - return new UserService(entityManager, repositories, storageUtil, cache, validator, observations); + return new UserService(entityManager, repositories, storageUtil, cache, validator); } @Bean @@ -961,8 +959,7 @@ StorageUtilService storageUtilService( AzureDownloadCountService azureDownloadCountService, SearchUtilService search, CacheService cache, - EntityManager entityManager, - ObservationRegistry observations + EntityManager entityManager ) { return new StorageUtilService( repositories, @@ -972,8 +969,7 @@ StorageUtilService storageUtilService( localStorage, search, cache, - entityManager, - observations + entityManager ); } @@ -991,11 +987,6 @@ VersionService getVersionService() { LatestExtensionVersionCacheKeyGenerator latestExtensionVersionCacheKeyGenerator() { return new LatestExtensionVersionCacheKeyGenerator(); } - - @Bean - ObservationRegistry observationRegistry() { - return ObservationRegistry.NOOP; - } } } diff --git a/server/src/test/java/org/eclipse/openvsx/admin/AdminAPITest.java b/server/src/test/java/org/eclipse/openvsx/admin/AdminAPITest.java index c9b6ec062..6b83e7333 100644 --- a/server/src/test/java/org/eclipse/openvsx/admin/AdminAPITest.java +++ b/server/src/test/java/org/eclipse/openvsx/admin/AdminAPITest.java @@ -12,7 +12,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.observation.ObservationRegistry; import org.eclipse.openvsx.*; import org.eclipse.openvsx.adapter.VSCodeIdService; import org.eclipse.openvsx.cache.CacheService; @@ -1258,8 +1257,7 @@ LocalRegistryService localRegistryService( StorageUtilService storageUtil, EclipseService eclipse, CacheService cache, - ExtensionVersionIntegrityService integrityService, - ObservationRegistry observations + ExtensionVersionIntegrityService integrityService ) { return new LocalRegistryService( entityManager, @@ -1272,30 +1270,23 @@ LocalRegistryService localRegistryService( storageUtil, eclipse, cache, - integrityService, - observations + integrityService ); } - @Bean - ObservationRegistry observationRegistry() { - return ObservationRegistry.NOOP; - } - @Bean ExtensionService extensionService( RepositoryService repositories, SearchUtilService search, CacheService cache, - PublishExtensionVersionHandler publishHandler, - ObservationRegistry observations + PublishExtensionVersionHandler publishHandler ) { - return new ExtensionService(repositories, search, cache, publishHandler, observations); + return new ExtensionService(repositories, search, cache, publishHandler); } @Bean - ExtensionValidator extensionValidator(ObservationRegistry observations) { - return new ExtensionValidator(observations); + ExtensionValidator extensionValidator() { + return new ExtensionValidator(); } @Bean @@ -1307,8 +1298,7 @@ StorageUtilService storageUtilService( AzureDownloadCountService azureDownloadCountService, SearchUtilService search, CacheService cache, - EntityManager entityManager, - ObservationRegistry observations + EntityManager entityManager ) { return new StorageUtilService( repositories, @@ -1318,8 +1308,7 @@ StorageUtilService storageUtilService( localStorage, search, cache, - entityManager, - observations + entityManager ); } diff --git a/server/src/test/java/org/eclipse/openvsx/cache/CacheServiceTest.java b/server/src/test/java/org/eclipse/openvsx/cache/CacheServiceTest.java index 4c7f0eeca..06034b2e0 100644 --- a/server/src/test/java/org/eclipse/openvsx/cache/CacheServiceTest.java +++ b/server/src/test/java/org/eclipse/openvsx/cache/CacheServiceTest.java @@ -9,7 +9,8 @@ * ****************************************************************************** */ package org.eclipse.openvsx.cache; -import io.micrometer.observation.ObservationRegistry; +import jakarta.persistence.EntityManager; +import jakarta.transaction.Transactional; import org.eclipse.openvsx.ExtensionService; import org.eclipse.openvsx.LocalRegistryService; import org.eclipse.openvsx.UserService; @@ -33,8 +34,6 @@ import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; -import jakarta.persistence.EntityManager; -import jakarta.transaction.Transactional; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.util.Collections; diff --git a/server/src/test/java/org/eclipse/openvsx/eclipse/EclipseServiceTest.java b/server/src/test/java/org/eclipse/openvsx/eclipse/EclipseServiceTest.java index 0ad846c22..638aedbd4 100644 --- a/server/src/test/java/org/eclipse/openvsx/eclipse/EclipseServiceTest.java +++ b/server/src/test/java/org/eclipse/openvsx/eclipse/EclipseServiceTest.java @@ -19,7 +19,6 @@ import java.time.LocalDateTime; import java.util.Map; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import org.eclipse.openvsx.ExtensionService; @@ -270,20 +269,14 @@ TransactionTemplate transactionTemplate() { return new MockTransactionTemplate(); } - @Bean - ObservationRegistry observationRegistry() { - return ObservationRegistry.NOOP; - } - @Bean EclipseService eclipseService( TokenService tokens, ExtensionService extensions, EntityManager entityManager, - RestTemplate restTemplate, - ObservationRegistry observations + RestTemplate restTemplate ) { - return new EclipseService(tokens, extensions, entityManager, restTemplate, observations); + return new EclipseService(tokens, extensions, entityManager, restTemplate); } @Bean @@ -291,15 +284,14 @@ ExtensionService extensionService( RepositoryService repositories, SearchUtilService search, CacheService cache, - PublishExtensionVersionHandler publishHandler, - ObservationRegistry observations + PublishExtensionVersionHandler publishHandler ) { - return new ExtensionService(repositories, search, cache, publishHandler, observations); + return new ExtensionService(repositories, search, cache, publishHandler); } @Bean - ExtensionValidator extensionValidator(ObservationRegistry observations) { - return new ExtensionValidator(observations); + ExtensionValidator extensionValidator() { + return new ExtensionValidator(); } @Bean @@ -311,8 +303,7 @@ StorageUtilService storageUtilService( AzureDownloadCountService azureDownloadCountService, SearchUtilService search, CacheService cache, - EntityManager entityManager, - ObservationRegistry observations + EntityManager entityManager ) { return new StorageUtilService( repositories, @@ -322,8 +313,7 @@ StorageUtilService storageUtilService( localStorage, search, cache, - entityManager, - observations + entityManager ); } diff --git a/server/src/test/java/org/eclipse/openvsx/publish/ExtensionVersionIntegrityServiceTest.java b/server/src/test/java/org/eclipse/openvsx/publish/ExtensionVersionIntegrityServiceTest.java index 59d664082..aee3a1de8 100644 --- a/server/src/test/java/org/eclipse/openvsx/publish/ExtensionVersionIntegrityServiceTest.java +++ b/server/src/test/java/org/eclipse/openvsx/publish/ExtensionVersionIntegrityServiceTest.java @@ -9,7 +9,6 @@ * ****************************************************************************** */ package org.eclipse.openvsx.publish; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import org.eclipse.openvsx.cache.CacheService; import org.eclipse.openvsx.entities.Extension; @@ -86,15 +85,15 @@ public void testGenerateSignature() throws IOException { assertNotNull(entry); if(expectedEntry.getName().equals(".signature.manifest")) { assertEquals( - new String(ArchiveUtil.readEntry(expectedSigZip, expectedEntry, ObservationRegistry.NOOP)), - new String(ArchiveUtil.readEntry(sigzip, entry, ObservationRegistry.NOOP)) + new String(ArchiveUtil.readEntry(expectedSigZip, expectedEntry)), + new String(ArchiveUtil.readEntry(sigzip, entry)) ); } }); var entry = sigzip.getEntry(".signature.sig"); assertNotNull(entry); - assertTrue(ArchiveUtil.readEntry(sigzip, entry, ObservationRegistry.NOOP).length > 0); + assertTrue(ArchiveUtil.readEntry(sigzip, entry).length > 0); } } } diff --git a/server/src/test/java/org/eclipse/openvsx/search/DatabaseSearchServiceTest.java b/server/src/test/java/org/eclipse/openvsx/search/DatabaseSearchServiceTest.java index c48c662ca..46cd8947f 100644 --- a/server/src/test/java/org/eclipse/openvsx/search/DatabaseSearchServiceTest.java +++ b/server/src/test/java/org/eclipse/openvsx/search/DatabaseSearchServiceTest.java @@ -10,7 +10,6 @@ package org.eclipse.openvsx.search; -import io.micrometer.observation.ObservationRegistry; import jakarta.persistence.EntityManager; import org.eclipse.openvsx.cache.LatestExtensionVersionCacheKeyGenerator; import org.eclipse.openvsx.entities.*; @@ -346,10 +345,5 @@ RelevanceService relevanceService(RepositoryService repositories) { LatestExtensionVersionCacheKeyGenerator latestExtensionVersionCacheKeyGenerator() { return new LatestExtensionVersionCacheKeyGenerator(); } - - @Bean - ObservationRegistry observationRegistry() { - return ObservationRegistry.NOOP; - } } } \ No newline at end of file diff --git a/server/src/test/java/org/eclipse/openvsx/search/ElasticSearchServiceTest.java b/server/src/test/java/org/eclipse/openvsx/search/ElasticSearchServiceTest.java index dbc51e1b5..946c99ebf 100644 --- a/server/src/test/java/org/eclipse/openvsx/search/ElasticSearchServiceTest.java +++ b/server/src/test/java/org/eclipse/openvsx/search/ElasticSearchServiceTest.java @@ -9,7 +9,6 @@ ********************************************************************************/ package org.eclipse.openvsx.search; -import io.micrometer.observation.ObservationRegistry; import org.eclipse.openvsx.cache.LatestExtensionVersionCacheKeyGenerator; import org.eclipse.openvsx.entities.*; import org.eclipse.openvsx.repositories.RepositoryService; @@ -299,11 +298,6 @@ RelevanceService relevanceService(RepositoryService repositories) { LatestExtensionVersionCacheKeyGenerator latestExtensionVersionCacheKeyGenerator() { return new LatestExtensionVersionCacheKeyGenerator(); } - - @Bean - ObservationRegistry observationRegistry() { - return ObservationRegistry.NOOP; - } } } \ No newline at end of file diff --git a/server/src/test/java/org/eclipse/openvsx/util/ArchiveUtilTest.java b/server/src/test/java/org/eclipse/openvsx/util/ArchiveUtilTest.java index 1bc0bb3aa..1afe98f7b 100644 --- a/server/src/test/java/org/eclipse/openvsx/util/ArchiveUtilTest.java +++ b/server/src/test/java/org/eclipse/openvsx/util/ArchiveUtilTest.java @@ -13,7 +13,6 @@ import java.util.zip.ZipFile; -import io.micrometer.observation.ObservationRegistry; import org.junit.jupiter.api.Test; public class ArchiveUtilTest { @@ -25,9 +24,9 @@ public void testTodoTree() throws Exception { try ( var archive = new ZipFile(packageUrl.getPath()); ) { - var packageJson = ArchiveUtil.readEntry(archive, "extension/package.json", ObservationRegistry.NOOP); + var packageJson = ArchiveUtil.readEntry(archive, "extension/package.json"); assertThat(packageJson.length).isEqualTo(44712); - var icon = ArchiveUtil.readEntry(archive, "extension/resources/todo-tree.png", ObservationRegistry.NOOP); + var icon = ArchiveUtil.readEntry(archive, "extension/resources/todo-tree.png"); assertThat(icon.length).isEqualTo(8854); } }