palaryn 0.1.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +243 -588
- package/dist/sdk/typescript/src/client.js +2 -2
- package/dist/sdk/typescript/src/client.js.map +1 -1
- package/dist/src/anomaly/detector.d.ts +7 -4
- package/dist/src/anomaly/detector.d.ts.map +1 -1
- package/dist/src/anomaly/detector.js +22 -12
- package/dist/src/anomaly/detector.js.map +1 -1
- package/dist/src/audit/logger.d.ts +10 -0
- package/dist/src/audit/logger.d.ts.map +1 -1
- package/dist/src/audit/logger.js +52 -38
- package/dist/src/audit/logger.js.map +1 -1
- package/dist/src/auth/routes.d.ts.map +1 -1
- package/dist/src/auth/routes.js +35 -0
- package/dist/src/auth/routes.js.map +1 -1
- package/dist/src/budget/manager.d.ts +5 -0
- package/dist/src/budget/manager.d.ts.map +1 -1
- package/dist/src/budget/manager.js +32 -0
- package/dist/src/budget/manager.js.map +1 -1
- package/dist/src/budget/model-pricing.d.ts +20 -0
- package/dist/src/budget/model-pricing.d.ts.map +1 -0
- package/dist/src/budget/model-pricing.js +107 -0
- package/dist/src/budget/model-pricing.js.map +1 -0
- package/dist/src/budget/usage-extractor.d.ts +3 -1
- package/dist/src/budget/usage-extractor.d.ts.map +1 -1
- package/dist/src/budget/usage-extractor.js +47 -3
- package/dist/src/budget/usage-extractor.js.map +1 -1
- package/dist/src/config/defaults.d.ts.map +1 -1
- package/dist/src/config/defaults.js +65 -13
- package/dist/src/config/defaults.js.map +1 -1
- package/dist/src/dlp/tool-patterns.d.ts +7 -0
- package/dist/src/dlp/tool-patterns.d.ts.map +1 -0
- package/dist/src/dlp/tool-patterns.js +34 -0
- package/dist/src/dlp/tool-patterns.js.map +1 -0
- package/dist/src/executor/filesystem-executor.d.ts +28 -0
- package/dist/src/executor/filesystem-executor.d.ts.map +1 -0
- package/dist/src/executor/filesystem-executor.js +192 -0
- package/dist/src/executor/filesystem-executor.js.map +1 -0
- package/dist/src/executor/http-executor.d.ts.map +1 -1
- package/dist/src/executor/http-executor.js +22 -2
- package/dist/src/executor/http-executor.js.map +1 -1
- package/dist/src/executor/index.d.ts +4 -0
- package/dist/src/executor/index.d.ts.map +1 -1
- package/dist/src/executor/index.js +9 -1
- package/dist/src/executor/index.js.map +1 -1
- package/dist/src/executor/shell-executor.d.ts +22 -0
- package/dist/src/executor/shell-executor.d.ts.map +1 -0
- package/dist/src/executor/shell-executor.js +119 -0
- package/dist/src/executor/shell-executor.js.map +1 -0
- package/dist/src/executor/sql-executor.d.ts +29 -0
- package/dist/src/executor/sql-executor.d.ts.map +1 -0
- package/dist/src/executor/sql-executor.js +114 -0
- package/dist/src/executor/sql-executor.js.map +1 -0
- package/dist/src/executor/websocket-executor.d.ts +26 -0
- package/dist/src/executor/websocket-executor.d.ts.map +1 -0
- package/dist/src/executor/websocket-executor.js +205 -0
- package/dist/src/executor/websocket-executor.js.map +1 -0
- package/dist/src/interceptor/index.d.ts +2 -0
- package/dist/src/interceptor/index.d.ts.map +1 -0
- package/dist/src/interceptor/index.js +6 -0
- package/dist/src/interceptor/index.js.map +1 -0
- package/dist/src/interceptor/provider-interceptor.d.ts +36 -0
- package/dist/src/interceptor/provider-interceptor.d.ts.map +1 -0
- package/dist/src/interceptor/provider-interceptor.js +302 -0
- package/dist/src/interceptor/provider-interceptor.js.map +1 -0
- package/dist/src/mcp/auth-verifier.d.ts.map +1 -1
- package/dist/src/mcp/auth-verifier.js +3 -2
- package/dist/src/mcp/auth-verifier.js.map +1 -1
- package/dist/src/mcp/bridge.d.ts +14 -10
- package/dist/src/mcp/bridge.d.ts.map +1 -1
- package/dist/src/mcp/bridge.js +51 -227
- package/dist/src/mcp/bridge.js.map +1 -1
- package/dist/src/mcp/http-transport.d.ts +2 -0
- package/dist/src/mcp/http-transport.d.ts.map +1 -1
- package/dist/src/mcp/http-transport.js +117 -66
- package/dist/src/mcp/http-transport.js.map +1 -1
- package/dist/src/mcp/internal-auth.d.ts +13 -0
- package/dist/src/mcp/internal-auth.d.ts.map +1 -0
- package/dist/src/mcp/internal-auth.js +12 -0
- package/dist/src/mcp/internal-auth.js.map +1 -0
- package/dist/src/mcp/tool-definitions.d.ts +41 -0
- package/dist/src/mcp/tool-definitions.d.ts.map +1 -0
- package/dist/src/mcp/tool-definitions.js +491 -0
- package/dist/src/mcp/tool-definitions.js.map +1 -0
- package/dist/src/middleware/auth.js.map +1 -1
- package/dist/src/middleware/session.js.map +1 -1
- package/dist/src/middleware/validate.d.ts +8 -0
- package/dist/src/middleware/validate.d.ts.map +1 -1
- package/dist/src/middleware/validate.js +45 -0
- package/dist/src/middleware/validate.js.map +1 -1
- package/dist/src/policy/engine.d.ts +4 -0
- package/dist/src/policy/engine.d.ts.map +1 -1
- package/dist/src/policy/engine.js +117 -0
- package/dist/src/policy/engine.js.map +1 -1
- package/dist/src/saas/routes.d.ts.map +1 -1
- package/dist/src/saas/routes.js +355 -22
- package/dist/src/saas/routes.js.map +1 -1
- package/dist/src/server/app.d.ts.map +1 -1
- package/dist/src/server/app.js +24 -3
- package/dist/src/server/app.js.map +1 -1
- package/dist/src/server/gateway.d.ts.map +1 -1
- package/dist/src/server/gateway.js +17 -0
- package/dist/src/server/gateway.js.map +1 -1
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +18 -0
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/storage/interfaces.d.ts +14 -3
- package/dist/src/storage/interfaces.d.ts.map +1 -1
- package/dist/src/storage/memory.d.ts +2 -0
- package/dist/src/storage/memory.d.ts.map +1 -1
- package/dist/src/storage/memory.js +6 -0
- package/dist/src/storage/memory.js.map +1 -1
- package/dist/src/storage/postgres.d.ts +5 -0
- package/dist/src/storage/postgres.d.ts.map +1 -1
- package/dist/src/storage/postgres.js +16 -0
- package/dist/src/storage/postgres.js.map +1 -1
- package/dist/src/storage/redis.d.ts +10 -0
- package/dist/src/storage/redis.d.ts.map +1 -1
- package/dist/src/storage/redis.js +65 -0
- package/dist/src/storage/redis.js.map +1 -1
- package/dist/src/types/budget.d.ts +4 -0
- package/dist/src/types/budget.d.ts.map +1 -1
- package/dist/src/types/config.d.ts +58 -0
- package/dist/src/types/config.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +1 -0
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/policy.d.ts +11 -1
- package/dist/src/types/policy.d.ts.map +1 -1
- package/dist/src/types/tool-result.d.ts +11 -0
- package/dist/src/types/tool-result.d.ts.map +1 -1
- package/dist/tests/unit/app-routes.test.d.ts +2 -0
- package/dist/tests/unit/app-routes.test.d.ts.map +1 -0
- package/dist/tests/unit/app-routes.test.js +715 -0
- package/dist/tests/unit/app-routes.test.js.map +1 -0
- package/dist/tests/unit/audit-logger.test.js +105 -0
- package/dist/tests/unit/audit-logger.test.js.map +1 -1
- package/dist/tests/unit/auth-providers.test.d.ts +2 -0
- package/dist/tests/unit/auth-providers.test.d.ts.map +1 -0
- package/dist/tests/unit/auth-providers.test.js +279 -0
- package/dist/tests/unit/auth-providers.test.js.map +1 -0
- package/dist/tests/unit/auth-routes-extended.test.d.ts +2 -0
- package/dist/tests/unit/auth-routes-extended.test.d.ts.map +1 -0
- package/dist/tests/unit/auth-routes-extended.test.js +993 -0
- package/dist/tests/unit/auth-routes-extended.test.js.map +1 -0
- package/dist/tests/unit/auth-verifier.test.d.ts +2 -0
- package/dist/tests/unit/auth-verifier.test.d.ts.map +1 -0
- package/dist/tests/unit/auth-verifier.test.js +505 -0
- package/dist/tests/unit/auth-verifier.test.js.map +1 -0
- package/dist/tests/unit/billing-routes.test.d.ts +2 -0
- package/dist/tests/unit/billing-routes.test.d.ts.map +1 -0
- package/dist/tests/unit/billing-routes.test.js +432 -0
- package/dist/tests/unit/billing-routes.test.js.map +1 -0
- package/dist/tests/unit/config-defaults.test.d.ts +2 -0
- package/dist/tests/unit/config-defaults.test.d.ts.map +1 -0
- package/dist/tests/unit/config-defaults.test.js +119 -0
- package/dist/tests/unit/config-defaults.test.js.map +1 -0
- package/dist/tests/unit/defaults.test.js +0 -10
- package/dist/tests/unit/defaults.test.js.map +1 -1
- package/dist/tests/unit/filesystem-executor.test.d.ts +2 -0
- package/dist/tests/unit/filesystem-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/filesystem-executor.test.js +280 -0
- package/dist/tests/unit/filesystem-executor.test.js.map +1 -0
- package/dist/tests/unit/gateway-branches.test.d.ts +2 -0
- package/dist/tests/unit/gateway-branches.test.d.ts.map +1 -0
- package/dist/tests/unit/gateway-branches.test.js +1039 -0
- package/dist/tests/unit/gateway-branches.test.js.map +1 -0
- package/dist/tests/unit/http-executor-branches.test.d.ts +2 -0
- package/dist/tests/unit/http-executor-branches.test.d.ts.map +1 -0
- package/dist/tests/unit/http-executor-branches.test.js +495 -0
- package/dist/tests/unit/http-executor-branches.test.js.map +1 -0
- package/dist/tests/unit/logger.test.d.ts +2 -0
- package/dist/tests/unit/logger.test.d.ts.map +1 -0
- package/dist/tests/unit/logger.test.js +97 -0
- package/dist/tests/unit/logger.test.js.map +1 -0
- package/dist/tests/unit/mcp-internal-auth.test.d.ts +2 -0
- package/dist/tests/unit/mcp-internal-auth.test.d.ts.map +1 -0
- package/dist/tests/unit/mcp-internal-auth.test.js +445 -0
- package/dist/tests/unit/mcp-internal-auth.test.js.map +1 -0
- package/dist/tests/unit/metrics.test.js +102 -0
- package/dist/tests/unit/metrics.test.js.map +1 -1
- package/dist/tests/unit/model-pricing.test.d.ts +2 -0
- package/dist/tests/unit/model-pricing.test.d.ts.map +1 -0
- package/dist/tests/unit/model-pricing.test.js +87 -0
- package/dist/tests/unit/model-pricing.test.js.map +1 -0
- package/dist/tests/unit/oauth-stores.test.d.ts +2 -0
- package/dist/tests/unit/oauth-stores.test.d.ts.map +1 -0
- package/dist/tests/unit/oauth-stores.test.js +260 -0
- package/dist/tests/unit/oauth-stores.test.js.map +1 -0
- package/dist/tests/unit/policy-engine.test.js +466 -0
- package/dist/tests/unit/policy-engine.test.js.map +1 -1
- package/dist/tests/unit/provider-interceptor.test.d.ts +2 -0
- package/dist/tests/unit/provider-interceptor.test.d.ts.map +1 -0
- package/dist/tests/unit/provider-interceptor.test.js +472 -0
- package/dist/tests/unit/provider-interceptor.test.js.map +1 -0
- package/dist/tests/unit/saas-routes-branches.test.d.ts +2 -0
- package/dist/tests/unit/saas-routes-branches.test.d.ts.map +1 -0
- package/dist/tests/unit/saas-routes-branches.test.js +2165 -0
- package/dist/tests/unit/saas-routes-branches.test.js.map +1 -0
- package/dist/tests/unit/saas-routes-crud.test.d.ts +2 -0
- package/dist/tests/unit/saas-routes-crud.test.d.ts.map +1 -0
- package/dist/tests/unit/saas-routes-crud.test.js +332 -0
- package/dist/tests/unit/saas-routes-crud.test.js.map +1 -0
- package/dist/tests/unit/saas-routes-data.test.d.ts +2 -0
- package/dist/tests/unit/saas-routes-data.test.d.ts.map +1 -0
- package/dist/tests/unit/saas-routes-data.test.js +405 -0
- package/dist/tests/unit/saas-routes-data.test.js.map +1 -0
- package/dist/tests/unit/saas-routes.test.js +3 -3
- package/dist/tests/unit/saas-routes.test.js.map +1 -1
- package/dist/tests/unit/shell-executor.test.d.ts +2 -0
- package/dist/tests/unit/shell-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/shell-executor.test.js +145 -0
- package/dist/tests/unit/shell-executor.test.js.map +1 -0
- package/dist/tests/unit/sql-executor.test.d.ts +2 -0
- package/dist/tests/unit/sql-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/sql-executor.test.js +177 -0
- package/dist/tests/unit/sql-executor.test.js.map +1 -0
- package/dist/tests/unit/stream-proxy.test.d.ts +2 -0
- package/dist/tests/unit/stream-proxy.test.d.ts.map +1 -0
- package/dist/tests/unit/stream-proxy.test.js +147 -0
- package/dist/tests/unit/stream-proxy.test.js.map +1 -0
- package/dist/tests/unit/tool-definitions.test.d.ts +2 -0
- package/dist/tests/unit/tool-definitions.test.d.ts.map +1 -0
- package/dist/tests/unit/tool-definitions.test.js +184 -0
- package/dist/tests/unit/tool-definitions.test.js.map +1 -0
- package/dist/tests/unit/usage-extractor.test.js +140 -0
- package/dist/tests/unit/usage-extractor.test.js.map +1 -1
- package/dist/tests/unit/webhook-handler.test.d.ts +2 -0
- package/dist/tests/unit/webhook-handler.test.d.ts.map +1 -0
- package/dist/tests/unit/webhook-handler.test.js +453 -0
- package/dist/tests/unit/webhook-handler.test.js.map +1 -0
- package/dist/tests/unit/webhook-routes.test.d.ts +2 -0
- package/dist/tests/unit/webhook-routes.test.d.ts.map +1 -0
- package/dist/tests/unit/webhook-routes.test.js +69 -0
- package/dist/tests/unit/webhook-routes.test.js.map +1 -0
- package/dist/tests/unit/websocket-executor.test.d.ts +2 -0
- package/dist/tests/unit/websocket-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/websocket-executor.test.js +121 -0
- package/dist/tests/unit/websocket-executor.test.js.map +1 -0
- package/package.json +8 -2
- package/policy-packs/demo_fail.yaml +41 -0
- package/policy-packs/full_tools.yaml +136 -0
- package/src/admin/index.ts +1 -0
- package/src/admin/routes.ts +509 -0
- package/src/admin/templates.ts +572 -0
- package/src/anomaly/detector.ts +730 -0
- package/src/anomaly/index.ts +1 -0
- package/src/approval/manager.ts +569 -0
- package/src/approval/webhook.ts +133 -0
- package/src/audit/logger.ts +490 -0
- package/src/auth/index.ts +5 -0
- package/src/auth/password.ts +21 -0
- package/src/auth/pkce.ts +22 -0
- package/src/auth/providers.ts +208 -0
- package/src/auth/routes.ts +561 -0
- package/src/auth/session.ts +84 -0
- package/src/billing/index.ts +6 -0
- package/src/billing/plan-enforcer.ts +135 -0
- package/src/billing/routes.ts +229 -0
- package/src/billing/stripe-client.ts +58 -0
- package/src/billing/webhook-handler.ts +182 -0
- package/src/billing/webhook-routes.ts +28 -0
- package/src/budget/manager.ts +679 -0
- package/src/budget/model-pricing.ts +119 -0
- package/src/budget/usage-extractor.ts +214 -0
- package/src/cli.ts +91 -0
- package/src/config/defaults.ts +261 -0
- package/src/config/validate.ts +88 -0
- package/src/dlp/composite-scanner.ts +213 -0
- package/src/dlp/index.ts +9 -0
- package/src/dlp/interfaces.ts +34 -0
- package/src/dlp/patterns.ts +30 -0
- package/src/dlp/prompt-injection-backend.ts +181 -0
- package/src/dlp/prompt-injection-patterns.ts +302 -0
- package/src/dlp/regex-backend.ts +181 -0
- package/src/dlp/scanner.ts +502 -0
- package/src/dlp/text-normalizer.ts +225 -0
- package/src/dlp/tool-patterns.ts +35 -0
- package/src/dlp/trufflehog-backend.ts +190 -0
- package/src/executor/filesystem-executor.ts +196 -0
- package/src/executor/http-executor.ts +349 -0
- package/src/executor/index.ts +9 -0
- package/src/executor/interfaces.ts +11 -0
- package/src/executor/noop-executor.ts +23 -0
- package/src/executor/registry.ts +64 -0
- package/src/executor/shell-executor.ts +148 -0
- package/src/executor/slack-executor.ts +176 -0
- package/src/executor/sql-executor.ts +146 -0
- package/src/executor/websocket-executor.ts +211 -0
- package/src/index.ts +24 -0
- package/src/interceptor/index.ts +1 -0
- package/src/interceptor/provider-interceptor.ts +315 -0
- package/src/mcp/auth-verifier.ts +152 -0
- package/src/mcp/bridge.ts +703 -0
- package/src/mcp/http-transport.ts +698 -0
- package/src/mcp/index.ts +9 -0
- package/src/mcp/internal-auth.ts +14 -0
- package/src/mcp/oauth-pages.ts +139 -0
- package/src/mcp/oauth-postgres-stores.ts +278 -0
- package/src/mcp/oauth-provider.ts +536 -0
- package/src/mcp/oauth-stores.ts +202 -0
- package/src/mcp/server.ts +55 -0
- package/src/mcp/tool-definitions.ts +562 -0
- package/src/metrics/collector.ts +357 -0
- package/src/metrics/index.ts +1 -0
- package/src/middleware/auth.ts +814 -0
- package/src/middleware/session.ts +85 -0
- package/src/middleware/validate.ts +130 -0
- package/src/policy/engine.ts +815 -0
- package/src/policy/index.ts +2 -0
- package/src/policy/opa-engine.ts +829 -0
- package/src/proxy/forward-proxy.ts +649 -0
- package/src/proxy/index.ts +1 -0
- package/src/ratelimit/limiter.ts +196 -0
- package/src/replay/engine.ts +142 -0
- package/src/replay/index.ts +1 -0
- package/src/saas/index.ts +1 -0
- package/src/saas/routes.ts +2178 -0
- package/src/server/app.ts +985 -0
- package/src/server/errors.ts +49 -0
- package/src/server/gateway.ts +1130 -0
- package/src/server/index.ts +307 -0
- package/src/server/logger.ts +255 -0
- package/src/server/stream-proxy.ts +202 -0
- package/src/storage/file-persistence.ts +315 -0
- package/src/storage/index.ts +4 -0
- package/src/storage/interfaces.ts +287 -0
- package/src/storage/memory.ts +686 -0
- package/src/storage/postgres.ts +1831 -0
- package/src/storage/redis.ts +835 -0
- package/src/tracing/index.ts +1 -0
- package/src/tracing/provider.ts +100 -0
- package/src/trust/calculator.ts +141 -0
- package/src/trust/index.ts +7 -0
- package/src/types/budget.ts +36 -0
- package/src/types/config.ts +278 -0
- package/src/types/events.ts +41 -0
- package/src/types/express.d.ts +14 -0
- package/src/types/index.ts +7 -0
- package/src/types/policy.ts +83 -0
- package/src/types/stripe-config.ts +11 -0
- package/src/types/subscription.ts +59 -0
- package/src/types/tool-call.ts +47 -0
- package/src/types/tool-result.ts +82 -0
- package/src/types/user.ts +125 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import * as promClient from 'prom-client';
|
|
2
|
+
|
|
3
|
+
export class GatewayMetrics {
|
|
4
|
+
private registry: promClient.Registry;
|
|
5
|
+
|
|
6
|
+
// Counters
|
|
7
|
+
private requestsTotal: promClient.Counter;
|
|
8
|
+
private policyDecisionsTotal: promClient.Counter;
|
|
9
|
+
private dlpDetectionsTotal: promClient.Counter;
|
|
10
|
+
private budgetBlockedTotal: promClient.Counter;
|
|
11
|
+
private rateLimitBlockedTotal: promClient.Counter;
|
|
12
|
+
private idempotencyHitsTotal: promClient.Counter;
|
|
13
|
+
private executorErrorsTotal: promClient.Counter;
|
|
14
|
+
|
|
15
|
+
// Cost & usage counters
|
|
16
|
+
private costUsdTotal: promClient.Counter;
|
|
17
|
+
private tokenUsageTotal: promClient.Counter;
|
|
18
|
+
|
|
19
|
+
// LLM-specific counters/histograms
|
|
20
|
+
private llmCostUsdTotal: promClient.Counter;
|
|
21
|
+
private llmTokensTotal: promClient.Counter;
|
|
22
|
+
private llmRequestsTotal: promClient.Counter;
|
|
23
|
+
private llmLatencySeconds: promClient.Histogram;
|
|
24
|
+
|
|
25
|
+
// Observability: cache and storage health
|
|
26
|
+
private cacheHitsTotal: promClient.Counter;
|
|
27
|
+
private cacheMissesTotal: promClient.Counter;
|
|
28
|
+
private storageWriteFailuresTotal: promClient.Counter;
|
|
29
|
+
private dlpTruncatedTotal: promClient.Counter;
|
|
30
|
+
|
|
31
|
+
// Histograms
|
|
32
|
+
private requestDuration: promClient.Histogram;
|
|
33
|
+
private costPerRequest: promClient.Histogram;
|
|
34
|
+
|
|
35
|
+
// Gauge
|
|
36
|
+
private activeApprovals: promClient.Gauge;
|
|
37
|
+
|
|
38
|
+
constructor() {
|
|
39
|
+
this.registry = new promClient.Registry();
|
|
40
|
+
|
|
41
|
+
// Enable default metrics (process CPU, memory, etc.) with palaryn_ prefix
|
|
42
|
+
promClient.collectDefaultMetrics({
|
|
43
|
+
register: this.registry,
|
|
44
|
+
prefix: 'palaryn_',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// palaryn_requests_total
|
|
48
|
+
this.requestsTotal = new promClient.Counter({
|
|
49
|
+
name: 'palaryn_requests_total',
|
|
50
|
+
help: 'Total number of tool call requests processed by the gateway',
|
|
51
|
+
labelNames: ['status', 'tool_name', 'capability'],
|
|
52
|
+
registers: [this.registry],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// palaryn_request_duration_seconds
|
|
56
|
+
this.requestDuration = new promClient.Histogram({
|
|
57
|
+
name: 'palaryn_request_duration_seconds',
|
|
58
|
+
help: 'Duration of tool call request processing in seconds',
|
|
59
|
+
labelNames: ['status', 'tool_name'],
|
|
60
|
+
buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
|
|
61
|
+
registers: [this.registry],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// palaryn_policy_decisions_total
|
|
65
|
+
this.policyDecisionsTotal = new promClient.Counter({
|
|
66
|
+
name: 'palaryn_policy_decisions_total',
|
|
67
|
+
help: 'Total number of policy decisions made',
|
|
68
|
+
labelNames: ['decision', 'rule_id'],
|
|
69
|
+
registers: [this.registry],
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// palaryn_dlp_detections_total
|
|
73
|
+
this.dlpDetectionsTotal = new promClient.Counter({
|
|
74
|
+
name: 'palaryn_dlp_detections_total',
|
|
75
|
+
help: 'Total number of DLP detections',
|
|
76
|
+
labelNames: ['detection_type', 'severity'],
|
|
77
|
+
registers: [this.registry],
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// palaryn_budget_blocked_total
|
|
81
|
+
this.budgetBlockedTotal = new promClient.Counter({
|
|
82
|
+
name: 'palaryn_budget_blocked_total',
|
|
83
|
+
help: 'Total number of requests blocked due to budget limits',
|
|
84
|
+
labelNames: ['reason_type'],
|
|
85
|
+
registers: [this.registry],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// palaryn_rate_limit_blocked_total
|
|
89
|
+
this.rateLimitBlockedTotal = new promClient.Counter({
|
|
90
|
+
name: 'palaryn_rate_limit_blocked_total',
|
|
91
|
+
help: 'Total number of requests blocked due to rate limiting',
|
|
92
|
+
labelNames: ['blocked_by'],
|
|
93
|
+
registers: [this.registry],
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// palaryn_idempotency_hits_total
|
|
97
|
+
this.idempotencyHitsTotal = new promClient.Counter({
|
|
98
|
+
name: 'palaryn_idempotency_hits_total',
|
|
99
|
+
help: 'Total number of idempotency cache hits (deduplicated requests)',
|
|
100
|
+
registers: [this.registry],
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// palaryn_active_approvals
|
|
104
|
+
this.activeApprovals = new promClient.Gauge({
|
|
105
|
+
name: 'palaryn_active_approvals',
|
|
106
|
+
help: 'Current number of pending approval requests',
|
|
107
|
+
registers: [this.registry],
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// palaryn_executor_errors_total
|
|
111
|
+
this.executorErrorsTotal = new promClient.Counter({
|
|
112
|
+
name: 'palaryn_executor_errors_total',
|
|
113
|
+
help: 'Total number of executor errors during tool execution',
|
|
114
|
+
labelNames: ['tool_name', 'error_type'],
|
|
115
|
+
registers: [this.registry],
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// palaryn_cost_usd_total
|
|
119
|
+
this.costUsdTotal = new promClient.Counter({
|
|
120
|
+
name: 'palaryn_cost_usd_total',
|
|
121
|
+
help: 'Total cost in USD tracked by the gateway',
|
|
122
|
+
labelNames: ['source', 'tool_name'],
|
|
123
|
+
registers: [this.registry],
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// palaryn_token_usage_total
|
|
127
|
+
this.tokenUsageTotal = new promClient.Counter({
|
|
128
|
+
name: 'palaryn_token_usage_total',
|
|
129
|
+
help: 'Total token usage tracked by the gateway',
|
|
130
|
+
labelNames: ['type', 'tool_name'],
|
|
131
|
+
registers: [this.registry],
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// palaryn_cost_per_request_usd
|
|
135
|
+
this.costPerRequest = new promClient.Histogram({
|
|
136
|
+
name: 'palaryn_cost_per_request_usd',
|
|
137
|
+
help: 'Cost per request in USD',
|
|
138
|
+
labelNames: ['tool_name'],
|
|
139
|
+
buckets: [0.0001, 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10],
|
|
140
|
+
registers: [this.registry],
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// palaryn_llm_cost_usd_total
|
|
144
|
+
this.llmCostUsdTotal = new promClient.Counter({
|
|
145
|
+
name: 'palaryn_llm_cost_usd_total',
|
|
146
|
+
help: 'Total LLM cost in USD by model and provider',
|
|
147
|
+
labelNames: ['model', 'provider'],
|
|
148
|
+
registers: [this.registry],
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// palaryn_llm_tokens_total
|
|
152
|
+
this.llmTokensTotal = new promClient.Counter({
|
|
153
|
+
name: 'palaryn_llm_tokens_total',
|
|
154
|
+
help: 'Total LLM tokens by type, model, and provider',
|
|
155
|
+
labelNames: ['type', 'model', 'provider'],
|
|
156
|
+
registers: [this.registry],
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// palaryn_llm_requests_total
|
|
160
|
+
this.llmRequestsTotal = new promClient.Counter({
|
|
161
|
+
name: 'palaryn_llm_requests_total',
|
|
162
|
+
help: 'Total LLM requests by model, provider, and status',
|
|
163
|
+
labelNames: ['model', 'provider', 'status'],
|
|
164
|
+
registers: [this.registry],
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// palaryn_llm_latency_seconds
|
|
168
|
+
this.llmLatencySeconds = new promClient.Histogram({
|
|
169
|
+
name: 'palaryn_llm_latency_seconds',
|
|
170
|
+
help: 'LLM request latency in seconds by model and provider',
|
|
171
|
+
labelNames: ['model', 'provider'],
|
|
172
|
+
buckets: [0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60],
|
|
173
|
+
registers: [this.registry],
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// palaryn_cache_hits_total
|
|
177
|
+
this.cacheHitsTotal = new promClient.Counter({
|
|
178
|
+
name: 'palaryn_cache_hits_total',
|
|
179
|
+
help: 'Total cache hits by store type',
|
|
180
|
+
labelNames: ['store'],
|
|
181
|
+
registers: [this.registry],
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// palaryn_cache_misses_total
|
|
185
|
+
this.cacheMissesTotal = new promClient.Counter({
|
|
186
|
+
name: 'palaryn_cache_misses_total',
|
|
187
|
+
help: 'Total cache misses by store type',
|
|
188
|
+
labelNames: ['store'],
|
|
189
|
+
registers: [this.registry],
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// palaryn_storage_write_failures_total
|
|
193
|
+
this.storageWriteFailuresTotal = new promClient.Counter({
|
|
194
|
+
name: 'palaryn_storage_write_failures_total',
|
|
195
|
+
help: 'Total storage write failures by store and backend',
|
|
196
|
+
labelNames: ['store', 'backend'],
|
|
197
|
+
registers: [this.registry],
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// palaryn_dlp_truncated_total
|
|
201
|
+
this.dlpTruncatedTotal = new promClient.Counter({
|
|
202
|
+
name: 'palaryn_dlp_truncated_total',
|
|
203
|
+
help: 'Total number of DLP scans that were truncated due to response size limits',
|
|
204
|
+
registers: [this.registry],
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Record a completed request with its status, tool info, and duration.
|
|
210
|
+
*/
|
|
211
|
+
recordRequest(status: string, toolName: string, capability: string, durationSeconds: number): void {
|
|
212
|
+
this.requestsTotal.inc({ status, tool_name: toolName, capability });
|
|
213
|
+
this.requestDuration.observe({ status, tool_name: toolName }, durationSeconds);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Record a policy engine decision.
|
|
218
|
+
*/
|
|
219
|
+
recordPolicyDecision(decision: string, ruleId: string): void {
|
|
220
|
+
this.policyDecisionsTotal.inc({ decision, rule_id: ruleId });
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Record a DLP detection event.
|
|
225
|
+
*/
|
|
226
|
+
recordDLPDetection(detectionType: string, severity: string): void {
|
|
227
|
+
this.dlpDetectionsTotal.inc({ detection_type: detectionType, severity });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Record a budget block event.
|
|
232
|
+
*/
|
|
233
|
+
recordBudgetBlock(reasonType: string): void {
|
|
234
|
+
this.budgetBlockedTotal.inc({ reason_type: reasonType });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Record a rate limit block event.
|
|
239
|
+
*/
|
|
240
|
+
recordRateLimitBlock(blockedBy: string): void {
|
|
241
|
+
this.rateLimitBlockedTotal.inc({ blocked_by: blockedBy });
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Record an idempotency cache hit.
|
|
246
|
+
*/
|
|
247
|
+
recordIdempotencyHit(): void {
|
|
248
|
+
this.idempotencyHitsTotal.inc();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Record an executor error.
|
|
253
|
+
*/
|
|
254
|
+
recordExecutorError(toolName: string, errorType: string): void {
|
|
255
|
+
this.executorErrorsTotal.inc({ tool_name: toolName, error_type: errorType });
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Set the current count of active (pending) approvals.
|
|
260
|
+
*/
|
|
261
|
+
setActiveApprovals(count: number): void {
|
|
262
|
+
this.activeApprovals.set(count);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Record a cost observation.
|
|
267
|
+
*/
|
|
268
|
+
recordCost(costUsd: number, source: string, toolName: string): void {
|
|
269
|
+
this.costUsdTotal.inc({ source, tool_name: toolName }, costUsd);
|
|
270
|
+
this.costPerRequest.observe({ tool_name: toolName }, costUsd);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Record token usage.
|
|
275
|
+
*/
|
|
276
|
+
recordTokenUsage(type: string, toolName: string, tokens: number): void {
|
|
277
|
+
this.tokenUsageTotal.inc({ type, tool_name: toolName }, tokens);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Record LLM-specific usage metrics (model, provider, tokens, cost, latency).
|
|
282
|
+
*/
|
|
283
|
+
recordLLMUsage(params: {
|
|
284
|
+
model: string;
|
|
285
|
+
provider: string;
|
|
286
|
+
inputTokens?: number;
|
|
287
|
+
outputTokens?: number;
|
|
288
|
+
costUsd?: number;
|
|
289
|
+
durationSeconds: number;
|
|
290
|
+
status: string;
|
|
291
|
+
}): void {
|
|
292
|
+
const { model, provider, inputTokens, outputTokens, costUsd, durationSeconds, status } = params;
|
|
293
|
+
|
|
294
|
+
this.llmRequestsTotal.inc({ model, provider, status });
|
|
295
|
+
this.llmLatencySeconds.observe({ model, provider }, durationSeconds);
|
|
296
|
+
|
|
297
|
+
if (costUsd !== undefined && costUsd > 0) {
|
|
298
|
+
this.llmCostUsdTotal.inc({ model, provider }, costUsd);
|
|
299
|
+
}
|
|
300
|
+
if (inputTokens !== undefined) {
|
|
301
|
+
this.llmTokensTotal.inc({ type: 'input', model, provider }, inputTokens);
|
|
302
|
+
}
|
|
303
|
+
if (outputTokens !== undefined) {
|
|
304
|
+
this.llmTokensTotal.inc({ type: 'output', model, provider }, outputTokens);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Record a cache hit for a specific store.
|
|
310
|
+
*/
|
|
311
|
+
recordCacheHit(store: string): void {
|
|
312
|
+
this.cacheHitsTotal.inc({ store });
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Record a cache miss for a specific store.
|
|
317
|
+
*/
|
|
318
|
+
recordCacheMiss(store: string): void {
|
|
319
|
+
this.cacheMissesTotal.inc({ store });
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Record a storage write failure.
|
|
324
|
+
*/
|
|
325
|
+
recordStorageWriteFailure(store: string, backend: string): void {
|
|
326
|
+
this.storageWriteFailuresTotal.inc({ store, backend });
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Record a DLP scan truncation event.
|
|
331
|
+
*/
|
|
332
|
+
recordDLPTruncation(): void {
|
|
333
|
+
this.dlpTruncatedTotal.inc();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Get serialized Prometheus metrics for the /metrics endpoint.
|
|
338
|
+
*/
|
|
339
|
+
async getMetrics(): Promise<string> {
|
|
340
|
+
return this.registry.metrics();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Get the content type header for Prometheus metrics responses.
|
|
345
|
+
*/
|
|
346
|
+
getContentType(): string {
|
|
347
|
+
return this.registry.contentType;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Reset all metrics in the registry. Used during graceful shutdown
|
|
352
|
+
* to flush metric state before the process exits.
|
|
353
|
+
*/
|
|
354
|
+
reset(): void {
|
|
355
|
+
this.registry.resetMetrics();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GatewayMetrics } from './collector';
|