From 78cc834977f151d3be01315d9d574a0d027523b9 Mon Sep 17 00:00:00 2001 From: Adnan Rahic Date: Thu, 20 Jul 2023 12:53:03 +0200 Subject: [PATCH] blog(testing otel demo): format edits --- .../en/blog/2023/testing-otel-demo/index.md | 106 +++++++++--------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/content/en/blog/2023/testing-otel-demo/index.md b/content/en/blog/2023/testing-otel-demo/index.md index c8f9d96809cf..5c538091d4f9 100644 --- a/content/en/blog/2023/testing-otel-demo/index.md +++ b/content/en/blog/2023/testing-otel-demo/index.md @@ -36,9 +36,8 @@ greater confidence. Trace-based testing is a type of testing that validates a system's behavior by triggering an operation against the system and validating its result by checking -the system output with the emitted -[traces](/docs/concepts/signals/traces/) generated by the system during -this call. +the system output with the emitted [traces](/docs/concepts/signals/traces/) +generated by the system during this call. This term was popularized by Ted Young in the talk [Trace Driven Development: Unifying Testing and Observability](https://www.youtube.com/watch?v=NU-fTr-udZg) @@ -113,8 +112,8 @@ spec: trigger: type: grpc grpc: - protobufFile: {{protobuf file with CurrencyService definition}} - address: {{currency service address}} + protobufFile: {{ protobuf file with CurrencyService definition }} + address: {{ currency service address }} method: oteldemo.CurrencyService.Convert request: |- { @@ -126,16 +125,17 @@ spec: "toCode": "CAD" } specs: - - name: It converts from USD to CAD - selector: span[name="CurrencyService/Convert" rpc.system="grpc" - rpc.method="Convert" rpc.service="CurrencyService"] - assertions: - - attr:app.currency.conversion.from = "USD" - - attr:app.currency.conversion.to = "CAD" - - name: It has more nanos than expected - selector: span[name="Test trigger"] - assertions: - - attr:response.body | json_path '$.nanos' >= 599380800 + - name: It converts from USD to CAD + selector: + span[name="CurrencyService/Convert" rpc.system="grpc" + rpc.method="Convert" rpc.service="CurrencyService"] + assertions: + - attr:app.currency.conversion.from = "USD" + - attr:app.currency.conversion.to = "CAD" + - name: It has more nanos than expected + selector: span[name="Test trigger"] + assertions: + - attr:response.body | json_path '$.nanos' >= 599380800 ``` In the `trigger` section, we define which operation to trigger. In this case, a @@ -148,9 +148,9 @@ the trace and the operation result. We can see two types of assertions: - The first assertion is against a trace - [span](/docs/concepts/signals/traces/#spans) that the - `CurrencyService` emitted. It checks if the service received a conversion - operation from USD to CAD by checking if the + [span](/docs/concepts/signals/traces/#spans) that the `CurrencyService` + emitted. It checks if the service received a conversion operation from USD to + CAD by checking if the [span attributes](/docs/concepts/signals/traces/#attributes) `app.currency.conversion.from` and `app.currency.conversion.to` have correct values; @@ -164,8 +164,8 @@ The end-to-end tests are based on front-end tests using [Cypress](https://www.cypress.io/). We call the services through the API used by the front end and check if the service interaction between them is correct. We also verify if a trace is -[propagated](/docs/concepts/signals/traces/#context-propagation) -correctly through the services. +[propagated](/docs/concepts/signals/traces/#context-propagation) correctly +through the services. For these tests, we considered a scenario based on the main use case of the demo: “_a user buying a product_” executed against the @@ -191,7 +191,7 @@ type: Transaction spec: name: 'Frontend Service' description: Run all Frontend tests enabled in sequence, - simulating a process of a user purchasing products on the Astronomy store + simulating a process of a user purchasing products on the Astronomy store steps: - ./01-see-ads.yaml - ./02-get-product-recommendation.yaml @@ -250,8 +250,8 @@ spec: url: http://{{frontend address}}/api/checkout method: POST headers: - - key: Content-Type - value: application/json + - key: Content-Type + value: application/json body: | { "userId": "2491f868-88f1-4345-8836-d5d8511a9f83", @@ -272,34 +272,38 @@ spec: } } specs: - - name: "The frontend has been called with success" - selector: span[name="Test trigger"] - assertions: - - attr:response.status = 200 - - selector: span[name="oteldemo.CheckoutService/PlaceOrder" rpc.system="grpc" - rpc.method="PlaceOrder" rpc.service="oteldemo.CheckoutService"] - name: "The order was placed" - assertions: - - attr:app.user.id = "2491f868-88f1-4345-8836-d5d8511a9f83" - - attr:app.order.items.count = 1 - - selector: span[name="oteldemo.PaymentService/Charge" rpc.system="grpc" - rpc.method="Charge" rpc.service="oteldemo.PaymentService"] - name: "The user was charged" - assertions: - - attr:rpc.grpc.status_code = 0 - - attr:selected_spans.count >= 1 - - selector: span[name="oteldemo.ShippingService/ShipOrder" rpc.system="grpc" - rpc.method="ShipOrder" rpc.service="oteldemo.ShippingService"] - name: "The product was shipped" - assertions: - - attr:rpc.grpc.status_code = 0 - - attr:selected_spans.count >= 1 - - selector: span[name="oteldemo.CartService/EmptyCart" rpc.system="grpc" - rpc.method="EmptyCart" rpc.service="oteldemo.CartService"] - name: "The cart was emptied" - assertions: - - attr:rpc.grpc.status_code = 0 - - attr:selected_spans.count >= 1 + - name: 'The frontend has been called with success' + selector: span[name="Test trigger"] + assertions: + - attr:response.status = 200 + - selector: + span[name="oteldemo.CheckoutService/PlaceOrder" rpc.system="grpc" + rpc.method="PlaceOrder" rpc.service="oteldemo.CheckoutService"] + name: 'The order was placed' + assertions: + - attr:app.user.id = "2491f868-88f1-4345-8836-d5d8511a9f83" + - attr:app.order.items.count = 1 + - selector: + span[name="oteldemo.PaymentService/Charge" rpc.system="grpc" + rpc.method="Charge" rpc.service="oteldemo.PaymentService"] + name: 'The user was charged' + assertions: + - attr:rpc.grpc.status_code = 0 + - attr:selected_spans.count >= 1 + - selector: + span[name="oteldemo.ShippingService/ShipOrder" rpc.system="grpc" + rpc.method="ShipOrder" rpc.service="oteldemo.ShippingService"] + name: 'The product was shipped' + assertions: + - attr:rpc.grpc.status_code = 0 + - attr:selected_spans.count >= 1 + - selector: + span[name="oteldemo.CartService/EmptyCart" rpc.system="grpc" + rpc.method="EmptyCart" rpc.service="oteldemo.CartService"] + name: 'The cart was emptied' + assertions: + - attr:rpc.grpc.status_code = 0 + - attr:selected_spans.count >= 1 ``` Finally, when running these tests we have the following report, showing each