Skip to content

Commit

Permalink
Merge pull request #874 from amvanbaren/observe-targetplatform-endpoints
Browse files Browse the repository at this point in the history
Change observed endpoints
  • Loading branch information
amvanbaren committed Mar 20, 2024
2 parents b7ad4a8 + b4843e6 commit 8e145b2
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
********************************************************************************/
package org.eclipse.openvsx;

import io.micrometer.observation.annotation.Observed;
import org.eclipse.openvsx.json.*;
import org.eclipse.openvsx.search.ISearchService;
import org.springframework.http.ResponseEntity;
Expand All @@ -20,8 +21,10 @@ public interface IExtensionRegistry {

NamespaceJson getNamespace(String namespace);

@Observed
ExtensionJson getExtension(String namespace, String extensionName, String targetPlatform);

@Observed
ExtensionJson getExtension(String namespace, String extensionName, String targetPlatform, String version);

VersionsJson getVersions(String namespace, String extension, String targetPlatform, int size, int offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ public NamespaceJson getNamespace(String namespaceName) {
}

@Override
@Observed
@Cacheable(value = CACHE_EXTENSION_JSON, keyGenerator = GENERATOR_EXTENSION_JSON)
public ExtensionJson getExtension(String namespace, String extensionName, String targetPlatform) {
return getExtension(namespace, extensionName, targetPlatform, VersionAlias.LATEST);
}

@Override
@Observed
@Cacheable(value = CACHE_EXTENSION_JSON, keyGenerator = GENERATOR_EXTENSION_JSON)
public ExtensionJson getExtension(String namespace, String extensionName, String targetPlatform, String version) {
var extVersion = findExtensionVersion(namespace, extensionName, targetPlatform, version);
Expand Down Expand Up @@ -261,7 +263,6 @@ public ReviewListJson getReviews(String namespace, String extensionName) {
}

@Override
@Observed
public SearchResultJson search(ISearchService.Options options) {
var json = new SearchResultJson();
var size = options.requestedSize;
Expand All @@ -283,7 +284,6 @@ public SearchResultJson search(ISearchService.Options options) {
}

@Override
@Observed
public QueryResultJson query(QueryRequest request) {
if (!StringUtils.isEmpty(request.extensionId)) {
var split = request.extensionId.split("\\.");
Expand Down Expand Up @@ -335,7 +335,6 @@ public QueryResultJson query(QueryRequest request) {
}

@Override
@Observed
public QueryResultJson queryV2(QueryRequestV2 request) {
if (!StringUtils.isEmpty(request.extensionId)) {
var split = request.extensionId.split("\\.");
Expand Down
5 changes: 2 additions & 3 deletions server/src/main/java/org/eclipse/openvsx/RegistryAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public ResponseEntity<ExtensionJson> getExtension(
return new ResponseEntity<>(json, HttpStatus.NOT_FOUND);
}

@Observed
@GetMapping(
path = "/api/{namespace}/{extension}/{targetPlatform:" + TargetPlatform.NAMES_PATH_PARAM_REGEX + "}",
produces = MediaType.APPLICATION_JSON_VALUE
Expand Down Expand Up @@ -400,6 +401,7 @@ public ResponseEntity<ExtensionJson> getExtension(
return new ResponseEntity<>(json, HttpStatus.NOT_FOUND);
}

@Observed
@GetMapping(
path = "/api/{namespace}/{extension}/{targetPlatform:" + TargetPlatform.NAMES_PATH_PARAM_REGEX + "}/{version:" + VERSION_PATH_PARAM_REGEX + "}",
produces = MediaType.APPLICATION_JSON_VALUE
Expand Down Expand Up @@ -905,7 +907,6 @@ public ResponseEntity<ReviewListJson> getReviews(
return new ResponseEntity<>(json, HttpStatus.NOT_FOUND);
}

@Observed
@GetMapping(
path = "/api/-/search",
produces = MediaType.APPLICATION_JSON_VALUE
Expand Down Expand Up @@ -1032,7 +1033,6 @@ private int mergeSearchResults(SearchResultJson result, List<SearchEntryJson> en
return mergedEntries;
}

@Observed
@GetMapping(
path = "/api/v2/-/query",
produces = MediaType.APPLICATION_JSON_VALUE
Expand Down Expand Up @@ -1145,7 +1145,6 @@ public ResponseEntity<QueryResultJson> getQueryV2(
.body(result);
}

@Observed
@GetMapping(
path = "/api/-/query",
produces = MediaType.APPLICATION_JSON_VALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public ResponseEntity<byte[]> getNamespaceLogo(String namespaceName, String file
}

@Override
@Observed
public ExtensionJson getExtension(String namespace, String extension, String targetPlatform) {
var urlTemplate = urlConfigService.getUpstreamUrl() + "/api/{namespace}/{extension}";
var uriVariables = new HashMap<String, String>();
Expand All @@ -111,6 +112,7 @@ public ExtensionJson getExtension(String namespace, String extension, String tar
}

@Override
@Observed
public ExtensionJson getExtension(String namespace, String extension, String targetPlatform, String version) {
var urlTemplate = urlConfigService.getUpstreamUrl() + "/api/{namespace}/{extension}";
var uriVariables = new HashMap<String, String>();
Expand Down Expand Up @@ -260,7 +262,6 @@ public ReviewListJson getReviews(String namespace, String extension) {
}

@Override
@Observed
public SearchResultJson search(ISearchService.Options options) {
var urlTemplate = urlConfigService.getUpstreamUrl() + "/api/-/search";
var uriVariables = new HashMap<String,String>();
Expand Down Expand Up @@ -295,7 +296,6 @@ public SearchResultJson search(ISearchService.Options options) {
}

@Override
@Observed
public QueryResultJson query(QueryRequest request) {
var urlTemplate = urlConfigService.getUpstreamUrl() + "/api/-/query";
var queryParams = new HashMap<String,String>();
Expand Down Expand Up @@ -333,7 +333,6 @@ public QueryResultJson query(QueryRequest request) {
}

@Override
@Observed
public QueryResultJson queryV2(QueryRequestV2 request) {
var urlTemplate = urlConfigService.getUpstreamUrl() + "/api/v2/-/query";
var queryParams = new HashMap<String,String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* ****************************************************************************** */
package org.eclipse.openvsx.cache;

import io.micrometer.observation.annotation.Observed;
import org.eclipse.openvsx.util.NamingUtil;
import org.eclipse.openvsx.util.VersionAlias;
import org.springframework.cache.interceptor.KeyGenerator;
Expand All @@ -19,11 +20,13 @@
@Component
public class ExtensionJsonCacheKeyGenerator implements KeyGenerator {
@Override
@Observed
public Object generate(Object target, Method method, Object... params) {
var version = params.length == 4 ? (String) params[3] : VersionAlias.LATEST;
return generate((String) params[0], (String) params[1], (String) params[2], version);
}

@Observed
public String generate(String namespaceName, String extensionName, String targetPlatform, String version) {
return NamingUtil.toFileFormat(namespaceName, extensionName, version, targetPlatform);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* ****************************************************************************** */
package org.eclipse.openvsx.cache;

import io.micrometer.observation.annotation.Observed;
import org.eclipse.openvsx.entities.Extension;
import org.eclipse.openvsx.entities.ExtensionVersion;
import org.eclipse.openvsx.util.NamingUtil;
Expand All @@ -22,6 +23,7 @@
@Component
public class LatestExtensionVersionCacheKeyGenerator implements KeyGenerator {
@Override
@Observed
public Object generate(Object target, Method method, Object... params) {
Extension extension;
String targetPlatform;
Expand Down Expand Up @@ -49,6 +51,7 @@ public Object generate(Object target, Method method, Object... params) {
return generate(extension, targetPlatform, preRelease, onlyActive, type);
}

@Observed
public String generate(Extension extension, String targetPlatform, boolean preRelease, boolean onlyActive, ExtensionVersion.Type type) {
var extensionName = extension.getName();
var namespaceName = extension.getNamespace().getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
********************************************************************************/
package org.eclipse.openvsx.repositories;

import io.micrometer.observation.annotation.Observed;
import org.eclipse.openvsx.entities.Extension;
import org.eclipse.openvsx.entities.Namespace;
import org.eclipse.openvsx.entities.UserData;
Expand All @@ -29,6 +30,7 @@ public interface ExtensionRepository extends Repository<Extension, Long> {

Extension findByNameIgnoreCaseAndNamespace(String name, Namespace namespace);

@Observed
Extension findByNameIgnoreCaseAndNamespaceNameIgnoreCase(String name, String namespace);

Extension findByPublicId(String publicId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public List<ExtensionVersion> findActiveVersionReferencesSorted(Collection<Exten
.collect(Collectors.toList());
}

@Observed
public List<String> findVersionStringsSorted(Long extensionId, String targetPlatform, boolean onlyActive, int numberOfRows) {
var conditions = new ArrayList<Condition>();
conditions.add(EXTENSION_VERSION.EXTENSION_ID.eq(extensionId));
Expand Down Expand Up @@ -268,7 +269,6 @@ private List<String> findVersionStringsSorted(List<Condition> conditions, Pageab
return versionsQuery.fetch(record -> record.get(EXTENSION_VERSION.VERSION));
}

@Observed
public Page<ExtensionVersion> findActiveVersions(QueryRequest request) {
var conditions = new ArrayList<Condition>();
if (!StringUtils.isEmpty(request.namespaceUuid)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* ****************************************************************************** */
package org.eclipse.openvsx.repositories;

import io.micrometer.observation.annotation.Observed;
import org.eclipse.openvsx.entities.ExtensionVersion;
import org.eclipse.openvsx.entities.FileResource;
import org.jooq.DSLContext;
Expand All @@ -30,6 +31,7 @@ public class FileResourceJooqRepository {
@Autowired
DSLContext dsl;

@Observed
public List<FileResource> findByType(Collection<ExtensionVersion> extVersions, Collection<String> types) {
if(extVersions.isEmpty() || types.isEmpty()) {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
********************************************************************************/
package org.eclipse.openvsx.repositories;

import io.micrometer.observation.annotation.Observed;
import org.eclipse.openvsx.entities.Namespace;
import org.eclipse.openvsx.entities.NamespaceMembership;
import org.eclipse.openvsx.entities.UserData;
Expand Down Expand Up @@ -57,6 +58,7 @@ private NamespaceMembership toNamespaceMembership(Record record) {
return namespaceMembership;
}

@Observed
public boolean isVerified(Namespace namespace, UserData user) {
var nm = NAMESPACE_MEMBERSHIP.as("nm");
var onm = NAMESPACE_MEMBERSHIP.as("onm");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public Extension findExtension(String name, Namespace namespace) {
return extensionRepo.findByNameIgnoreCaseAndNamespace(name, namespace);
}

@Observed
public Extension findExtension(String name, String namespace) {
return extensionRepo.findByNameIgnoreCaseAndNamespaceNameIgnoreCase(name, namespace);
}
Expand Down Expand Up @@ -155,6 +156,7 @@ public Page<String> findActiveVersionStringsSorted(String namespace, String exte
return extensionVersionJooqRepo.findActiveVersionStringsSorted(namespace, extension, targetPlatform, page);
}

@Observed
public List<String> findVersionStringsSorted(Extension extension, String targetPlatform, boolean onlyActive) {
return extensionVersionJooqRepo.findVersionStringsSorted(extension.getId(), targetPlatform, onlyActive, MAX_VERSIONS);
}
Expand Down Expand Up @@ -219,6 +221,7 @@ public FileResource findFileByType(ExtensionVersion extVersion, String type) {
return fileResourceRepo.findByExtensionAndType(extVersion, type);
}

@Observed
public List<FileResource> findFilesByType(Collection<ExtensionVersion> extVersions, Collection<String> types) {
return fileResourceJooqRepo.findByType(extVersions, types);
}
Expand Down Expand Up @@ -259,6 +262,7 @@ public NamespaceMembership findMembership(UserData user, Namespace namespace) {
return membershipRepo.findByUserAndNamespace(user, namespace);
}

@Observed
public boolean isVerified(Namespace namespace, UserData user) {
return membershipJooqRepo.isVerified(namespace, user);
}
Expand Down Expand Up @@ -319,7 +323,6 @@ public List<Extension> findActiveExtensionsById(Collection<Long> ids) {
return extensionJooqRepo.findAllActiveById(ids);
}

@Observed
public Page<ExtensionVersion> findActiveVersions(QueryRequest request) {
return extensionVersionJooqRepo.findActiveVersions(request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@

package org.eclipse.openvsx.search;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.micrometer.observation.annotation.Observed;
import jakarta.transaction.Transactional;
import org.eclipse.openvsx.entities.Extension;
import org.eclipse.openvsx.repositories.RepositoryService;
import org.eclipse.openvsx.search.RelevanceService.SearchStats;
import org.eclipse.openvsx.util.TargetPlatform;
import org.eclipse.openvsx.util.VersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.elasticsearch.core.*;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.eclipse.openvsx.entities.Extension;
import org.eclipse.openvsx.repositories.RepositoryService;
import org.eclipse.openvsx.search.RelevanceService.SearchStats;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.SearchHitsImpl;
import org.springframework.data.elasticsearch.core.TotalHitsRelation;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import jakarta.transaction.Transactional;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.eclipse.openvsx.cache.CacheService.CACHE_AVERAGE_REVIEW_RATING;
import static org.eclipse.openvsx.cache.CacheService.CACHE_DATABASE_SEARCH;
Expand All @@ -55,7 +56,6 @@ public boolean isEnabled() {
@Autowired
VersionService versions;

@Observed
@Transactional
@Cacheable(CACHE_DATABASE_SEARCH)
@CacheEvict(value = CACHE_AVERAGE_REVIEW_RATING, allEntries = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
import co.elastic.clients.util.ObjectBuilder;
import io.micrometer.observation.annotation.Observed;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.openvsx.entities.Extension;
import org.eclipse.openvsx.migration.HandlerJobRequest;
Expand Down Expand Up @@ -251,7 +250,6 @@ public void removeSearchEntry(Extension extension) {
}
}

@Observed
public SearchHits<ExtensionSearch> search(Options options) {
var resultWindow = options.requestedOffset + options.requestedSize;
if(resultWindow > getMaxResultWindow()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
********************************************************************************/
package org.eclipse.openvsx.search;

import org.eclipse.openvsx.entities.Extension;
import org.springframework.data.elasticsearch.core.SearchHits;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

import io.micrometer.observation.annotation.Observed;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.eclipse.openvsx.entities.Extension;

/**
* Common interface for all search service implementations.
*/
Expand All @@ -31,7 +30,6 @@ public interface ISearchService {
/**
* Search with given options
*/
@Observed
SearchHits<ExtensionSearch> search(Options options);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

package org.eclipse.openvsx.search;

import io.micrometer.observation.annotation.Observed;
import org.eclipse.openvsx.entities.Extension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.eclipse.openvsx.entities.Extension;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -55,7 +54,6 @@ protected ISearchService getImplementation() {

}

@Observed
public SearchHits<ExtensionSearch> search(ElasticSearchService.Options options) {
return getImplementation().search(options);
}
Expand Down

0 comments on commit 8e145b2

Please sign in to comment.