diff --git a/arch/envoy.template.yaml b/arch/envoy.template.yaml index 4c716e3a..14e26e84 100644 --- a/arch/envoy.template.yaml +++ b/arch/envoy.template.yaml @@ -115,26 +115,20 @@ static_resources: domains: - "*" routes: + + {% for internal_clustrer in ["embeddings", "zeroshot", "guard", "arch_fc", "hallucination"] %} - match: prefix: "/" headers: - name: "x-arch-upstream" string_match: - exact: model_server + exact: {{ internal_clustrer }} route: auto_host_rewrite: true - cluster: model_server - timeout: 60s - - match: - prefix: "/" - headers: - - name: "x-arch-upstream" - string_match: - exact: arch_fc - route: - auto_host_rewrite: true - cluster: model_server + cluster: {{ internal_clustrer }} timeout: 60s + {% endfor %} + {% for _, cluster in arch_clusters.items() %} - match: prefix: "/" @@ -278,13 +272,14 @@ static_resources: typed_config: "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext sni: api.mistral.ai - - name: model_server + {% for internal_clustrer in ["embeddings", "zeroshot", "guard", "arch_fc", "hallucination"] %} + - name: {{ internal_clustrer }} connect_timeout: 5s type: STRICT_DNS dns_lookup_family: V4_ONLY lb_policy: ROUND_ROBIN load_assignment: - cluster_name: model_server + cluster_name: {{ internal_clustrer }} endpoints: - lb_endpoints: - endpoint: @@ -292,7 +287,8 @@ static_resources: socket_address: address: host.docker.internal port_value: 51000 - hostname: "model_server" + hostname: {{ internal_clustrer }} + {% endfor %} - name: mistral_7b_instruct connect_timeout: 5s type: STRICT_DNS @@ -308,21 +304,6 @@ static_resources: address: mistral_7b_instruct port_value: 10001 hostname: "mistral_7b_instruct" - - name: arch_fc - connect_timeout: 5s - type: STRICT_DNS - dns_lookup_family: V4_ONLY - lb_policy: ROUND_ROBIN - load_assignment: - cluster_name: arch_fc - endpoints: - - lb_endpoints: - - endpoint: - address: - socket_address: - address: host.docker.internal - port_value: 51000 - hostname: "arch_fc" {% for _, cluster in arch_clusters.items() %} - name: {{ cluster.name }} {% if cluster.connect_timeout -%} diff --git a/crates/common/src/consts.rs b/crates/common/src/consts.rs index fdc21aed..fe67f6a8 100644 --- a/crates/common/src/consts.rs +++ b/crates/common/src/consts.rs @@ -8,9 +8,13 @@ pub const USER_ROLE: &str = "user"; pub const TOOL_ROLE: &str = "tool"; pub const ASSISTANT_ROLE: &str = "assistant"; pub const GPT_35_TURBO: &str = "gpt-3.5-turbo"; -pub const ARC_FC_CLUSTER: &str = "arch_fc"; pub const ARCH_FC_REQUEST_TIMEOUT_MS: u64 = 120000; // 2 minutes pub const MODEL_SERVER_NAME: &str = "model_server"; +pub const ZEROSHOT_INTERNAL_HOST: &str = "zeroshot"; +pub const ARCH_FC_INTERNAL_HOST: &str = "arch_fc"; +pub const HALLUCINATION_INTERNAL_HOST: &str = "hallucination"; +pub const EMBEDDINGS_INTERNAL_HOST: &str = "embeddings"; +pub const GUARD_INTERNAL_HOST: &str = "guard"; pub const ARCH_ROUTING_HEADER: &str = "x-arch-llm-provider"; pub const ARCH_MESSAGES_KEY: &str = "arch_messages"; pub const ARCH_PROVIDER_HINT_HEADER: &str = "x-arch-llm-provider-hint"; diff --git a/crates/prompt_gateway/src/filter_context.rs b/crates/prompt_gateway/src/filter_context.rs index 655b391f..b60191a5 100644 --- a/crates/prompt_gateway/src/filter_context.rs +++ b/crates/prompt_gateway/src/filter_context.rs @@ -1,10 +1,9 @@ use crate::stream_context::StreamContext; use common::common_types::EmbeddingType; +use common::consts::{ARCH_INTERNAL_CLUSTER_NAME, EMBEDDINGS_INTERNAL_HOST}; use common::configuration::{Configuration, Overrides, PromptGuards, PromptTarget}; -use common::consts::ARCH_INTERNAL_CLUSTER_NAME; use common::consts::ARCH_UPSTREAM_HOST_HEADER; use common::consts::DEFAULT_EMBEDDING_MODEL; -use common::consts::MODEL_SERVER_NAME; use common::embeddings::{ CreateEmbeddingRequest, CreateEmbeddingRequestInput, CreateEmbeddingResponse, }; @@ -100,10 +99,10 @@ impl FilterContext { ARCH_INTERNAL_CLUSTER_NAME, "/embeddings", vec![ - (ARCH_UPSTREAM_HOST_HEADER, MODEL_SERVER_NAME), + (ARCH_UPSTREAM_HOST_HEADER, EMBEDDINGS_INTERNAL_HOST), (":method", "POST"), (":path", "/embeddings"), - (":authority", MODEL_SERVER_NAME), + (":authority", EMBEDDINGS_INTERNAL_HOST), ("content-type", "application/json"), ("x-envoy-upstream-rq-timeout-ms", "60000"), ], diff --git a/crates/prompt_gateway/src/stream_context.rs b/crates/prompt_gateway/src/stream_context.rs index 18463b49..33938deb 100644 --- a/crates/prompt_gateway/src/stream_context.rs +++ b/crates/prompt_gateway/src/stream_context.rs @@ -12,11 +12,7 @@ use common::common_types::{ }; use common::configuration::{Overrides, PromptGuards, PromptTarget}; use common::consts::{ - ARCH_FC_MODEL_NAME, ARCH_FC_REQUEST_TIMEOUT_MS, ARCH_INTERNAL_CLUSTER_NAME, ARCH_MESSAGES_KEY, - ARCH_MODEL_PREFIX, ARCH_STATE_HEADER, ARCH_UPSTREAM_HOST_HEADER, ARC_FC_CLUSTER, - ASSISTANT_ROLE, CHAT_COMPLETIONS_PATH, DEFAULT_EMBEDDING_MODEL, DEFAULT_HALLUCINATED_THRESHOLD, - DEFAULT_INTENT_MODEL, DEFAULT_PROMPT_TARGET_THRESHOLD, GPT_35_TURBO, MODEL_SERVER_NAME, - REQUEST_ID_HEADER, SYSTEM_ROLE, TOOL_ROLE, USER_ROLE, + ARCH_FC_INTERNAL_HOST, ARCH_FC_MODEL_NAME, ARCH_FC_REQUEST_TIMEOUT_MS, ARCH_INTERNAL_CLUSTER_NAME, ARCH_MESSAGES_KEY, ARCH_MODEL_PREFIX, ARCH_STATE_HEADER, ARCH_UPSTREAM_HOST_HEADER, ASSISTANT_ROLE, CHAT_COMPLETIONS_PATH, DEFAULT_EMBEDDING_MODEL, DEFAULT_HALLUCINATED_THRESHOLD, DEFAULT_INTENT_MODEL, DEFAULT_PROMPT_TARGET_THRESHOLD, EMBEDDINGS_INTERNAL_HOST, GPT_35_TURBO, GUARD_INTERNAL_HOST, HALLUCINATION_INTERNAL_HOST, REQUEST_ID_HEADER, SYSTEM_ROLE, TOOL_ROLE, USER_ROLE, ZEROSHOT_INTERNAL_HOST }; use common::embeddings::{ CreateEmbeddingRequest, CreateEmbeddingRequestInput, CreateEmbeddingResponse, @@ -244,10 +240,10 @@ impl StreamContext { }; let mut headers = vec![ - (ARCH_UPSTREAM_HOST_HEADER, MODEL_SERVER_NAME), + (ARCH_UPSTREAM_HOST_HEADER, ZEROSHOT_INTERNAL_HOST), (":method", "POST"), (":path", "/zeroshot"), - (":authority", MODEL_SERVER_NAME), + (":authority", ZEROSHOT_INTERNAL_HOST), ("content-type", "application/json"), ("x-envoy-max-retries", "3"), ("x-envoy-upstream-rq-timeout-ms", "60000"), @@ -557,9 +553,9 @@ impl StreamContext { let mut headers = vec![ (":method", "POST"), - (ARCH_UPSTREAM_HOST_HEADER, ARC_FC_CLUSTER), + (ARCH_UPSTREAM_HOST_HEADER, ARCH_FC_INTERNAL_HOST), (":path", "/v1/chat/completions"), - (":authority", ARC_FC_CLUSTER), + (":authority", ARCH_FC_INTERNAL_HOST), ("content-type", "application/json"), ("x-envoy-max-retries", "3"), ("x-envoy-upstream-rq-timeout-ms", timeout_str.as_str()), @@ -713,10 +709,10 @@ impl StreamContext { }; let mut headers = vec![ - (ARCH_UPSTREAM_HOST_HEADER, MODEL_SERVER_NAME), + (ARCH_UPSTREAM_HOST_HEADER, HALLUCINATION_INTERNAL_HOST), (":method", "POST"), (":path", "/hallucination"), - (":authority", MODEL_SERVER_NAME), + (":authority", HALLUCINATION_INTERNAL_HOST), ("content-type", "application/json"), ("x-envoy-max-retries", "3"), ("x-envoy-upstream-rq-timeout-ms", "60000"), @@ -948,10 +944,10 @@ impl StreamContext { }; let mut headers = vec![ - (ARCH_UPSTREAM_HOST_HEADER, MODEL_SERVER_NAME), + (ARCH_UPSTREAM_HOST_HEADER, EMBEDDINGS_INTERNAL_HOST), (":method", "POST"), (":path", "/embeddings"), - (":authority", MODEL_SERVER_NAME), + (":authority", EMBEDDINGS_INTERNAL_HOST), ("content-type", "application/json"), ("x-envoy-max-retries", "3"), ("x-envoy-upstream-rq-timeout-ms", "60000"), @@ -1207,10 +1203,10 @@ impl HttpContext for StreamContext { }; let mut headers = vec![ - (ARCH_UPSTREAM_HOST_HEADER, MODEL_SERVER_NAME), + (ARCH_UPSTREAM_HOST_HEADER, GUARD_INTERNAL_HOST), (":method", "POST"), (":path", "/guard"), - (":authority", MODEL_SERVER_NAME), + (":authority", GUARD_INTERNAL_HOST), ("content-type", "application/json"), ("x-envoy-max-retries", "3"), ("x-envoy-upstream-rq-timeout-ms", "60000"), diff --git a/crates/prompt_gateway/tests/integration.rs b/crates/prompt_gateway/tests/integration.rs index 14ca1aa2..7f7322f8 100644 --- a/crates/prompt_gateway/tests/integration.rs +++ b/crates/prompt_gateway/tests/integration.rs @@ -78,10 +78,10 @@ fn normal_flow(module: &mut Tester, filter_context: i32, http_context: i32) { .expect_http_call( Some("arch_internal"), Some(vec![ - ("x-arch-upstream", "model_server"), + ("x-arch-upstream", "guard"), (":method", "POST"), (":path", "/guard"), - (":authority", "model_server"), + (":authority", "guard"), ("content-type", "application/json"), ("x-envoy-max-retries", "3"), ("x-envoy-upstream-rq-timeout-ms", "60000"), @@ -119,10 +119,10 @@ fn normal_flow(module: &mut Tester, filter_context: i32, http_context: i32) { .expect_http_call( Some("arch_internal"), Some(vec![ - ("x-arch-upstream", "model_server"), + ("x-arch-upstream", "embeddings"), (":method", "POST"), (":path", "/embeddings"), - (":authority", "model_server"), + (":authority", "embeddings"), ("content-type", "application/json"), ("x-envoy-max-retries", "3"), ("x-envoy-upstream-rq-timeout-ms", "60000"), @@ -164,10 +164,10 @@ fn normal_flow(module: &mut Tester, filter_context: i32, http_context: i32) { .expect_http_call( Some("arch_internal"), Some(vec![ - ("x-arch-upstream", "model_server"), + ("x-arch-upstream", "zeroshot"), (":method", "POST"), (":path", "/zeroshot"), - (":authority", "model_server"), + (":authority", "zeroshot"), ("content-type", "application/json"), ("x-envoy-max-retries", "3"), ("x-envoy-upstream-rq-timeout-ms", "60000"), @@ -249,10 +249,10 @@ fn setup_filter(module: &mut Tester, config: &str) -> i32 { .expect_http_call( Some("arch_internal"), Some(vec![ - ("x-arch-upstream", "model_server"), + ("x-arch-upstream", "embeddings"), (":method", "POST"), (":path", "/embeddings"), - (":authority", "model_server"), + (":authority", "embeddings"), ("content-type", "application/json"), ("x-envoy-upstream-rq-timeout-ms", "60000"), ]), @@ -568,10 +568,10 @@ fn request_to_llm_gateway() { .expect_http_call( Some("arch_internal"), Some(vec![ - ("x-arch-upstream", "model_server"), + ("x-arch-upstream", "hallucination"), (":method", "POST"), (":path", "/hallucination"), - (":authority", "model_server"), + (":authority", "hallucination"), ("content-type", "application/json"), ("x-envoy-max-retries", "3"), ("x-envoy-upstream-rq-timeout-ms", "60000"), diff --git a/demos/function_calling/grafana/dashboards/envoy_overview.json b/demos/function_calling/grafana/dashboards/envoy_overview.json index eca35419..3bb43a91 100644 --- a/demos/function_calling/grafana/dashboards/envoy_overview.json +++ b/demos/function_calling/grafana/dashboards/envoy_overview.json @@ -39,8 +39,8 @@ "axisPlacement": "auto", "barAlignment": 0, "barWidthFactor": 0.6, - "drawStyle": "line", - "fillOpacity": 0, + "drawStyle": "bars", + "fillOpacity": 54, "gradientMode": "none", "hideFrom": { "legend": false, @@ -58,7 +58,7 @@ "spanNulls": false, "stacking": { "group": "A", - "mode": "none" + "mode": "normal" }, "thresholdsStyle": { "mode": "off" @@ -79,32 +79,7 @@ ] } }, - "overrides": [ - { - "__systemRef": "hideSeriesFrom", - "matcher": { - "id": "byNames", - "options": { - "mode": "exclude", - "names": [ - "api_server" - ], - "prefix": "All except:", - "readOnly": true - } - }, - "properties": [ - { - "id": "custom.hideFrom", - "value": { - "legend": false, - "tooltip": false, - "viz": true - } - } - ] - } - ] + "overrides": [] }, "gridPos": { "h": 8, @@ -112,7 +87,7 @@ "x": 0, "y": 0 }, - "id": 3, + "id": 5, "options": { "legend": { "calcs": [], @@ -133,34 +108,18 @@ }, "disableTextWrap": false, "editorMode": "code", - "expr": "avg(rate(envoy_cluster_internal_upstream_rq_completed{envoy_cluster_name=~\"api_server|openai\"}[1m])) by (envoy_cluster_name)", - "fullMetaSearch": false, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "__auto", - "range": true, - "refId": "A", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "PBFA97CFB590B2093" - }, - "disableTextWrap": false, - "editorMode": "code", - "expr": "avg(rate(envoy_cluster_external_upstream_rq_completed{envoy_cluster_name=~\"api_server|openai\"}[1m])) by (envoy_cluster_name)", + "expr": "avg(rate(envoy_cluster_external_upstream_rq_time_sum{envoy_cluster_name=\"api_server\"}[1m]) / rate(envoy_cluster_external_upstream_rq_time_count[1m])) by (envoy_cluster_name)", "fullMetaSearch": false, "hide": false, "includeNullMetadata": true, "instant": false, "legendFormat": "__auto", "range": true, - "refId": "B", + "refId": "A", "useBackend": false } ], - "title": "Upstream request rate", + "title": "request latency - developer api server (ms)", "type": "timeseries" }, { @@ -230,7 +189,7 @@ "x": 12, "y": 0 }, - "id": 1, + "id": 4, "options": { "legend": { "calcs": [], @@ -251,7 +210,7 @@ }, "disableTextWrap": false, "editorMode": "code", - "expr": "avg(rate (envoy_cluster_external_upstream_rq_time_sum{envoy_cluster_name=~\"api_server|openai\"}[1m])/ rate(envoy_cluster_external_upstream_rq_time_count{envoy_cluster_name=~\"api_server|openai\"}[1m])) by (envoy_cluster_name)", + "expr": "avg(rate(envoy_cluster_external_upstream_rq_time_sum{envoy_cluster_name!=\"hallucination\", envoy_cluster_name!=\"zeroshot\", envoy_cluster_name!=\"embeddings\", envoy_cluster_name!=\"arch_fc\", envoy_cluster_name!=\"api_server\"}[1m]) / rate(envoy_cluster_external_upstream_rq_time_count[1m])) by (envoy_cluster_name)", "fullMetaSearch": false, "hide": false, "includeNullMetadata": true, @@ -274,7 +233,40 @@ "fieldConfig": { "defaults": { "color": { - "mode": "thresholds" + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "bars", + "fillOpacity": 54, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "thresholdsStyle": { + "mode": "off" + } }, "mappings": [], "thresholds": { @@ -299,25 +291,19 @@ "x": 0, "y": 8 }, - "id": 4, + "id": 1, "options": { - "colorMode": "value", - "graphMode": "area", - "justifyMode": "auto", - "orientation": "auto", - "percentChangeColorMode": "standard", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true }, - "showPercentChange": false, - "textMode": "auto", - "wideLayout": true + "tooltip": { + "mode": "single", + "sort": "none" + } }, - "pluginVersion": "11.2.0", "targets": [ { "datasource": { @@ -325,20 +311,20 @@ "uid": "PBFA97CFB590B2093" }, "disableTextWrap": false, - "editorMode": "builder", - "exemplar": false, - "expr": "envoy_cluster_upstream_rq_completed{envoy_cluster_name=~\"openai|api_server\"}", + "editorMode": "code", + "expr": "avg(rate(envoy_cluster_external_upstream_rq_time_sum{envoy_cluster_name!=\"openai\",envoy_cluster_name!=\"arch_llm_listener\",envoy_cluster_name!=\"api_server\"}[1m]) / rate(envoy_cluster_external_upstream_rq_time_count[1m])) by (envoy_cluster_name)", "fullMetaSearch": false, + "hide": false, "includeNullMetadata": true, - "instant": true, - "legendFormat": "{{envoy_cluster_name}}", - "range": false, + "instant": false, + "legendFormat": "__auto", + "range": true, "refId": "A", "useBackend": false } ], - "title": "# of Completd Requests", - "type": "stat" + "title": "request latency - internal arch services (ms)", + "type": "timeseries" }, { "datasource": { @@ -349,7 +335,40 @@ "fieldConfig": { "defaults": { "color": { - "mode": "thresholds" + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } }, "mappings": [], "thresholds": { @@ -371,28 +390,22 @@ "gridPos": { "h": 8, "w": 12, - "x": 12, - "y": 8 + "x": 0, + "y": 16 }, - "id": 5, + "id": 3, "options": { - "colorMode": "value", - "graphMode": "area", - "justifyMode": "auto", - "orientation": "auto", - "percentChangeColorMode": "standard", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true }, - "showPercentChange": false, - "textMode": "auto", - "wideLayout": true + "tooltip": { + "mode": "single", + "sort": "none" + } }, - "pluginVersion": "11.2.0", "targets": [ { "datasource": { @@ -400,23 +413,38 @@ "uid": "PBFA97CFB590B2093" }, "disableTextWrap": false, - "editorMode": "builder", - "exemplar": false, - "expr": "envoy_cluster_upstream_rq_cancelled{envoy_cluster_name=~\"api_server|openai\"} + envoy_cluster_upstream_rq_pending_failure_eject{envoy_cluster_name=~\"api_server|openai\"} + envoy_cluster_upstream_rq_pending_overflow{envoy_cluster_name=~\"api_server|openai\"}", + "editorMode": "code", + "expr": "avg(rate(envoy_cluster_internal_upstream_rq_completed{envoy_cluster_name !=\"opentelemetry_collector\"}[1m])) by (envoy_cluster_name)", "fullMetaSearch": false, "includeNullMetadata": true, - "instant": true, - "legendFormat": "{{envoy_cluster_name}}", - "range": false, + "instant": false, + "legendFormat": "__auto", + "range": true, "refId": "A", "useBackend": false + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "disableTextWrap": false, + "editorMode": "code", + "expr": "avg(rate(envoy_cluster_external_upstream_rq_completed{envoy_cluster_name !=\"opentelemetry_collector\"}[1m])) by (envoy_cluster_name)", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "B", + "useBackend": false } ], - "title": "# of Failed or Cancelled Requests", - "type": "stat" + "title": "Request count (per sec)", + "type": "timeseries" } ], - "refresh": "", "schemaVersion": 39, "tags": [], "templating": { @@ -428,8 +456,8 @@ }, "timepicker": {}, "timezone": "browser", - "title": "Arch Gateway Dashboard", + "title": "Intelligent Gateway Overview", "uid": "adt6uhx5lk8aob", - "version": 1, + "version": 14, "weekStart": "" }