Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add random errors in AdService #694

Merged
merged 11 commits into from
Jan 26, 2023
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,5 @@ significant modifications will be credited to OpenTelemetry Authors.
([#688](https://github.com/open-telemetry/opentelemetry-demo/pull/688))
* Update docker-compose services to restart unless stopped
([#690](https://github.com/open-telemetry/opentelemetry-demo/pull/690))
* Add logic to exercise error handling in AdService
([#694](https://github.com/open-telemetry/opentelemetry-demo/pull/694))
5 changes: 5 additions & 0 deletions src/adservice/src/main/java/hipstershop/AdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import hipstershop.Demo.AdResponse;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
import io.grpc.protobuf.services.*;
Expand Down Expand Up @@ -158,6 +159,10 @@ public void getAds(AdRequest req, StreamObserver<AdResponse> responseObserver) {

adRequestsCounter.add(1, Attributes.of(adRequestTypeKey, adRequestType.name(), adResponseTypeKey, adResponseType.name()));

if (random.nextInt(100) == 1) {
throw new StatusRuntimeException(Status.RESOURCE_EXHAUSTED);
}

AdResponse reply = AdResponse.newBuilder().addAllAds(allAds).build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
Expand Down