From b3788a095d6cd59b8d02a70165fecefe534cc948 Mon Sep 17 00:00:00 2001 From: David Hontecillas Date: Thu, 10 Jul 2025 12:35:48 +0200 Subject: [PATCH 1/8] draft for a workflows example --- workflows/README.md | 16 +++++ workflows/config/fakehttpapi/config.json | 59 +++++++++++++++ .../config/fakehttpapi/data/customer.json | 6 ++ .../fakehttpapi/data/customized_content.json | 24 +++++++ .../fakehttpapi/data/default_profile.json | 6 ++ .../data/footer_promoted_movies.json | 22 ++++++ .../fakehttpapi/data/recently_added.json | 21 ++++++ workflows/config/fakehttpapi/data/sales.json | 6 ++ workflows/config/krakend/krakend.json | 71 +++++++++++++++++++ workflows/docker-compose.yml | 18 +++++ 10 files changed, 249 insertions(+) create mode 100644 workflows/README.md create mode 100644 workflows/config/fakehttpapi/config.json create mode 100644 workflows/config/fakehttpapi/data/customer.json create mode 100644 workflows/config/fakehttpapi/data/customized_content.json create mode 100644 workflows/config/fakehttpapi/data/default_profile.json create mode 100644 workflows/config/fakehttpapi/data/footer_promoted_movies.json create mode 100644 workflows/config/fakehttpapi/data/recently_added.json create mode 100644 workflows/config/fakehttpapi/data/sales.json create mode 100644 workflows/config/krakend/krakend.json create mode 100644 workflows/docker-compose.yml diff --git a/workflows/README.md b/workflows/README.md new file mode 100644 index 0000000..f364e35 --- /dev/null +++ b/workflows/README.md @@ -0,0 +1,16 @@ +# Workflows example + +This example simulates a backend for frontend example for a streaming +platforme like could be Nerdflix, or Rainforest Prime Video. + +A customer can have several profiles. + +## Endpoints + +### `/sequential_workflow` + +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. diff --git a/workflows/config/fakehttpapi/config.json b/workflows/config/fakehttpapi/config.json new file mode 100644 index 0000000..abd6d93 --- /dev/null +++ b/workflows/config/fakehttpapi/config.json @@ -0,0 +1,59 @@ +{ + "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", + "attempt_extensions": [ + "json" + ] + } + } + }, + { + "method": "GET", + "path_pattern": "/regular/", + "behaviour": [], + "content": { + "source": "directory", + "config": { + "dir": "/etc/reqstatsrv/config/data", + "attempt_extensions": [ + "json" + ] + } + } + }, + { + "method": "GET", + "path_pattern": "/", + "behaviour": [], + "content": { + "source": "directory", + "config": { + "dir": "/etc/reqstatsrv/config/data", + "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/customized_content.json b/workflows/config/fakehttpapi/data/customized_content.json new file mode 100644 index 0000000..efc57a6 --- /dev/null +++ b/workflows/config/fakehttpapi/data/customized_content.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/default_profile.json b/workflows/config/fakehttpapi/data/default_profile.json new file mode 100644 index 0000000..426892a --- /dev/null +++ b/workflows/config/fakehttpapi/data/default_profile.json @@ -0,0 +1,6 @@ +{ + "profile": { + "name": "Bart Sink Son", + "profile_id": "f2938a38" + } +} 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/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..b4e2841 --- /dev/null +++ b/workflows/config/krakend/krakend.json @@ -0,0 +1,71 @@ +{ + "$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": "/sequential_workflow", + "input_headers": ["*"], + "input_query_strings": [ + "customer", + "profile" + ], + "extra_config": { + "proxy": { + "sequential": true + } + }, + "backend": [ + { + "url_pattern": "/__workflow/streaming_dashboard", + "extra_config": { + "workflow": { + "endpoint": "/__workflow_impl/streaming_dashboard", + "ignore_errors": true, + "backend": [ + { + "url_pattern": "/recently_added.json", + "group": "recent" + }, + { + "url_pattern": "/__workflow/customized_content/", + "extra_config": { + "workflow": { + "endpoint": "/__workflow_impl/customized_content/", + "sequential": true, + "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" + } + ] + } + }, + { + "url_pattern": "/customized_content", + "group": "recommended" + } + ] + } + } + } + ] + } + } + }, + { + "url_pattern": "/footer_promoted_movies", + "group": "our_suggestions" + } + ] + } + ] +} diff --git a/workflows/docker-compose.yml b/workflows/docker-compose.yml new file mode 100644 index 0000000..fa41692 --- /dev/null +++ b/workflows/docker-compose.yml @@ -0,0 +1,18 @@ +services: + krakend_ee: + image: krakend/krakend-ee:2.10.3 + volumes: + - ./config/krakend:/etc/krakend + ports: + - "1234:1234" + - "8080:8080" + command: ["run", "-d", "-c", "krakend.json"] + fakeapi: + image: dhontecillas/reqstatsrv:v0.3 + ports: + - "8088:8088" + command: + - "/reqstatsrv" + - "/etc/reqstatsrv/config/config.json" + volumes: + - ./config/fakehttpapi:/etc/reqstatsrv/config From 45c20f2fa1a3e14d0b8c8526fde225c7d97e18c0 Mon Sep 17 00:00:00 2001 From: David Hontecillas Date: Mon, 14 Jul 2025 10:39:41 +0200 Subject: [PATCH 2/8] feat(workflows): add working example Added description in the workflow example README, and improved example config. --- workflows/README.md | 13 ++++- .../fakehttpapi/data/header_banner.json | 22 ++++++++ .../data/profile_recommended_actors.json | 10 ++++ ...t.json => profile_recommended_movies.json} | 0 workflows/config/krakend/krakend.json | 51 ++++++++++--------- workflows/docker-compose.yml | 4 +- 6 files changed, 73 insertions(+), 27 deletions(-) create mode 100644 workflows/config/fakehttpapi/data/header_banner.json create mode 100644 workflows/config/fakehttpapi/data/profile_recommended_actors.json rename workflows/config/fakehttpapi/data/{customized_content.json => profile_recommended_movies.json} (100%) diff --git a/workflows/README.md b/workflows/README.md index f364e35..a1366a5 100644 --- a/workflows/README.md +++ b/workflows/README.md @@ -7,10 +7,21 @@ A customer can have several profiles. ## Endpoints -### `/sequential_workflow` +### `/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/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/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/customized_content.json b/workflows/config/fakehttpapi/data/profile_recommended_movies.json similarity index 100% rename from workflows/config/fakehttpapi/data/customized_content.json rename to workflows/config/fakehttpapi/data/profile_recommended_movies.json diff --git a/workflows/config/krakend/krakend.json b/workflows/config/krakend/krakend.json index b4e2841..cba9e6f 100644 --- a/workflows/config/krakend/krakend.json +++ b/workflows/config/krakend/krakend.json @@ -8,50 +8,53 @@ "debug_endpoint": true, "endpoints": [ { - "endpoint": "/sequential_workflow", + "endpoint": "/home_dashboard", "input_headers": ["*"], "input_query_strings": [ "customer", "profile" ], - "extra_config": { - "proxy": { - "sequential": true - } - }, "backend": [ + { + "url_pattern": "/header_banner", + "group": "header" + }, { - "url_pattern": "/__workflow/streaming_dashboard", + "url_pattern": "/__workflow/customized_dashboard", + "group": "custom_content", "extra_config": { + "proxy": { + "sequential": true + }, "workflow": { - "endpoint": "/__workflow_impl/streaming_dashboard", + "endpoint": "/__workflow_impl/customized_dashboard", "ignore_errors": true, + "extra_config": { + "sequential": true + }, "backend": [ { - "url_pattern": "/recently_added.json", - "group": "recent" + "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" + } + ] + } }, { - "url_pattern": "/__workflow/customized_content/", + "url_pattern": "/__workflow/for_profile_content", + "group": "recommended", "extra_config": { "workflow": { - "endpoint": "/__workflow_impl/customized_content/", - "sequential": true, - "ignore_errors": true, + "endpoint": "/__workflow_impl/for_profile_content", "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" - } - ] - } + "url_pattern": "/profile_recommended_movies" }, { - "url_pattern": "/customized_content", - "group": "recommended" + "url_pattern": "/profile_recommended_actors" } ] } diff --git a/workflows/docker-compose.yml b/workflows/docker-compose.yml index fa41692..7559f8b 100644 --- a/workflows/docker-compose.yml +++ b/workflows/docker-compose.yml @@ -1,6 +1,6 @@ services: krakend_ee: - image: krakend/krakend-ee:2.10.3 + image: krakend/krakend-ee:2.10.3-watch volumes: - ./config/krakend:/etc/krakend ports: @@ -8,7 +8,7 @@ services: - "8080:8080" command: ["run", "-d", "-c", "krakend.json"] fakeapi: - image: dhontecillas/reqstatsrv:v0.3 + image: dhontecillas/reqstatsrv:v0.4 ports: - "8088:8088" command: From cea3f65ee365a0e40a190069dfde4fc273f2e86e Mon Sep 17 00:00:00 2001 From: David Hontecillas Date: Mon, 14 Jul 2025 14:41:05 +0200 Subject: [PATCH 3/8] update krakend.json for workflows --- workflows/config/krakend/krakend.json | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/workflows/config/krakend/krakend.json b/workflows/config/krakend/krakend.json index cba9e6f..c27513b 100644 --- a/workflows/config/krakend/krakend.json +++ b/workflows/config/krakend/krakend.json @@ -15,22 +15,15 @@ "profile" ], "backend": [ - { - "url_pattern": "/header_banner", - "group": "header" - }, { - "url_pattern": "/__workflow/customized_dashboard", + "url_pattern": "/__workflow/customized_dashboard/{req_querystring.profile}", "group": "custom_content", "extra_config": { - "proxy": { - "sequential": true - }, "workflow": { - "endpoint": "/__workflow_impl/customized_dashboard", + "endpoint": "/__workflow_impl/customized_dashboard/{req_querystring.profile}", "ignore_errors": true, "extra_config": { - "sequential": true + "proxy": { "sequential": true} }, "backend": [ { @@ -44,7 +37,7 @@ } }, { - "url_pattern": "/__workflow/for_profile_content", + "url_pattern": "/__workflow/for_profile_content/?q={resp0_profile.profile_id}", "group": "recommended", "extra_config": { "workflow": { @@ -63,10 +56,6 @@ ] } } - }, - { - "url_pattern": "/footer_promoted_movies", - "group": "our_suggestions" } ] } From e70ae2178f63e70c8bcfa79f4371642df61661ee Mon Sep 17 00:00:00 2001 From: David Hontecillas Date: Mon, 14 Jul 2025 15:10:32 +0200 Subject: [PATCH 4/8] workflow use resp0_param in a nested workflow --- workflows/config/krakend/krakend.json | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/workflows/config/krakend/krakend.json b/workflows/config/krakend/krakend.json index c27513b..d99cde8 100644 --- a/workflows/config/krakend/krakend.json +++ b/workflows/config/krakend/krakend.json @@ -16,14 +16,21 @@ ], "backend": [ { - "url_pattern": "/__workflow/customized_dashboard/{req_querystring.profile}", + "url_pattern": "/__workflow/customized_dashboard/", "group": "custom_content", "extra_config": { "workflow": { - "endpoint": "/__workflow_impl/customized_dashboard/{req_querystring.profile}", + "endpoint": "/__workflow_impl/customized_dashboard/", + "input_query_strings": [ + "customer", + "profile" + ], "ignore_errors": true, "extra_config": { - "proxy": { "sequential": true} + "proxy": { + "sequential": true, + "sequential_propagated_params": ["resp0_profile"] + } }, "backend": [ { @@ -37,14 +44,18 @@ } }, { - "url_pattern": "/__workflow/for_profile_content/?q={resp0_profile.profile_id}", + "url_pattern": "/__workflow/for_profile_content/{resp0_profile.profile_id}", "group": "recommended", "extra_config": { "workflow": { - "endpoint": "/__workflow_impl/for_profile_content", + "endpoint": "/__workflow_impl/for_profile_content/{resp0_profile.profile_id}", "backend": [ { - "url_pattern": "/profile_recommended_movies" + "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" From 079a3e285b48841e4ff7108b2f3ff3c604c2a6cd Mon Sep 17 00:00:00 2001 From: David Hontecillas Date: Mon, 14 Jul 2025 15:50:53 +0200 Subject: [PATCH 5/8] wip: only the resp0 part working --- workflows/config/fakehttpapi/config.json | 3 +++ .../fakehttpapi/data/default_profile.json | 2 +- ....json => pprofile_recommended_movies.json} | 0 .../profile_recommended_movies__q_xx.json | 24 +++++++++++++++++++ .../profile_recommended_movies__q_yy.json | 24 +++++++++++++++++++ workflows/config/krakend/krakend.json | 12 ++++++---- 6 files changed, 60 insertions(+), 5 deletions(-) rename workflows/config/fakehttpapi/data/{profile_recommended_movies.json => pprofile_recommended_movies.json} (100%) create mode 100644 workflows/config/fakehttpapi/data/profile_recommended_movies__q_xx.json create mode 100644 workflows/config/fakehttpapi/data/profile_recommended_movies__q_yy.json diff --git a/workflows/config/fakehttpapi/config.json b/workflows/config/fakehttpapi/config.json index abd6d93..cabb94b 100644 --- a/workflows/config/fakehttpapi/config.json +++ b/workflows/config/fakehttpapi/config.json @@ -21,6 +21,7 @@ "source": "directory", "config": { "dir": "/etc/reqstatsrv/config/data", + "dunder_querystrings": true, "attempt_extensions": [ "json" ] @@ -35,6 +36,7 @@ "source": "directory", "config": { "dir": "/etc/reqstatsrv/config/data", + "dunder_querystrings": true, "attempt_extensions": [ "json" ] @@ -49,6 +51,7 @@ "source": "directory", "config": { "dir": "/etc/reqstatsrv/config/data", + "dunder_querystrings": true, "attempt_extensions": [ "json" ] diff --git a/workflows/config/fakehttpapi/data/default_profile.json b/workflows/config/fakehttpapi/data/default_profile.json index 426892a..385769c 100644 --- a/workflows/config/fakehttpapi/data/default_profile.json +++ b/workflows/config/fakehttpapi/data/default_profile.json @@ -1,6 +1,6 @@ { "profile": { "name": "Bart Sink Son", - "profile_id": "f2938a38" + "profile_id": "xx" } } diff --git a/workflows/config/fakehttpapi/data/profile_recommended_movies.json b/workflows/config/fakehttpapi/data/pprofile_recommended_movies.json similarity index 100% rename from workflows/config/fakehttpapi/data/profile_recommended_movies.json rename to workflows/config/fakehttpapi/data/pprofile_recommended_movies.json 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/krakend/krakend.json b/workflows/config/krakend/krakend.json index d99cde8..afcd126 100644 --- a/workflows/config/krakend/krakend.json +++ b/workflows/config/krakend/krakend.json @@ -21,10 +21,10 @@ "extra_config": { "workflow": { "endpoint": "/__workflow_impl/customized_dashboard/", - "input_query_strings": [ - "customer", - "profile" - ], + "input_query_strings": [ + "customer", + "profile" + ], "ignore_errors": true, "extra_config": { "proxy": { @@ -33,6 +33,10 @@ } }, "backend": [ + { + "host": ["http://localhost:8080"], + "url_pattern": "/__debug/workflow/" + }, { "url_pattern": "/default_profile", "extra_config": { From 06523474a3763be6a2601370a99ed14c974d3b58 Mon Sep 17 00:00:00 2001 From: David Hontecillas Date: Mon, 14 Jul 2025 17:38:36 +0200 Subject: [PATCH 6/8] wip: attempt body generator to use query string profile as profile_id --- workflows/config/krakend/krakend.json | 35 ++++++++++++++++++++---- workflows/config/krakend/profile_id.tmpl | 7 +++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 workflows/config/krakend/profile_id.tmpl diff --git a/workflows/config/krakend/krakend.json b/workflows/config/krakend/krakend.json index afcd126..c7c4161 100644 --- a/workflows/config/krakend/krakend.json +++ b/workflows/config/krakend/krakend.json @@ -38,13 +38,36 @@ "url_pattern": "/__debug/workflow/" }, { - "url_pattern": "/default_profile", + "url_pattern": "/__workflow/find_profile_id", "extra_config": { - "validation/cel": [ - { - "check_expr": "('profile' in req_querystring) == false || size(req_querystring.profile) == 0 || size(req_querystring.profile[0]) == 0" - } - ] + "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" + } + } + } + ] + } } }, { 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 }} +} From ddf00444e5527cbd0bb2bfb287bf1e5428eadbf7 Mon Sep 17 00:00:00 2001 From: David Hontecillas Date: Thu, 31 Jul 2025 12:04:59 +0200 Subject: [PATCH 7/8] update workflows example to 2.10.2 --- opentelemetry/config/krakend/krakend.json | 6 +++++- workflows/docker-compose.yml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) 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/docker-compose.yml b/workflows/docker-compose.yml index 7559f8b..cd842a3 100644 --- a/workflows/docker-compose.yml +++ b/workflows/docker-compose.yml @@ -1,6 +1,6 @@ services: krakend_ee: - image: krakend/krakend-ee:2.10.3-watch + image: krakend/krakend-ee:2.10.2-watch volumes: - ./config/krakend:/etc/krakend ports: From 0b7c013ab9a0f881be1ee2e812011f1ca0760499 Mon Sep 17 00:00:00 2001 From: David Hontecillas Date: Thu, 31 Jul 2025 15:44:57 +0200 Subject: [PATCH 8/8] update workflows example to latest krakend version --- workflows/README.md | 3 +- workflows/config/krakend/krakend.json | 160 ++++++++++++++------------ workflows/docker-compose.yml | 2 +- 3 files changed, 88 insertions(+), 77 deletions(-) diff --git a/workflows/README.md b/workflows/README.md index a1366a5..17f392b 100644 --- a/workflows/README.md +++ b/workflows/README.md @@ -1,9 +1,8 @@ # Workflows example This example simulates a backend for frontend example for a streaming -platforme like could be Nerdflix, or Rainforest Prime Video. +platforme like could be NerdFilms, or Rainforest Top Video. -A customer can have several profiles. ## Endpoints diff --git a/workflows/config/krakend/krakend.json b/workflows/config/krakend/krakend.json index c7c4161..855c8ed 100644 --- a/workflows/config/krakend/krakend.json +++ b/workflows/config/krakend/krakend.json @@ -3,97 +3,109 @@ "version": 3, "name": "My first API Gateway - KrakenD", "port": 8080, - "host": ["http://fakeapi:8088"], + "host": [ + "http://fakeapi:8088" + ], "echo_endpoint": true, "debug_endpoint": true, "endpoints": [ { "endpoint": "/home_dashboard", - "input_headers": ["*"], + "input_headers": [ + "*" + ], "input_query_strings": [ - "customer", - "profile" + "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": [ + { + "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": [ { - "host": ["http://localhost:8080"], - "url_pattern": "/__debug/workflow/" + "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" + } + ] + } }, { - "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" - } - } - } - ] - } + "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": "/__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" - } - ] - } - } + "url_pattern": "/profile_recommended_movies?q={resp0_profile.profile_id}" + }, + { + "url_pattern": "/profile_recommended_actors" } - ] + ] + } + } } + ] } + } } ] } diff --git a/workflows/docker-compose.yml b/workflows/docker-compose.yml index cd842a3..7559f8b 100644 --- a/workflows/docker-compose.yml +++ b/workflows/docker-compose.yml @@ -1,6 +1,6 @@ services: krakend_ee: - image: krakend/krakend-ee:2.10.2-watch + image: krakend/krakend-ee:2.10.3-watch volumes: - ./config/krakend:/etc/krakend ports: