diff --git a/opentelemetry/config/krakend/krakend.json b/opentelemetry/config/krakend/krakend.json index 422b3b0..843460d 100644 --- a/opentelemetry/config/krakend/krakend.json +++ b/opentelemetry/config/krakend/krakend.json @@ -79,7 +79,11 @@ "input_query_strings": ["*"], "backend": [ { "url_pattern": "/customer.json" }, - { "url_pattern": "/sales.json" } + { "url_pattern": "/sales.json" }, + { + "host": ["http://localhost:8080"], + "url_pattern": "/__debug" + } ] }, { diff --git a/workflows/README.md b/workflows/README.md new file mode 100644 index 0000000..17f392b --- /dev/null +++ b/workflows/README.md @@ -0,0 +1,26 @@ +# Workflows example + +This example simulates a backend for frontend example for a streaming +platforme like could be NerdFilms, or Rainforest Top Video. + + +## Endpoints + +### `/home_dashboard` + +Is modeled as the initial screen that a customer would watch. + +The request can specify the `customer` and optionally the `profile`. +If the profile is not provided, it would request the default profile for +a given customer in a sequential workflow. + +We have three backends to request in parallel: + +- header +- customized content +- footer + +**Customized content** is a workflow, because if `profile` is not provided we want +to have sequential call that first fetches the default profile. Once we are +sure we have `profile` available, we can call another workflow that will +execute the fetch of customized content from different backends. diff --git a/workflows/config/fakehttpapi/config.json b/workflows/config/fakehttpapi/config.json new file mode 100644 index 0000000..cabb94b --- /dev/null +++ b/workflows/config/fakehttpapi/config.json @@ -0,0 +1,62 @@ +{ + "port": 8088, + "endpoints": [ + { + "method": "GET", + "path_pattern": "/timeouter/", + "behaviour": [ + { + "name": "delayer", + "config": { + "delay_millis_distribution": [ + {"key": 0, "val": 0.0}, + {"key": 600000, "val": 0.0}, + {"key": 900000, "val": 100.0} + ], + "seed": 1 + } + } + ], + "content": { + "source": "directory", + "config": { + "dir": "/etc/reqstatsrv/config/data", + "dunder_querystrings": true, + "attempt_extensions": [ + "json" + ] + } + } + }, + { + "method": "GET", + "path_pattern": "/regular/", + "behaviour": [], + "content": { + "source": "directory", + "config": { + "dir": "/etc/reqstatsrv/config/data", + "dunder_querystrings": true, + "attempt_extensions": [ + "json" + ] + } + } + }, + { + "method": "GET", + "path_pattern": "/", + "behaviour": [], + "content": { + "source": "directory", + "config": { + "dir": "/etc/reqstatsrv/config/data", + "dunder_querystrings": true, + "attempt_extensions": [ + "json" + ] + } + } + } + ] +} diff --git a/workflows/config/fakehttpapi/data/customer.json b/workflows/config/fakehttpapi/data/customer.json new file mode 100644 index 0000000..5d15bf7 --- /dev/null +++ b/workflows/config/fakehttpapi/data/customer.json @@ -0,0 +1,6 @@ +{ + "customer_id": "1", + "customer": { + "name": "Bard SingSong" + } +} diff --git a/workflows/config/fakehttpapi/data/default_profile.json b/workflows/config/fakehttpapi/data/default_profile.json new file mode 100644 index 0000000..385769c --- /dev/null +++ b/workflows/config/fakehttpapi/data/default_profile.json @@ -0,0 +1,6 @@ +{ + "profile": { + "name": "Bart Sink Son", + "profile_id": "xx" + } +} diff --git a/workflows/config/fakehttpapi/data/footer_promoted_movies.json b/workflows/config/fakehttpapi/data/footer_promoted_movies.json new file mode 100644 index 0000000..7043bab --- /dev/null +++ b/workflows/config/fakehttpapi/data/footer_promoted_movies.json @@ -0,0 +1,22 @@ +{ + "movies": [ + { + "title": "WarGames", + "genre": "Thriller", + "cast": [ + "Matthew Broderick", + "Ally Sheedy" + ], + "year": 1983 + }, + { + "title": "Tron", + "genre": "Action", + "cast": [ + "Jeff Bridges", + "Brucxe Boxleitner" + ], + "year": 1982 + } + ] +} diff --git a/workflows/config/fakehttpapi/data/header_banner.json b/workflows/config/fakehttpapi/data/header_banner.json new file mode 100644 index 0000000..4e55a1d --- /dev/null +++ b/workflows/config/fakehttpapi/data/header_banner.json @@ -0,0 +1,22 @@ +{ + "movies": [ + { + "title": "Sinners", + "genre": "Horror", + "cast": [ + "Michael B. Jordan", + "Miles Caton" + ], + "year": 2025 + }, + { + "title": "The Report", + "genre": "Drama", + "cast": [ + "Adam Driver", + "Annette Benning" + ], + "year": 2019 + } + ] +} diff --git a/workflows/config/fakehttpapi/data/pprofile_recommended_movies.json b/workflows/config/fakehttpapi/data/pprofile_recommended_movies.json new file mode 100644 index 0000000..efc57a6 --- /dev/null +++ b/workflows/config/fakehttpapi/data/pprofile_recommended_movies.json @@ -0,0 +1,24 @@ +{ + "movies": [ + { + "title": "Double Impact", + "genre": "Action", + "cast": [ + "Jean-Claude Van Damme", + "Alonna Shaw", + "Bolo Yeung" + ], + "year": 1991 + }, + { + "title": "Kickboxer", + "genre": "Action", + "cast": [ + "Jean-Claude Van Damme", + "Dennis Alexio", + "Rochelle Ashana" + ], + "year": 1989 + } + ] +} diff --git a/workflows/config/fakehttpapi/data/profile_recommended_actors.json b/workflows/config/fakehttpapi/data/profile_recommended_actors.json new file mode 100644 index 0000000..0ddd13c --- /dev/null +++ b/workflows/config/fakehttpapi/data/profile_recommended_actors.json @@ -0,0 +1,10 @@ +{ + "actors": [ + { + "name": "Jet Lee" + }, + { + "name": "Zhang Ziyi" + } + ] +} diff --git a/workflows/config/fakehttpapi/data/profile_recommended_movies__q_xx.json b/workflows/config/fakehttpapi/data/profile_recommended_movies__q_xx.json new file mode 100644 index 0000000..4d312c1 --- /dev/null +++ b/workflows/config/fakehttpapi/data/profile_recommended_movies__q_xx.json @@ -0,0 +1,24 @@ +{ + "movies": [ + { + "title": "XX", + "genre": "Action", + "cast": [ + "Jean-Claude Van Damme", + "Alonna Shaw", + "Bolo Yeung" + ], + "year": 1991 + }, + { + "title": "XX", + "genre": "Action", + "cast": [ + "Jean-Claude Van Damme", + "Dennis Alexio", + "Rochelle Ashana" + ], + "year": 1989 + } + ] +} diff --git a/workflows/config/fakehttpapi/data/profile_recommended_movies__q_yy.json b/workflows/config/fakehttpapi/data/profile_recommended_movies__q_yy.json new file mode 100644 index 0000000..efc57a6 --- /dev/null +++ b/workflows/config/fakehttpapi/data/profile_recommended_movies__q_yy.json @@ -0,0 +1,24 @@ +{ + "movies": [ + { + "title": "Double Impact", + "genre": "Action", + "cast": [ + "Jean-Claude Van Damme", + "Alonna Shaw", + "Bolo Yeung" + ], + "year": 1991 + }, + { + "title": "Kickboxer", + "genre": "Action", + "cast": [ + "Jean-Claude Van Damme", + "Dennis Alexio", + "Rochelle Ashana" + ], + "year": 1989 + } + ] +} diff --git a/workflows/config/fakehttpapi/data/recently_added.json b/workflows/config/fakehttpapi/data/recently_added.json new file mode 100644 index 0000000..51f357c --- /dev/null +++ b/workflows/config/fakehttpapi/data/recently_added.json @@ -0,0 +1,21 @@ +{ + "movies": [ + { + "title": "The Fantastic Four: First Steps", + "genre": "Action", + "cast": [ + "Pedro Pascal", + "Vanessa Kirby" + ], + "year": 2025 + }, + { + "title": "Billy Joel: And So It Goes", + "genre": "Documentary", + "cast": [ + "Billy Joel" + ], + "year": 2025 + } + ] +} diff --git a/workflows/config/fakehttpapi/data/sales.json b/workflows/config/fakehttpapi/data/sales.json new file mode 100644 index 0000000..3aef1c3 --- /dev/null +++ b/workflows/config/fakehttpapi/data/sales.json @@ -0,0 +1,6 @@ +{ + "sales": { + "lemonade": 23, + "cookies": 2 + } +} diff --git a/workflows/config/krakend/krakend.json b/workflows/config/krakend/krakend.json new file mode 100644 index 0000000..855c8ed --- /dev/null +++ b/workflows/config/krakend/krakend.json @@ -0,0 +1,113 @@ +{ + "$schema": "https://www.krakend.io/schema/v3.json", + "version": 3, + "name": "My first API Gateway - KrakenD", + "port": 8080, + "host": [ + "http://fakeapi:8088" + ], + "echo_endpoint": true, + "debug_endpoint": true, + "endpoints": [ + { + "endpoint": "/home_dashboard", + "input_headers": [ + "*" + ], + "input_query_strings": [ + "customer", + "profile" + ], + "backend": [ + { + "url_pattern": "/__workflow/customized_dashboard/", + "group": "custom_content", + "extra_config": { + "workflow": { + "endpoint": "/__workflow_impl/customized_dashboard/", + "input_query_strings": [ + "customer", + "profile" + ], + "ignore_errors": true, + "extra_config": { + "proxy": { + "sequential": true, + "sequential_propagated_params": [ + "resp0_profile" + ] + } + }, + "backend": [ + { + "host": [ + "http://localhost:8080" + ], + "url_pattern": "/__debug/workflow/" + }, + { + "url_pattern": "/__workflow/find_profile_id", + "extra_config": { + "workflow": { + "endpoint": "/__workflow_impl/find_profile_id", + "encoding": "no-op", + "ignore_errors": true, + "backend": [ + { + "url_pattern": "/default_profile", + "extra_config": { + "validation/cel": [ + { + "check_expr": "('profile' in req_querystring) == false || size(req_querystring.profile) == 0 || size(req_querystring.profile[0]) == 0" + } + ] + } + }, + { + "host": [ + "http://localhost:8080" + ], + "url_pattern": "/__debug/profile_from_query_param/", + "extra_config": { + "modifier/response-body-generator": { + "content_type": "application/json", + "debug": true, + "path": "./profile_id.tmpl" + } + } + } + ] + } + } + }, + { + "url_pattern": "/__workflow/for_profile_content/{resp0_profile.profile_id}", + "group": "recommended", + "extra_config": { + "workflow": { + "endpoint": "/__workflow_impl/for_profile_content/{resp0_profile.profile_id}", + "backend": [ + { + "host": [ + "http://localhost:8080" + ], + "url_pattern": "/__debug/{resp0_profile.profile_id}" + }, + { + "url_pattern": "/profile_recommended_movies?q={resp0_profile.profile_id}" + }, + { + "url_pattern": "/profile_recommended_actors" + } + ] + } + } + } + ] + } + } + } + ] + } + ] +} diff --git a/workflows/config/krakend/profile_id.tmpl b/workflows/config/krakend/profile_id.tmpl new file mode 100644 index 0000000..0223b6a --- /dev/null +++ b/workflows/config/krakend/profile_id.tmpl @@ -0,0 +1,7 @@ +{ + {{ if .req_querystring.profile }} + "profile": { + "profile_id": "{{index .req_querystring.profile 0}}" + } + {{ end }} +} diff --git a/workflows/docker-compose.yml b/workflows/docker-compose.yml new file mode 100644 index 0000000..7559f8b --- /dev/null +++ b/workflows/docker-compose.yml @@ -0,0 +1,18 @@ +services: + krakend_ee: + image: krakend/krakend-ee:2.10.3-watch + volumes: + - ./config/krakend:/etc/krakend + ports: + - "1234:1234" + - "8080:8080" + command: ["run", "-d", "-c", "krakend.json"] + fakeapi: + image: dhontecillas/reqstatsrv:v0.4 + ports: + - "8088:8088" + command: + - "/reqstatsrv" + - "/etc/reqstatsrv/config/config.json" + volumes: + - ./config/fakehttpapi:/etc/reqstatsrv/config