diff --git a/CHANGELOG.md b/CHANGELOG.md index 00c4f09336..181808a857 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,8 @@ the release. ([#1378](https://github.com/open-telemetry/opentelemetry-demo/pull/1378)) * [cartservice] update .NET to .NET 8.0.2 ([#1380](https://github.com/open-telemetry/opentelemetry-demo/pull/1380)) +* [productcatalogservice] Added Problems to ListProducts and GetProduct endpoints + ([#1382](https://github.com/open-telemetry/opentelemetry-demo/pull/1382)) ## 1.7.2 diff --git a/src/ffspostgres/init-scripts/20-ffs_data.sql b/src/ffspostgres/init-scripts/20-ffs_data.sql index 700e993236..4537342577 100644 --- a/src/ffspostgres/init-scripts/20-ffs_data.sql +++ b/src/ffspostgres/init-scripts/20-ffs_data.sql @@ -7,4 +7,6 @@ VALUES ('productCatalogFailure', 'Fail product catalog service on a specific product', 0), ('recommendationCache', 'Cache recommendations', 0), ('adServiceFailure', 'Fail ad service requests', 0), - ('cartServiceFailure', 'Fail cart service requests', 0); + ('cartServiceFailure', 'Fail cart service requests', 0), + ('itemNotFound', 'Fail Product Catalog Get - Not Found', 0), + ('itemListInternal', 'Fail Product Catalog List - Internal server error', 0); diff --git a/src/productcatalogservice/main.go b/src/productcatalogservice/main.go index 2f3d0d7f2d..79fd2e0739 100644 --- a/src/productcatalogservice/main.go +++ b/src/productcatalogservice/main.go @@ -217,6 +217,13 @@ func (p *productCatalog) Watch(req *healthpb.HealthCheckRequest, ws healthpb.Hea func (p *productCatalog) ListProducts(ctx context.Context, req *pb.Empty) (*pb.ListProductsResponse, error) { span := trace.SpanFromContext(ctx) + if p.getFeatureFlag(ctx, "itemListInternal") { + msg := fmt.Sprintf("itemListInternal flag enabled! List failed!") + span.SetStatus(otelcodes.Error, msg) + span.AddEvent(msg) + return nil, status.Errorf(codes.Internal, msg) + } + span.SetAttributes( attribute.Int("app.products.count", len(catalog)), ) @@ -237,6 +244,13 @@ func (p *productCatalog) GetProduct(ctx context.Context, req *pb.GetProductReque return nil, status.Errorf(codes.Internal, msg) } + if p.getFeatureFlag(ctx, "itemNotFound") { + msg := fmt.Sprintf("itemNotFound flag enabled! Product Not Found!") + span.SetStatus(otelcodes.Error, msg) + span.AddEvent(msg) + return nil, status.Errorf(codes.NotFound, msg) + } + var found *pb.Product for _, product := range catalog { if req.Id == product.Id { @@ -281,6 +295,11 @@ func (p *productCatalog) checkProductFailure(ctx context.Context, id string) boo return false } + return p.getFeatureFlag(ctx, "productCatalogFailure") +} + +func (p *productCatalog) getFeatureFlag(ctx context.Context, flagName string) bool { + conn, err := createClient(ctx, p.featureFlagSvcAddr) if err != nil { span := trace.SpanFromContext(ctx) @@ -289,7 +308,6 @@ func (p *productCatalog) checkProductFailure(ctx context.Context, id string) boo } defer conn.Close() - flagName := "productCatalogFailure" ffResponse, err := pb.NewFeatureFlagServiceClient(conn).GetFlag(ctx, &pb.GetFlagRequest{ Name: flagName, })