|
1 | 1 | local helpers = require "spec.helpers" |
2 | 2 | local shell = require "resty.shell" |
3 | 3 | local pl_file = require "pl.file" |
| 4 | +local timeout = 10 |
| 5 | +local step = 1 |
4 | 6 |
|
5 | 7 | local UUID_PATTERN = "%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x" |
6 | 8 |
|
@@ -820,14 +822,16 @@ describe("Plugin: prometheus (access) AI metrics", function() |
820 | 822 | assert.res_status(200, res) |
821 | 823 |
|
822 | 824 | local body |
| 825 | + -- wait until the histogram observe finished and get the correct metrics. |
823 | 826 | helpers.wait_until(function() |
824 | 827 | local res = assert(admin_client:send { |
825 | 828 | method = "GET", |
826 | 829 | path = "/metrics", |
827 | 830 | }) |
828 | 831 | body = assert.res_status(200, res) |
829 | | - return res.status == 200 |
830 | | - end) |
| 832 | + return body:find('ai_llm_provider_latency_ms_bucket{ai_provider="openai",ai_model="gpt-3.5-turbo",cache_status="",vector_db="",embeddings_provider="",embeddings_model="",workspace="default",le="+Inf"} 1', |
| 833 | + nil, true) |
| 834 | + end, timeout, step) |
831 | 835 |
|
832 | 836 | assert.matches('kong_nginx_metric_errors_total 0', body, nil, true) |
833 | 837 | assert.matches('http_requests_total{service="empty_service",route="http-route",code="200",source="service",workspace="default",consumer=""} 2', body, nil, true) |
@@ -864,8 +868,9 @@ describe("Plugin: prometheus (access) AI metrics", function() |
864 | 868 | path = "/metrics", |
865 | 869 | }) |
866 | 870 | body = assert.res_status(200, res) |
867 | | - return res.status == 200 |
868 | | - end) |
| 871 | + return body:find('ai_llm_provider_latency_ms_bucket{ai_provider="openai",ai_model="gpt-3.5-turbo",cache_status="",vector_db="",embeddings_provider="",embeddings_model="",workspace="default",le="+Inf"} 2', |
| 872 | + nil, true) |
| 873 | + end, timeout, step) |
869 | 874 |
|
870 | 875 | assert.matches('kong_nginx_metric_errors_total 0', body, nil, true) |
871 | 876 | assert.matches('http_requests_total{service="empty_service",route="http-route",code="200",source="service",workspace="default",consumer=""} 3', body, nil, true) |
@@ -898,8 +903,9 @@ describe("Plugin: prometheus (access) AI metrics", function() |
898 | 903 | path = "/metrics", |
899 | 904 | }) |
900 | 905 | body = assert.res_status(200, res) |
901 | | - return res.status == 200 |
902 | | - end) |
| 906 | + return body:find('ai_llm_provider_latency_ms_bucket{ai_provider="openai",ai_model="gpt-3.5-turbo",cache_status="",vector_db="",embeddings_provider="",embeddings_model="",workspace="default",le="+Inf"} 2', |
| 907 | + nil, true) |
| 908 | + end, timeout, step) |
903 | 909 |
|
904 | 910 | assert.matches('http_requests_total{service="empty_service",route="http-route",code="400",source="kong",workspace="default",consumer=""} 1', body, nil, true) |
905 | 911 | assert.matches('kong_nginx_metric_errors_total 0', body, nil, true) |
|
0 commit comments