diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 27da97b..a8a8365 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -13,7 +13,7 @@ var ( Name: "mcp_calls_total", Help: "Total number of MCP calls", }, - []string{"method", "name", "success"}, + []string{"server", "method", "name", "success"}, ) // MCPCallDuration measures the duration of MCP calls by method, name (for `tools/call`) and success @@ -23,6 +23,6 @@ var ( Help: "Duration of MCP calls in seconds", Buckets: prometheus.DefBuckets, }, - []string{"method", "name", "success"}, + []string{"server", "method", "name", "success"}, ) ) diff --git a/internal/server/metrics_middleware.go b/internal/server/metrics_middleware.go index 4e90fcb..b7e572c 100644 --- a/internal/server/metrics_middleware.go +++ b/internal/server/metrics_middleware.go @@ -10,6 +10,8 @@ import ( "github.com/modelcontextprotocol/go-sdk/mcp" ) +const serverName = "argocd-mcp-server" + func NewMetricsMiddleware(logger *slog.Logger) mcp.Middleware { return func(next mcp.MethodHandler) mcp.MethodHandler { return func(ctx context.Context, method string, req mcp.Request) (mcp.Result, error) { @@ -30,8 +32,8 @@ func NewMetricsMiddleware(logger *slog.Logger) mcp.Middleware { success = success && !r.IsError } // increment/update the metrics - metrics.MCPCallsTotal.WithLabelValues(method, tool, strconv.FormatBool(success)).Inc() - metrics.MCPCallDuration.WithLabelValues(method, tool, strconv.FormatBool(success)).Observe(float64(duration.Seconds())) + metrics.MCPCallsTotal.WithLabelValues(serverName, method, tool, strconv.FormatBool(success)).Inc() + metrics.MCPCallDuration.WithLabelValues(serverName, method, tool, strconv.FormatBool(success)).Observe(float64(duration.Seconds())) return result, err } } diff --git a/taskfile.yaml b/taskfile.yaml index ddb4271..2099caf 100644 --- a/taskfile.yaml +++ b/taskfile.yaml @@ -24,7 +24,8 @@ tasks: podman-compose-up: cmds: - - podman-compose up -d --build + # --build is used to build the images if they are not already built + - podman-compose up -d --build podman-compose-down: cmds: diff --git a/test/e2e/server_test.go b/test/e2e/server_test.go index a6a828f..b109e4e 100644 --- a/test/e2e/server_test.go +++ b/test/e2e/server_test.go @@ -63,6 +63,7 @@ func TestStatefulServer(t *testing.T) { var mcpCallsDurationSecondsInfBucketBefore int64 if td.name == "http" { mcpCallsTotalMetricBefore, mcpCallsDurationSecondsInfBucketBefore = getMetrics(t, "http://localhost:50081", map[string]string{ + "server": "argocd-mcp-server", "method": "tools/call", "name": "unhealthyApplications", "success": "true", @@ -99,6 +100,7 @@ func TestStatefulServer(t *testing.T) { if td.name == "http" { // get the metrics after the call mcpCallsTotalMetricAfter, mcpCallsDurationSecondsInfBucketAfter := getMetrics(t, "http://localhost:50081", map[string]string{ + "server": "argocd-mcp-server", "method": "tools/call", "name": "unhealthyApplications", "success": "true", @@ -114,6 +116,7 @@ func TestStatefulServer(t *testing.T) { var mcpCallsDurationSecondsInfBucketBefore int64 if td.name == "http" { mcpCallsTotalMetricBefore, mcpCallsDurationSecondsInfBucketBefore = getMetrics(t, "http://localhost:50081", map[string]string{ + "server": "argocd-mcp-server", "method": "tools/call", "name": "unhealthyApplicationResources", "success": "true", @@ -181,6 +184,7 @@ func TestStatefulServer(t *testing.T) { if td.name == "http" { // get the metrics after the call mcpCallsTotalMetricAfter, mcpCallsDurationSecondsInfBucketAfter := getMetrics(t, "http://localhost:50081", map[string]string{ + "server": "argocd-mcp-server", "method": "tools/call", "name": "unhealthyApplicationResources", "success": "true", @@ -195,6 +199,7 @@ func TestStatefulServer(t *testing.T) { var mcpCallsDurationSecondsInfBucketBefore int64 if td.name == "http" { mcpCallsTotalMetricBefore, mcpCallsDurationSecondsInfBucketBefore = getMetrics(t, "http://localhost:50081", map[string]string{ + "server": "argocd-mcp-server", "method": "tools/call", "name": "unhealthyApplicationResources", "success": "false", @@ -215,6 +220,7 @@ func TestStatefulServer(t *testing.T) { if td.name == "http" { // get the metrics after the call mcpCallsTotalMetricAfter, mcpCallsDurationSecondsInfBucketAfter := getMetrics(t, "http://localhost:50081", map[string]string{ + "server": "argocd-mcp-server", "method": "tools/call", "name": "unhealthyApplicationResources", "success": "false",