-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: add connector test cases and missing attributes #5059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Pratham-Mishra04
merged 1 commit into
dev
from
07-09-feat_add_connector_test_cases_and_missing_attributes
Jul 9, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| package schemas | ||
|
|
||
| // EnrichmentDim describes one identity/context dimension that connectors attach | ||
| // to the telemetry they emit for a request (which team/customer/business unit/ | ||
| // virtual key/etc. the request belongs to). | ||
| // | ||
| // It is the single source of truth that keeps the CURATED emitters from drifting | ||
| // apart — the ones that hand-pick a dimension list: | ||
| // - Prometheus labels (OSS plugins/telemetry) | ||
| // - Datadog metric tags (enterprise plugins/datadog, buildMetricTags) | ||
| // - BigQuery columns (enterprise plugins/bigquery, traceColumns) | ||
| // | ||
| // Each of those derives its list from this registry, and a per-connector | ||
| // conformance test asserts the derived list matches — so adding a dimension in | ||
| // one place can't silently leave the others behind. | ||
| // | ||
| // The GENERIC emitters (otel, kafka, pubsub) project the entire span attribute | ||
| // map and therefore already carry every dimension; they need no derivation and | ||
| // no conformance test here. | ||
| // | ||
| // `alias` and `routing_engine_used` are in the metric tier but derived only | ||
| // post-response (once model resolution/routing has run). They are attached to | ||
| // the span in framework/tracing and carry a normal (non-empty) SpanAttr, so a | ||
| // record/trace-tier connector can read them like any other dimension. | ||
| type EnrichmentDim struct { | ||
| // Name is the canonical short identifier, used verbatim as the Prometheus | ||
| // label and the Datadog metric tag key. The BigQuery column name also equals | ||
| // it unless Column overrides (see below). | ||
| Name string | ||
| // Column is the BigQuery column name when it differs from Name. BigQuery | ||
| // predates the "method" naming and stores it as "request_type"; empty means | ||
| // the column name equals Name. | ||
| Column string | ||
| // SpanAttr is the canonical bifrost.* span-attribute key the dimension is | ||
| // stored under. It is what the record/trace-tier emitters read and what a | ||
| // connector derives its projection from. | ||
| SpanAttr string | ||
| // MetricSafe marks a LOW-cardinality dimension eligible to become a Prometheus | ||
| // label / Datadog metric tag. High-cardinality dims (per-user, arrays) are | ||
| // false and live only on records/traces (BigQuery columns, span attributes). | ||
| MetricSafe bool | ||
| // Multi marks an array-valued dimension — governance can attach several teams/ | ||
| // customers/business units to a single request. Array dims are never | ||
| // MetricSafe (they would explode metric series cardinality). | ||
| Multi bool | ||
| } | ||
|
|
||
| // EnrichmentDims is the canonical, ordered registry of identity/context | ||
| // dimensions. Order is stable so derived lists (labels/tags/columns) are | ||
| // deterministic. Add a dimension here once and every curated connector picks it | ||
| // up via its derivation + conformance test. | ||
| var EnrichmentDims = []EnrichmentDim{ | ||
| // --- Metric tier: low-cardinality, safe as Prometheus labels / Datadog tags, | ||
| // and also present on records/traces. --- | ||
| {Name: "provider", SpanAttr: AttrBifrostProviderName, MetricSafe: true}, | ||
| {Name: "model", SpanAttr: AttrRequestModel, MetricSafe: true}, | ||
| {Name: "method", Column: "request_type", SpanAttr: AttrLegacyRequestType, MetricSafe: true}, | ||
| // alias and routing_engine_used are derived post-response and attached to the | ||
| // span in framework/tracing (they have no meaning until the model is resolved | ||
| // and routing has run), so connectors read them like any other dimension. | ||
| {Name: "alias", SpanAttr: AttrBifrostAlias, MetricSafe: true}, | ||
| {Name: "routing_engine_used", SpanAttr: AttrBifrostRoutingEngineUsed, MetricSafe: true}, | ||
| {Name: "virtual_key_id", SpanAttr: AttrBifrostVirtualKeyID, MetricSafe: true}, | ||
| {Name: "virtual_key_name", SpanAttr: AttrBifrostVirtualKeyName, MetricSafe: true}, | ||
| {Name: "selected_key_id", SpanAttr: AttrBifrostSelectedKeyID, MetricSafe: true}, | ||
| {Name: "selected_key_name", SpanAttr: AttrBifrostSelectedKeyName, MetricSafe: true}, | ||
| {Name: "routing_rule_id", SpanAttr: AttrBifrostRoutingRuleID, MetricSafe: true}, | ||
| {Name: "routing_rule_name", SpanAttr: AttrBifrostRoutingRuleName, MetricSafe: true}, | ||
| {Name: "team_id", SpanAttr: AttrBifrostTeamID, MetricSafe: true}, | ||
| {Name: "team_name", SpanAttr: AttrBifrostTeamName, MetricSafe: true}, | ||
| {Name: "customer_id", SpanAttr: AttrBifrostCustomerID, MetricSafe: true}, | ||
| {Name: "customer_name", SpanAttr: AttrBifrostCustomerName, MetricSafe: true}, | ||
| {Name: "business_unit_id", SpanAttr: AttrBifrostBusinessUnitID, MetricSafe: true}, | ||
| {Name: "business_unit_name", SpanAttr: AttrBifrostBusinessUnitName, MetricSafe: true}, | ||
| {Name: "fallback_index", SpanAttr: AttrBifrostFallbackIndex, MetricSafe: true}, | ||
|
|
||
| // --- Record/trace tier only: high cardinality, NOT metric-safe. Present on | ||
| // BigQuery columns and span attributes, never as metric labels/tags. --- | ||
| {Name: "user_id", SpanAttr: AttrBifrostUserID}, | ||
| {Name: "user_name", SpanAttr: AttrBifrostUserName}, | ||
| {Name: "team_ids", SpanAttr: AttrBifrostTeamIDs, Multi: true}, | ||
| {Name: "team_names", SpanAttr: AttrBifrostTeamNames, Multi: true}, | ||
| {Name: "customer_ids", SpanAttr: AttrBifrostCustomerIDs, Multi: true}, | ||
| {Name: "customer_names", SpanAttr: AttrBifrostCustomerNames, Multi: true}, | ||
| {Name: "business_unit_ids", SpanAttr: AttrBifrostBusinessUnitIDs, Multi: true}, | ||
| {Name: "business_unit_names", SpanAttr: AttrBifrostBusinessUnitNames, Multi: true}, | ||
| } | ||
|
|
||
| // ColumnName returns the BigQuery column name for the dimension — Column when | ||
| // set, otherwise Name. | ||
| func (d EnrichmentDim) ColumnName() string { | ||
| if d.Column != "" { | ||
| return d.Column | ||
| } | ||
| return d.Name | ||
| } | ||
|
|
||
| // EnrichmentDimColumnNames returns the BigQuery column name for every dimension, | ||
| // in registry order (the record/trace-tier set). | ||
| func EnrichmentDimColumnNames() []string { | ||
| out := make([]string, len(EnrichmentDims)) | ||
| for i, d := range EnrichmentDims { | ||
| out[i] = d.ColumnName() | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| // MetricSafeEnrichmentDims returns the low-cardinality dimensions eligible to be | ||
| // Prometheus labels / Datadog metric tags, in registry order. | ||
| func MetricSafeEnrichmentDims() []EnrichmentDim { | ||
| out := make([]EnrichmentDim, 0, len(EnrichmentDims)) | ||
| for _, d := range EnrichmentDims { | ||
| if d.MetricSafe { | ||
| out = append(out, d) | ||
| } | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| // EnrichmentDimNames returns every dimension name, in registry order (the | ||
| // record/trace-tier set). | ||
| func EnrichmentDimNames() []string { | ||
| out := make([]string, len(EnrichmentDims)) | ||
| for i, d := range EnrichmentDims { | ||
| out[i] = d.Name | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| // MetricSafeEnrichmentDimNames returns the names of the metric-tier dimensions, | ||
| // in registry order. | ||
| func MetricSafeEnrichmentDimNames() []string { | ||
| out := make([]string, 0, len(EnrichmentDims)) | ||
| for _, d := range EnrichmentDims { | ||
| if d.MetricSafe { | ||
| out = append(out, d.Name) | ||
| } | ||
| } | ||
| return out | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package schemas | ||
|
|
||
| import "testing" | ||
|
|
||
| // TestArrayDimsAreNeverMetricSafe is the structural guard that keeps array | ||
| // (Multi) dimensions out of the metric tier — i.e. out of Prometheus labels and | ||
| // Datadog metric tags. An array value like "team-a,team-b,team-c" would become a | ||
| // distinct label/tag value per team combination and explode series cardinality, | ||
| // so a Multi dimension must never be MetricSafe. The curated connectors derive | ||
| // their metric-tier lists from MetricSafeEnrichmentDims(), so this invariant is | ||
| // what actually prevents arrays from ever being shared as Prometheus labels. | ||
| func TestArrayDimsAreNeverMetricSafe(t *testing.T) { | ||
| for _, d := range EnrichmentDims { | ||
| if d.Multi && d.MetricSafe { | ||
| t.Errorf("dimension %q is Multi (array) AND MetricSafe — arrays must never be metric labels/tags (cardinality explosion)", d.Name) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // TestEnrichmentDimNamesUnique guards against a copy-paste duplicate slipping into | ||
| // the registry, which would double-emit a label/column. | ||
| func TestEnrichmentDimNamesUnique(t *testing.T) { | ||
| seen := map[string]bool{} | ||
| for _, d := range EnrichmentDims { | ||
| if seen[d.Name] { | ||
| t.Errorf("duplicate enrichment dimension name %q", d.Name) | ||
| } | ||
| seen[d.Name] = true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package telemetry | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/maximhq/bifrost/core/schemas" | ||
| ) | ||
|
|
||
| // TestPrometheusLabelsMatchEnrichmentRegistry keeps the Prometheus bifrost label | ||
| // set in parity with the canonical enrichment registry (core/schemas): every | ||
| // metric-safe dimension must be a label, and no record-tier (high cardinality) | ||
| // dimension may be. Known divergences are enumerated in the allowlist below; the | ||
| // test fails on any new drift and when a listed entry no longer applies. | ||
| func TestPrometheusLabelsMatchEnrichmentRegistry(t *testing.T) { | ||
| labels := map[string]bool{} | ||
| for _, l := range defaultBifrostLabelNames { | ||
| labels[l] = true | ||
| } | ||
|
|
||
| metricSafe := map[string]bool{} | ||
| for _, n := range schemas.MetricSafeEnrichmentDimNames() { | ||
| metricSafe[n] = true | ||
| } | ||
| allDims := map[string]bool{} | ||
| for _, n := range schemas.EnrichmentDimNames() { | ||
| allDims[n] = true | ||
| } | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
|
|
||
| // Metric-safe dims the telemetry plugin does not expose as labels. Empty: the | ||
| // Prometheus label set covers the full metric-safe registry. | ||
| knownMissing := map[string]string{} | ||
|
|
||
| // 1) Every metric-safe dim must be a label, unless a known gap. | ||
| for n := range metricSafe { | ||
| if !labels[n] && knownMissing[n] == "" { | ||
| t.Errorf("Prometheus labels are missing registry metric-safe dimension %q", n) | ||
| } | ||
| } | ||
| // 2) Every enrichment-dim label must be metric-safe (no high-cardinality labels). | ||
| for l := range labels { | ||
| if !allDims[l] { | ||
| continue // non-enrichment label (e.g. status_code) — out of scope | ||
| } | ||
| if !metricSafe[l] { | ||
| t.Errorf("Prometheus exposes record-tier dimension %q as a label (cardinality risk)", l) | ||
| } | ||
| } | ||
| // 3) Keep the allowlist honest: a gap that has closed must be removed. | ||
| for n := range knownMissing { | ||
| if labels[n] { | ||
| t.Errorf("dimension %q is now a label — remove it from knownMissing", n) | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.