Skip to content

Commit

Permalink
Merge branch 'master' into zdu-UID2-1863-Change-UID2-Shard-for-opt-ou…
Browse files Browse the repository at this point in the history
…t-policy-check
  • Loading branch information
zaiweidu authored Sep 20, 2023
2 parents 3b2da5d + 2b60fc6 commit 8891494
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.uid2</groupId>
<artifactId>uid2-shared</artifactId>
<version>5.3.5-SNAPSHOT</version>
<version>5.3.6-e4c068510c</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Library for all the shared uid2 operations</description>
<url>https://github.com/IABTechLab/uid2docs</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OperatorKey> getAll() {
return operatorKeyStore.getAuthorizables();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

public interface IOperatorKeyProvider extends IAuthorizableProvider {
OperatorKey getOperatorKey(String token);
OperatorKey getOperatorKeyFromHash(String hash);
Collection<OperatorKey> getAll();
}
20 changes: 18 additions & 2 deletions src/main/java/com/uid2/shared/store/ScopedStoreReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
Expand All @@ -22,6 +25,7 @@ public class ScopedStoreReader<T> {
private final String dataTypeName;
private final DownloadCloudStorage contentStreamProvider;
private final AtomicReference<T> latestSnapshot;
private final AtomicLong latestEntryCount = new AtomicLong(-1L);

public ScopedStoreReader(DownloadCloudStorage fileStreamProvider, StoreScope scope, Parser<T> parser, String dataTypeName) {
this.metadataStreamProvider = fileStreamProvider;
Expand All @@ -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() {
Expand All @@ -55,8 +64,15 @@ private long loadContent(String path) throws Exception {
try (InputStream inputStream = this.contentStreamProvider.download(path)) {
ParsingResult<T> 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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -77,17 +77,17 @@ 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));

final long count = serviceLinkStore.loadContent(makeMetadata("locationPath"));

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 8891494

Please sign in to comment.