diff --git a/pom.xml b/pom.xml index 5b226b19..dff313b2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.uid2 uid2-shared - 5.3.5-SNAPSHOT + 5.3.6-e4c068510c ${project.groupId}:${project.artifactId} Library for all the shared uid2 operations https://github.com/IABTechLab/uid2docs diff --git a/src/main/java/com/uid2/shared/auth/RotatingOperatorKeyProvider.java b/src/main/java/com/uid2/shared/auth/RotatingOperatorKeyProvider.java index 5493c61b..9bf29600 100644 --- a/src/main/java/com/uid2/shared/auth/RotatingOperatorKeyProvider.java +++ b/src/main/java/com/uid2/shared/auth/RotatingOperatorKeyProvider.java @@ -74,6 +74,11 @@ public OperatorKey getOperatorKey(String token) { return operatorKeyStore.getAuthorizableByKey(token); } + @Override + public OperatorKey getOperatorKeyFromHash(String hash) { + return (OperatorKey) this.operatorKeyStore.getAuthorizableByHash(hash); + } + @Override public Collection getAll() { return operatorKeyStore.getAuthorizables(); diff --git a/src/main/java/com/uid2/shared/store/IOperatorKeyProvider.java b/src/main/java/com/uid2/shared/store/IOperatorKeyProvider.java index ed69875b..8af803c8 100644 --- a/src/main/java/com/uid2/shared/store/IOperatorKeyProvider.java +++ b/src/main/java/com/uid2/shared/store/IOperatorKeyProvider.java @@ -7,5 +7,6 @@ public interface IOperatorKeyProvider extends IAuthorizableProvider { OperatorKey getOperatorKey(String token); + OperatorKey getOperatorKeyFromHash(String hash); Collection getAll(); } diff --git a/src/main/java/com/uid2/shared/store/ScopedStoreReader.java b/src/main/java/com/uid2/shared/store/ScopedStoreReader.java index ecee9432..b3366e20 100644 --- a/src/main/java/com/uid2/shared/store/ScopedStoreReader.java +++ b/src/main/java/com/uid2/shared/store/ScopedStoreReader.java @@ -6,11 +6,14 @@ import com.uid2.shared.store.parser.Parser; import com.uid2.shared.store.parser.ParsingResult; import com.uid2.shared.store.scope.StoreScope; +import io.micrometer.core.instrument.Gauge; +import io.micrometer.core.instrument.Metrics; import io.vertx.core.json.JsonObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.InputStream; +import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; public class ScopedStoreReader { @@ -22,6 +25,7 @@ public class ScopedStoreReader { private final String dataTypeName; private final DownloadCloudStorage contentStreamProvider; private final AtomicReference latestSnapshot; + private final AtomicLong latestEntryCount = new AtomicLong(-1L); public ScopedStoreReader(DownloadCloudStorage fileStreamProvider, StoreScope scope, Parser parser, String dataTypeName) { this.metadataStreamProvider = fileStreamProvider; @@ -34,6 +38,11 @@ public ScopedStoreReader(DownloadCloudStorage fileStreamProvider, StoreScope sco this.contentStreamProvider = fileStreamProvider; } latestSnapshot = new AtomicReference<>(); + + Gauge.builder("uid2_scoped_store_entry_count", latestEntryCount::get) + .tag("store", dataTypeName) + .description("gauge for " + dataTypeName + " store total entry count") + .register(Metrics.globalRegistry); } public CloudPath getMetadataPath() { @@ -55,8 +64,15 @@ private long loadContent(String path) throws Exception { try (InputStream inputStream = this.contentStreamProvider.download(path)) { ParsingResult parsed = parser.deserialize(inputStream); latestSnapshot.set(parsed.getData()); - LOGGER.info(String.format("Loaded %d %s", parsed.getCount(), dataTypeName)); - return parsed.getCount(); + + final int count = parsed.getCount(); + latestEntryCount.set(count); + LOGGER.info(String.format("Loaded %d %s from %s", count, dataTypeName, path)); + return count; + } + catch (Exception e) { + LOGGER.error(String.format("Unable to load %s from %s", dataTypeName, path)); + throw e; } } diff --git a/src/main/java/com/uid2/shared/vertx/RotatingStoreVerticle.java b/src/main/java/com/uid2/shared/vertx/RotatingStoreVerticle.java index aa5f1bdc..c7c03511 100644 --- a/src/main/java/com/uid2/shared/vertx/RotatingStoreVerticle.java +++ b/src/main/java/com/uid2/shared/vertx/RotatingStoreVerticle.java @@ -39,22 +39,22 @@ public RotatingStoreVerticle(String storeName, long refreshIntervalMs, IMetadata this.counterStoreRefreshed = Counter .builder("uid2.config_store.refreshed") .tag("store", storeName) - .description("counter for how many times " + storeName + "store is refreshed") + .description("counter for how many times " + storeName + " store is refreshed") .register(Metrics.globalRegistry); this.counterStoreRefreshTimeMs = Counter .builder("uid2.config_store.refreshtime_ms") .tag("store", storeName) - .description("counter for total time (ms) " + storeName + "store spend in refreshing") + .description("counter for total time (ms) " + storeName + " store spend in refreshing") .register(Metrics.globalRegistry); this.gaugeStoreVersion = Gauge .builder("uid2.config_store.version", () -> this.latestVersion.get()) .tag("store", storeName) - .description("gauge for " + storeName + "store version") + .description("gauge for " + storeName + " store version") .register(Metrics.globalRegistry); this.gaugeStoreEntryCount = Gauge .builder("uid2.config_store.entry_count", () -> this.latestEntryCount.get()) .tag("store", storeName) - .description("gauge for " + storeName + "store total entry count") + .description("gauge for " + storeName + " store total entry count") .register(Metrics.globalRegistry); this.gaugeConsecutiveRefreshFailures = Gauge .builder("uid2.config_store.consecutive_refresh_failures", () -> this.storeRefreshIsFailing.get()) diff --git a/src/test/java/com/uid2/shared/store/RotatingServiceLinkStoreTest.java b/src/test/java/com/uid2/shared/store/RotatingServiceLinkStoreTest.java index bdc46120..d2dc7eac 100644 --- a/src/test/java/com/uid2/shared/store/RotatingServiceLinkStoreTest.java +++ b/src/test/java/com/uid2/shared/store/RotatingServiceLinkStoreTest.java @@ -64,9 +64,9 @@ public void loadContentEmptyArray() throws Exception { @Test public void loadContentMultipleServices() throws Exception { JsonArray content = new JsonArray(); - ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "AWS Venice"); + ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1"); ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1"); - ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "AWS Venice"); + ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1"); ServiceLink l4 = addServiceLink(content, "jkl1011", 3, 124, "test2"); when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content)); @@ -77,9 +77,9 @@ public void loadContentMultipleServices() throws Exception { @Test public void findServiceLinksMultipleServices() throws Exception { JsonArray content = new JsonArray(); - ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "AWS Venice"); + ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1"); ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1"); - ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "AWS Venice"); + ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1"); ServiceLink l4 = addServiceLink(content, "jkl1011", 3, 124, "test2"); when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content)); @@ -87,7 +87,7 @@ public void findServiceLinksMultipleServices() throws Exception { ServiceLink sl = serviceLinkStore.getServiceLink(1, "abc123"); assertNotNull(sl); - assertEquals("AWS Venice", sl.getName()); + assertEquals("Test Service 1", sl.getName()); assertEquals(1, sl.getServiceId()); assertEquals(123, sl.getSiteId()); assertEquals("abc123", sl.getLinkId()); diff --git a/src/test/java/com/uid2/shared/store/RotatingServiceStoreTest.java b/src/test/java/com/uid2/shared/store/RotatingServiceStoreTest.java index 3bacc35a..16cccb8a 100644 --- a/src/test/java/com/uid2/shared/store/RotatingServiceStoreTest.java +++ b/src/test/java/com/uid2/shared/store/RotatingServiceStoreTest.java @@ -66,9 +66,9 @@ public void loadContentEmptyArray() throws Exception { @Test public void loadContentMultipleServices() throws Exception { JsonArray content = new JsonArray(); - Service s1 = addService(content, 1, 123, "AWS Venice", Set.of()); + Service s1 = addService(content, 1, 123, "Test Service 1", Set.of()); Service s2 = addService(content, 2, 123, "test1", Set.of(Role.GENERATOR)); - Service s3 = addService(content, 3, 124, "AWS Venice", Set.of(Role.GENERATOR, Role.SHARING_PORTAL)); + Service s3 = addService(content, 3, 124, "Test Service 1", Set.of(Role.GENERATOR, Role.SHARING_PORTAL)); Service s4 = addService(content, 4, 125, "test2", Set.of(Role.CLIENTKEY_ISSUER)); when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));