Skip to content

Commit

Permalink
rename adservice to ad
Browse files Browse the repository at this point in the history
  • Loading branch information
puckpuck committed Dec 14, 2024
1 parent 0edb6b5 commit ce335ca
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/ad/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ WORKDIR /usr/src/app/
COPY ./src/ad/gradlew* ./src/ad/settings.gradle* ./src/ad/build.gradle ./
COPY ./src/ad/gradle ./gradle

RUN chmod +x ./gradlew
RUN ./gradlew
RUN ./gradlew downloadRepos

COPY ./src/ad/ ./
COPY ./pb/ ./proto
RUN chmod +x ./gradlew
RUN ./gradlew installDist -PprotoSourceDir=./proto

# -----------------------------------------------------------------------------
Expand Down
20 changes: 10 additions & 10 deletions src/ad/src/main/java/oteldemo/AdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public final class AdService {
private HealthStatusManager healthMgr;

private static final AdService service = new AdService();
private static final Tracer tracer = GlobalOpenTelemetry.getTracer("adservice");
private static final Meter meter = GlobalOpenTelemetry.getMeter("adservice");
private static final Tracer tracer = GlobalOpenTelemetry.getTracer("ad");
private static final Meter meter = GlobalOpenTelemetry.getMeter("ad");

private static final LongCounter adRequestsCounter =
meter
Expand All @@ -80,7 +80,7 @@ private void start() throws IOException {
.orElseThrow(
() ->
new IllegalStateException(
"environment vars: AD_SERVICE_PORT must not be null")));
"environment vars: AD_PORT must not be null")));
healthMgr = new HealthStatusManager();

// Create a flagd instance with OpenTelemetry
Expand Down Expand Up @@ -132,9 +132,9 @@ private enum AdResponseType {

private static class AdServiceImpl extends oteldemo.AdServiceGrpc.AdServiceImplBase {

private static final String ADSERVICE_FAILURE = "adServiceFailure";
private static final String ADSERVICE_MANUAL_GC_FEATURE_FLAG = "adServiceManualGc";
private static final String ADSERVICE_HIGH_CPU_FEATURE_FLAG = "adServiceHighCpu";
private static final String AD_FAILURE = "adFailure";
private static final String AD_MANUAL_GC_FEATURE_FLAG = "adManualGc";
private static final String AD_HIGH_CPU_FEATURE_FLAG = "adHighCpu";
private static final Client ffClient = OpenFeatureAPI.getInstance().getClient();

private AdServiceImpl() {}
Expand Down Expand Up @@ -169,7 +169,7 @@ public void getAds(AdRequest req, StreamObserver<AdResponse> responseObserver) {
}

CPULoad cpuload = CPULoad.getInstance();
cpuload.execute(ffClient.getBooleanValue(ADSERVICE_HIGH_CPU_FEATURE_FLAG, false, evaluationContext));
cpuload.execute(ffClient.getBooleanValue(AD_HIGH_CPU_FEATURE_FLAG, false, evaluationContext));

span.setAttribute("app.ads.contextKeys", req.getContextKeysList().toString());
span.setAttribute("app.ads.contextKeys.count", req.getContextKeysCount());
Expand Down Expand Up @@ -202,12 +202,12 @@ public void getAds(AdRequest req, StreamObserver<AdResponse> responseObserver) {
adRequestTypeKey, adRequestType.name(), adResponseTypeKey, adResponseType.name()));

// Throw 1/10 of the time to simulate a failure when the feature flag is enabled
if (ffClient.getBooleanValue(ADSERVICE_FAILURE, false, evaluationContext) && random.nextInt(10) == 0) {
if (ffClient.getBooleanValue(AD_FAILURE, false, evaluationContext) && random.nextInt(10) == 0) {
throw new StatusRuntimeException(Status.UNAVAILABLE);
}

if (ffClient.getBooleanValue(ADSERVICE_MANUAL_GC_FEATURE_FLAG, false, evaluationContext)) {
logger.warn("Feature Flag " + ADSERVICE_MANUAL_GC_FEATURE_FLAG + " enabled, performing a manual gc now");
if (ffClient.getBooleanValue(AD_MANUAL_GC_FEATURE_FLAG, false, evaluationContext)) {
logger.warn("Feature Flag " + AD_MANUAL_GC_FEATURE_FLAG + " enabled, performing a manual gc now");
GarbageCollectionTrigger gct = new GarbageCollectionTrigger();
gct.doExecute();
}
Expand Down
6 changes: 3 additions & 3 deletions src/flagd/demo.flagd.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"defaultVariant": "off"
},
"adServiceManualGc": {
"adManualGc": {
"description": "Triggers full manual garbage collections in the ad service",
"state": "ENABLED",
"variants": {
Expand All @@ -28,7 +28,7 @@
},
"defaultVariant": "off"
},
"adServiceHighCpu": {
"adHighCpu": {
"description": "Triggers high cpu load in the ad service",
"state": "ENABLED",
"variants": {
Expand All @@ -37,7 +37,7 @@
},
"defaultVariant": "off"
},
"adServiceFailure": {
"adFailure": {
"description": "Fail ad service",
"state": "ENABLED",
"variants": {
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/gateways/rpc/Ad.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import { ChannelCredentials } from '@grpc/grpc-js';
import { AdResponse, AdServiceClient } from '../../protos/demo';

const { AD_SERVICE_ADDR = '' } = process.env;
const { AD_ADDR = '' } = process.env;

const client = new AdServiceClient(AD_SERVICE_ADDR, ChannelCredentials.createInsecure());
const client = new AdServiceClient(AD_ADDR, ChannelCredentials.createInsecure());

const AdGateway = () => ({
listAds(contextKeys: string[]) {
Expand Down

0 comments on commit ce335ca

Please sign in to comment.