diff --git a/Makefile b/Makefile index 620b01b18c..55c83fb4fe 100644 --- a/Makefile +++ b/Makefile @@ -94,6 +94,10 @@ build-env-file: run-tests: docker compose run frontendTests docker compose run integrationTests + docker compose run traceBasedTests + +run-tracetesting: + docker compose run traceBasedTests .PHONY: generate-protobuf generate-protobuf: diff --git a/docker-compose.yml b/docker-compose.yml index d79b90d511..a54aacf0bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -714,10 +714,25 @@ services: - quoteservice # Tracebased Tests + traceBasedTests: + image: ${IMAGE_NAME}:${IMAGE_VERSION}-traceBasedTests + container_name: traceBasedTests + profiles: + - tests + build: + context: ./ + dockerfile: ./test/tracetesting/Dockerfile + extra_hosts: + - "host.docker.internal:host-gateway" + depends_on: + - tracetest-server + tracetest-server: image: kubeshop/tracetest:latest platform: linux/amd64 container_name: tracetest-server + profiles: + - tests volumes: - type: bind source: ./test/tracetesting/tracetest-config.yaml @@ -736,7 +751,7 @@ services: otelcol: condition: service_started # adding demo services as dependencies - accountingservice: + frontend: condition: service_started adservice: condition: service_started @@ -748,25 +763,16 @@ services: condition: service_started emailservice: condition: service_started - featureflagservice: - condition: service_started - frauddetectionservice: - condition: service_started - frontend: - condition: service_started - frontendproxy: - condition: service_started paymentservice: condition: service_started productcatalogservice: condition: service_started - quoteservice: - condition: service_started recommendationservice: condition: service_started shippingservice: condition: service_started - + quoteservice: + condition: service_started healthcheck: test: [ "CMD", "wget", "--spider", "localhost:11633" ] interval: 1s @@ -778,6 +784,8 @@ services: tracetest-postgres: image: postgres:14 container_name: tracetest-postgres + profiles: + - tests environment: POSTGRES_PASSWORD: postgres POSTGRES_USER: postgres diff --git a/test/test.js b/test/test.js index 0d6071a6cc..0fd07167f0 100644 --- a/test/test.js +++ b/test/test.js @@ -254,7 +254,7 @@ test("payment: expired credit card", (t) => { test("product: list", async (t) => { const res = await productList({}); - t.is(res.products.length, 9); + t.is(res.products.length, 10); }); test("product: get", async (t) => { @@ -283,7 +283,7 @@ test("recommendation: list products", async (t) => { const req = deepCopy(data.recommend); const res = await recommend(req); - t.is(res.productIds.length, 4); + t.is(res.productIds.length, 5); t.is(arrayIntersection(res.productIds, req.productIds).length, 0); }); diff --git a/test/tracetesting/Dockerfile b/test/tracetesting/Dockerfile new file mode 100644 index 0000000000..25be5eeec8 --- /dev/null +++ b/test/tracetesting/Dockerfile @@ -0,0 +1,14 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + + +FROM alpine + +WORKDIR /app + +RUN apk --update add bash jq curl +RUN curl -L https://raw.githubusercontent.com/kubeshop/tracetest/main/install-cli.sh | bash + +COPY ./test/tracetesting ./ + +CMD ["/bin/sh", "/app/run.bash"] diff --git a/test/tracetesting/cli-config.yml b/test/tracetesting/cli-config.yml index 3cdc56fe2d..9cd26732c7 100755 --- a/test/tracetesting/cli-config.yml +++ b/test/tracetesting/cli-config.yml @@ -2,5 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 scheme: http -endpoint: localhost:11633 +endpoint: tracetest-server:11633 analyticsEnabled: false diff --git a/test/tracetesting/run.bash b/test/tracetesting/run.bash index b73dadb508..c132e4ea82 100755 --- a/test/tracetesting/run.bash +++ b/test/tracetesting/run.bash @@ -41,6 +41,13 @@ run_tracetest ./tech-based-tests/payment-service/valid-credit-card.yaml || EXIT_ run_tracetest ./tech-based-tests/payment-service/invalid-credit-card.yaml || EXIT_STATUS=$? run_tracetest ./tech-based-tests/payment-service/amex-credit-card-not-allowed.yaml || EXIT_STATUS=$? run_tracetest ./tech-based-tests/payment-service/expired-credit-card.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/product-catalog-service/list.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/product-catalog-service/get.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/product-catalog-service/search.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/recommendation-service/list.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/shipping-service/quote.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/shipping-service/empty-quote.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/shipping-service/order.yaml || EXIT_STATUS=$? # run business tests echo "" diff --git a/test/tracetesting/tech-based-tests/cart-service/add-item-to-cart.yaml b/test/tracetesting/tech-based-tests/cart-service/add-item-to-cart.yaml index 280c252012..b5047f79e7 100644 --- a/test/tracetesting/tech-based-tests/cart-service/add-item-to-cart.yaml +++ b/test/tracetesting/tech-based-tests/cart-service/add-item-to-cart.yaml @@ -341,7 +341,7 @@ spec: } specs: - name: It added an item correctly into the shopping cart - selector: span[tracetest.span.type="rpc" name="oteldemo.CartService/AddItem" rpc.system="grpc" rpc.method="AddItem" rpc.service="oteldemo.CartService"] + selector: span[tracetest.span.type="http" name="oteldemo.CartService/AddItem" http.target="/oteldemo.CartService/AddItem" http.method="POST"] assertions: - attr:http.status_code = 200 - name: It set the cart item correctly on the database diff --git a/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-empty.yaml b/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-empty.yaml index b4027543f1..1ad2893264 100644 --- a/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-empty.yaml +++ b/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-empty.yaml @@ -337,7 +337,7 @@ spec: } specs: - name: It retrieved the cart items correctly - selector: span[tracetest.span.type="rpc" name="oteldemo.CartService/GetCart" rpc.system="grpc" rpc.method="GetCart" rpc.service="oteldemo.CartService"] + selector: span[tracetest.span.type="http" name="oteldemo.CartService/GetCart" http.target="/oteldemo.CartService/GetCart" http.method="POST"] assertions: - attr:http.status_code = 200 - name: It returned no items diff --git a/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-populated.yaml b/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-populated.yaml index ae69283b08..3b0b5eebb2 100644 --- a/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-populated.yaml +++ b/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-populated.yaml @@ -337,8 +337,7 @@ spec: } specs: - name: It retrieved the cart items correctly - selector: span[tracetest.span.type="http" name="oteldemo.CartService/GetCart" - http.target="/oteldemo.CartService/GetCart" http.method="POST"] + selector: span[tracetest.span.type="http" name="oteldemo.CartService/GetCart" http.target="/oteldemo.CartService/GetCart" http.method="POST"] assertions: - attr:http.status_code = 200 - name: It returned the first item with correct attributes diff --git a/test/tracetesting/tech-based-tests/cart-service/empty-cart.yaml b/test/tracetesting/tech-based-tests/cart-service/empty-cart.yaml index fcef14ee94..1ed67516e2 100644 --- a/test/tracetesting/tech-based-tests/cart-service/empty-cart.yaml +++ b/test/tracetesting/tech-based-tests/cart-service/empty-cart.yaml @@ -337,8 +337,7 @@ spec: } specs: - name: It emptied the shopping cart with success - selector: span[tracetest.span.type="http" name="oteldemo.CartService/EmptyCart" - http.target="/oteldemo.CartService/EmptyCart" http.method="POST"] + selector: span[tracetest.span.type="rpc" name="oteldemo.CartService/EmptyCart" rpc.system="grpc" rpc.method="EmptyCart" rpc.service="oteldemo.CartService"] assertions: - attr:rpc.grpc.status_code = 0 - name: It sent cleaning message to the database diff --git a/test/tracetesting/tech-based-tests/email-service/confirmation.yaml b/test/tracetesting/tech-based-tests/email-service/confirmation.yaml index c7f12aa004..def39e5776 100644 --- a/test/tracetesting/tech-based-tests/email-service/confirmation.yaml +++ b/test/tracetesting/tech-based-tests/email-service/confirmation.yaml @@ -14,7 +14,7 @@ spec: headers: - key: Content-Type value: application/json - body: | + body: |- { "email": "google@example.com", "order": { diff --git a/test/tracetesting/tech-based-tests/payment-service/amex-credit-card-not-allowed.yaml b/test/tracetesting/tech-based-tests/payment-service/amex-credit-card-not-allowed.yaml index 1e63ba6616..8716abfe29 100644 --- a/test/tracetesting/tech-based-tests/payment-service/amex-credit-card-not-allowed.yaml +++ b/test/tracetesting/tech-based-tests/payment-service/amex-credit-card-not-allowed.yaml @@ -347,12 +347,7 @@ spec: } specs: - name: It should call Charge method and receive a gRPC error - selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" - rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"] + selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"] assertions: - attr:rpc.grpc.status_code = 2 - - name: It should receive an invalid credit card message - selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" - rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"] - assertions: - attr:grpc.error_message = "Sorry, we cannot process amex credit cards. Only VISA or MasterCard is accepted." diff --git a/test/tracetesting/tech-based-tests/payment-service/expired-credit-card.yaml b/test/tracetesting/tech-based-tests/payment-service/expired-credit-card.yaml index 958518c479..7cbb5700d2 100644 --- a/test/tracetesting/tech-based-tests/payment-service/expired-credit-card.yaml +++ b/test/tracetesting/tech-based-tests/payment-service/expired-credit-card.yaml @@ -341,7 +341,7 @@ spec: "creditCard": { "creditCardNumber": "0000-0000-0000-0000", "creditCardCvv": 672, - "creditCardExpirationYear": 2039, + "creditCardExpirationYear": 2021, "creditCardExpirationMonth": 1 } } @@ -350,7 +350,4 @@ spec: selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"] assertions: - attr:rpc.grpc.status_code = 2 - - name: It should receive an invalid credit card message - selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"] - assertions: - attr:grpc.error_message = "The credit card (ending 0454) expired on 1/2021." diff --git a/test/tracetesting/tech-based-tests/payment-service/invalid-credit-card.yaml b/test/tracetesting/tech-based-tests/payment-service/invalid-credit-card.yaml index bb5e16e612..6ed9a0a98e 100644 --- a/test/tracetesting/tech-based-tests/payment-service/invalid-credit-card.yaml +++ b/test/tracetesting/tech-based-tests/payment-service/invalid-credit-card.yaml @@ -350,7 +350,4 @@ spec: selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"] assertions: - attr:rpc.grpc.status_code = 2 - - name: It should receive an invalid credit card message - selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"] - assertions: - attr:grpc.error_message = "Credit card info is invalid." diff --git a/test/tracetesting/tech-based-tests/payment-service/valid-credit-card.yaml b/test/tracetesting/tech-based-tests/payment-service/valid-credit-card.yaml index 5cd663c43f..0cbe1b94dd 100644 --- a/test/tracetesting/tech-based-tests/payment-service/valid-credit-card.yaml +++ b/test/tracetesting/tech-based-tests/payment-service/valid-credit-card.yaml @@ -341,7 +341,7 @@ spec: "creditCard": { "creditCardNumber": "4432-8015-6152-0454", "creditCardCvv": 672, - "creditCardExpirationYear": 2021, + "creditCardExpirationYear": 2039, "creditCardExpirationMonth": 1 } } @@ -353,4 +353,4 @@ spec: - name: It should return a transaction ID selector: span[tracetest.span.type="general" name="Tracetest trigger"] assertions: - - attr:tracetest.response.body| json_path '$.transactionId' != "" + - attr:tracetest.response.body | json_path '$.transactionId' != "" diff --git a/test/tracetesting/tech-based-tests/product-catalog-service/get.yaml b/test/tracetesting/tech-based-tests/product-catalog-service/get.yaml new file mode 100644 index 0000000000..20c9b7ad68 --- /dev/null +++ b/test/tracetesting/tech-based-tests/product-catalog-service/get.yaml @@ -0,0 +1,351 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: product-get + name: 'Product: Get' + description: Get a single product available on product catalog + trigger: + type: grpc + grpc: + protobufFile: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: productcatalogservice:3550 + method: oteldemo.ProductCatalogService.GetProduct + request: |- + { + "id": "OLJCESPC7Z" + } + specs: + - name: It queried the product catalog correctly for a specific product + selector: span[tracetest.span.type="rpc" name="oteldemo.ProductCatalogService/GetProduct" rpc.system="grpc" rpc.method="GetProduct" rpc.service="oteldemo.ProductCatalogService"] + assertions: + - attr:rpc.grpc.status_code = 0 + - attr:app.product.id = "OLJCESPC7Z" + - name: It returned a product with valid attributes + selector: span[tracetest.span.type="general" name="Tracetest trigger"] + assertions: + - attr:tracetest.response.body | json_path '$.id' = "OLJCESPC7Z" + - attr:tracetest.response.body | json_path '$.description' != "" + - attr:tracetest.response.body | json_path '$.picture' != "" + - attr:tracetest.response.body | json_path '$.priceUsd' != "{}" + - attr:tracetest.response.body | json_path '$.categories' != "[]" diff --git a/test/tracetesting/tech-based-tests/product-catalog-service/list.yaml b/test/tracetesting/tech-based-tests/product-catalog-service/list.yaml new file mode 100644 index 0000000000..f863121e04 --- /dev/null +++ b/test/tracetesting/tech-based-tests/product-catalog-service/list.yaml @@ -0,0 +1,345 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: product-list + name: 'Product: List' + description: List all products available on product catalog + trigger: + type: grpc + grpc: + protobufFile: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: productcatalogservice:3550 + method: oteldemo.ProductCatalogService.ListProducts + request: "" + specs: + - name: It queried the product catalog correctly + selector: span[tracetest.span.type="rpc" name="oteldemo.ProductCatalogService/ListProducts" + rpc.system="grpc" rpc.method="ListProducts" rpc.service="oteldemo.ProductCatalogService"] + assertions: + - attr:rpc.grpc.status_code = 0 + - attr:app.products.count = 10 + - name: It returned products with IDs + selector: span[tracetest.span.type="general" name="Tracetest trigger"] + assertions: + - attr:tracetest.response.body | json_path '$.products[*].id' != "" diff --git a/test/tracetesting/tech-based-tests/product-catalog-service/search.yaml b/test/tracetesting/tech-based-tests/product-catalog-service/search.yaml new file mode 100644 index 0000000000..3f88ed3354 --- /dev/null +++ b/test/tracetesting/tech-based-tests/product-catalog-service/search.yaml @@ -0,0 +1,347 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: product-search + name: 'Product: Search' + description: Search for products querying for their names + trigger: + type: grpc + grpc: + protobufFile: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: productcatalogservice:3550 + method: oteldemo.ProductCatalogService.SearchProducts + request: |- + { + "query": "Roof Binoculars" + } + specs: + - name: It called SearchProducts correctly and it returned 1 item + selector: span[tracetest.span.type="rpc" name="oteldemo.ProductCatalogService/SearchProducts" rpc.system="grpc" rpc.method="SearchProducts" rpc.service="oteldemo.ProductCatalogService"] + assertions: + - attr:app.products_search.count = 1 + - attr:rpc.grpc.status_code = 0 + - name: It returned the desired product + selector: span[tracetest.span.type="general" name="Tracetest trigger"] + assertions: + - attr:tracetest.response.body | json_path '$.results[0].name' = "Roof Binoculars" diff --git a/test/tracetesting/tech-based-tests/recommendation-service/list.yaml b/test/tracetesting/tech-based-tests/recommendation-service/list.yaml new file mode 100644 index 0000000000..d9a51af559 --- /dev/null +++ b/test/tracetesting/tech-based-tests/recommendation-service/list.yaml @@ -0,0 +1,345 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: recommendation-list + name: 'Recommendation: List products' + description: List all products recommended to an user + trigger: + type: grpc + grpc: + protobufFile: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: recommendationservice:9001 + method: oteldemo.RecommendationService.ListRecommendations + request: |- + { + "userId": "1234", + "productIds": [ "OLJCESPC7Z", "66VCHSJNUP", "1YMWWN1N4O", "L9ECAV7KIM", "2ZYFJ3GM2N" ] + } + specs: + - name: It called ListRecommendations correctly and got 5 products + selector: span[tracetest.span.type="rpc" name="/oteldemo.RecommendationService/ListRecommendations" + rpc.system="grpc" rpc.method="ListRecommendations" rpc.service="oteldemo.RecommendationService"] + assertions: + - attr:rpc.grpc.status_code = 0 + - attr:app.products_recommended.count = 5 diff --git a/test/tracetesting/tech-based-tests/shipping-service/empty-quote.yaml b/test/tracetesting/tech-based-tests/shipping-service/empty-quote.yaml new file mode 100644 index 0000000000..1d8dc7e2f8 --- /dev/null +++ b/test/tracetesting/tech-based-tests/shipping-service/empty-quote.yaml @@ -0,0 +1,355 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: shipping-empty-quote + name: 'Shipping: Empty Quote' + description: Quote delivery for no items + trigger: + type: grpc + grpc: + protobufFile: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: shippingservice:50050 + method: oteldemo.ShippingService.GetQuote + request: |- + { + "address": { + "streetAddress": "One Microsoft Way", + "city": "Redmond", + "state": "Washington", + "country": "United States", + "zipCode": "98052" + }, + "items": [] + } + specs: + - name: It called GetQuote correctly + selector: span[tracetest.span.type="rpc" name="oteldemo.ShippingService/GetQuote" rpc.system="grpc"] + assertions: + - attr:rpc.grpc.status_code = 0 + - name: It returned a valid quote + selector: span[tracetest.span.type="general" name="Tracetest trigger"] + assertions: + - attr:tracetest.response.body | json_path '$.costUsd.currencyCode' = "USD" + - attr:tracetest.response.body | json_path '$.costUsd.units' = 0 + - attr:tracetest.response.body | json_path '$.costUsd.nanos' = 0 \ No newline at end of file diff --git a/test/tracetesting/tech-based-tests/shipping-service/order.yaml b/test/tracetesting/tech-based-tests/shipping-service/order.yaml new file mode 100644 index 0000000000..c6405400b2 --- /dev/null +++ b/test/tracetesting/tech-based-tests/shipping-service/order.yaml @@ -0,0 +1,358 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: shipping-order + name: 'Shipping: Order' + description: Create one delivery order + trigger: + type: grpc + grpc: + protobufFile: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: shippingservice:50050 + method: oteldemo.ShippingService.ShipOrder + request: |- + { + "address": { + "streetAddress": "One Microsoft Way", + "city": "Redmond", + "state": "Washington", + "country": "United States", + "zipCode": "98052" + }, + "items": [ + { + "productId": "66VCHSJNUP", + "quantity": 2 + } + ] + } + specs: + - name: It called GetQuote correctly + selector: span[tracetest.span.type="rpc" name="oteldemo.ShippingService/ShipOrder" rpc.system="grpc"] + assertions: + - attr:rpc.grpc.status_code = 0 + - name: It returned a trackingId + selector: span[tracetest.span.type="general" name="Tracetest trigger"] + assertions: + - attr:tracetest.response.body | json_path '$.trackingId' != "" \ No newline at end of file diff --git a/test/tracetesting/tech-based-tests/shipping-service/quote.yaml b/test/tracetesting/tech-based-tests/shipping-service/quote.yaml new file mode 100644 index 0000000000..77be715f1f --- /dev/null +++ b/test/tracetesting/tech-based-tests/shipping-service/quote.yaml @@ -0,0 +1,360 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: shipping-quote + name: 'Shipping: Quote' + description: Quote delivery for one order + trigger: + type: grpc + grpc: + protobufFile: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: shippingservice:50050 + method: oteldemo.ShippingService.GetQuote + request: |- + { + "address": { + "streetAddress": "One Microsoft Way", + "city": "Redmond", + "state": "Washington", + "country": "United States", + "zipCode": "98052" + }, + "items": [ + { + "productId": "66VCHSJNUP", + "quantity": 2 + } + ] + } + specs: + - name: It called GetQuote correctly + selector: span[tracetest.span.type="rpc" name="oteldemo.ShippingService/GetQuote" rpc.system="grpc"] + assertions: + - attr:rpc.grpc.status_code = 0 + - name: It returned a valid quote + selector: span[tracetest.span.type="general" name="Tracetest trigger"] + assertions: + - attr:tracetest.response.body | json_path '$.costUsd.currencyCode' = "USD" + - attr:tracetest.response.body | json_path '$.costUsd.units' = 17 + - attr:tracetest.response.body | json_path '$.costUsd.nanos' = 800000000 \ No newline at end of file