Skip to content

Commit be40131

Browse files
ChrisJBurnsclaude
andauthored
Add ConfigMap content assertions to vMCP telemetry integration tests (#4807)
Add ConfigMap content assertions to telemetry integration tests Verify the vmcp-config ConfigMap contains the correct telemetry settings from the referenced MCPTelemetryConfig: endpoint (with https:// prefix stripped), tracing/metrics enabled flags, and that the ConfigMap updates when the MCPTelemetryConfig endpoint changes. This ensures the full data path is tested end-to-end: CRD spec → converter → ConfigMap → telemetry config, not just status conditions. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0fb1b42 commit be40131

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

cmd/thv-operator/test-integration/virtualmcp/virtualmcpserver_telemetryconfig_integration_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package controllers
66

77
import (
8+
"fmt"
89
"time"
910

1011
. "github.com/onsi/ginkgo/v2"
@@ -13,6 +14,7 @@ import (
1314
apierrors "k8s.io/apimachinery/pkg/api/errors"
1415
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1516
"k8s.io/apimachinery/pkg/types"
17+
"sigs.k8s.io/yaml"
1618

1719
mcpv1alpha1 "github.com/stacklok/toolhive/cmd/thv-operator/api/v1alpha1"
1820
telemetryconfig "github.com/stacklok/toolhive/pkg/telemetry"
@@ -140,6 +142,33 @@ var _ = Describe("VirtualMCPServer TelemetryConfig Integration",
140142
return false
141143
}, timeout, interval).Should(BeTrue())
142144
})
145+
146+
It("should produce a ConfigMap with telemetry config from the MCPTelemetryConfig", func() {
147+
configMapName := fmt.Sprintf("%s-vmcp-config", virtualMCPServer.Name)
148+
Eventually(func() bool {
149+
cm := &corev1.ConfigMap{}
150+
err := k8sClient.Get(ctx, types.NamespacedName{
151+
Name: configMapName,
152+
Namespace: namespace,
153+
}, cm)
154+
if err != nil {
155+
return false
156+
}
157+
configYAML, ok := cm.Data["config.yaml"]
158+
if !ok || configYAML == "" {
159+
return false
160+
}
161+
// Parse the config and verify telemetry fields match the MCPTelemetryConfig
162+
var config vmcpconfig.Config
163+
if err := yaml.Unmarshal([]byte(configYAML), &config); err != nil {
164+
return false
165+
}
166+
return config.Telemetry != nil &&
167+
config.Telemetry.Endpoint == "otel-collector:4317" && // NormalizeTelemetryConfig strips https://
168+
config.Telemetry.TracingEnabled &&
169+
config.Telemetry.MetricsEnabled
170+
}, timeout, interval).Should(BeTrue())
171+
})
143172
})
144173

145174
Context("VirtualMCPServer should update when MCPTelemetryConfig spec changes", Ordered, func() {
@@ -253,6 +282,26 @@ var _ = Describe("VirtualMCPServer TelemetryConfig Integration",
253282
return fetched.Status.TelemetryConfigHash != "" &&
254283
fetched.Status.TelemetryConfigHash != initialHash
255284
}, timeout, interval).Should(BeTrue())
285+
286+
// Verify the ConfigMap reflects the new endpoint
287+
configMapName := fmt.Sprintf("%s-vmcp-config", virtualMCPServer.Name)
288+
Eventually(func() bool {
289+
cm := &corev1.ConfigMap{}
290+
err := k8sClient.Get(ctx, types.NamespacedName{
291+
Name: configMapName,
292+
Namespace: namespace,
293+
}, cm)
294+
if err != nil {
295+
return false
296+
}
297+
var config vmcpconfig.Config
298+
if err := yaml.Unmarshal([]byte(cm.Data["config.yaml"]), &config); err != nil {
299+
return false
300+
}
301+
// NormalizeTelemetryConfig strips https:// prefix
302+
return config.Telemetry != nil &&
303+
config.Telemetry.Endpoint == "new-collector:4317"
304+
}, timeout, interval).Should(BeTrue())
256305
})
257306
})
258307

0 commit comments

Comments
 (0)