Skip to content

Commit f8bb79e

Browse files
committed
Fix bitmap encoding every telemetry bit as set
The telemetry struct's fields have no json tags, so structwalk.Walk does not honor omitempty and visits every field regardless of value. Bits() ignored the visited value and set the bit on mere presence, so every telemetry bit was 1 on every deploy (the acceptance golden showed all mutually-exclusive one-hot members set at once). Gate the telemetry walk on the visited bool value so a field maps to a bit only when true. Also drop blank lines in splitLines so a stray one can never shift bit indices in the append-only schema, and make the test stand-in tagless to match the real struct (the tagged stand-in masked the bug). Co-authored-by: Isaac
1 parent d209615 commit f8bb79e

6 files changed

Lines changed: 104 additions & 129 deletions

File tree

‎acceptance/bundle/bitmap/out.bitmap-text.txt‎

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,63 +3199,63 @@
31993199
0 python.mutators[*]
32003200
0 python.venv_path
32013201
0 definitions
3202-
1 telemetry.ArtifactDynamicVersionIsSet
3203-
1 telemetry.HasTfOnlyReferences
3204-
1 telemetry.SelectUsed
3205-
1 telemetry.ArtifactsReferenceUsed
3206-
1 telemetry.ConfigHasDoubleDollarBrace
3207-
1 telemetry.ConfigHasDoubleDollar
3208-
1 telemetry.ConfigHasBackslashDollarBrace
3209-
1 telemetry.ConfigHasBackslashDollar
3210-
1 telemetry.StatePathIsShared
3211-
1 telemetry.StatePathInDeployerHome
3212-
1 telemetry.StatePathInOtherUserHome
3213-
1 telemetry.StatePathOther
3214-
1 telemetry.DMSUndeclaredDeployingUser
3215-
1 telemetry.DMSUndeclaredOtherUser
3216-
1 telemetry.DMSUndeclaredServicePrincipal
3217-
1 telemetry.DMSUndeclaredGroup
3218-
1 telemetry.DMSCompatAuto
3219-
1 telemetry.DMSCompatOnlySelfUndeclared
3220-
1 telemetry.DMSCompatNot
3221-
1 telemetry.DirectMigrateError
3222-
1 telemetry.DirectMigrateCommitError
3223-
1 telemetry.DirectMigrateWarnings
3224-
1 telemetry.DirectMigratedViaConfig
3225-
1 telemetry.DirectMigratedViaEnv
3226-
1 telemetry.EngineTerraformConfig
3227-
1 telemetry.EngineTerraformEnv
3228-
1 telemetry.SkipArtifactCleanupTrue
3229-
1 telemetry.SkipArtifactCleanupFalse
3230-
1 telemetry.HasServerlessComputeTrue
3231-
1 telemetry.HasServerlessComputeFalse
3232-
1 telemetry.HasClassicJobComputeTrue
3233-
1 telemetry.HasClassicJobComputeFalse
3234-
1 telemetry.HasClassicInteractiveComputeTrue
3235-
1 telemetry.HasClassicInteractiveComputeFalse
3236-
1 telemetry.ArtifactBuildCommandIsSetTrue
3237-
1 telemetry.ArtifactBuildCommandIsSetFalse
3238-
1 telemetry.ArtifactFilesIsSetTrue
3239-
1 telemetry.ArtifactFilesIsSetFalse
3240-
1 telemetry.SourceLinkedSetForNonDevelopmentTrue
3241-
1 telemetry.SourceLinkedSetForNonDevelopmentFalse
3202+
0 telemetry.ArtifactDynamicVersionIsSet
3203+
0 telemetry.HasTfOnlyReferences
3204+
0 telemetry.SelectUsed
3205+
0 telemetry.ArtifactsReferenceUsed
3206+
0 telemetry.ConfigHasDoubleDollarBrace
3207+
0 telemetry.ConfigHasDoubleDollar
3208+
0 telemetry.ConfigHasBackslashDollarBrace
3209+
0 telemetry.ConfigHasBackslashDollar
3210+
0 telemetry.StatePathIsShared
3211+
0 telemetry.StatePathInDeployerHome
3212+
0 telemetry.StatePathInOtherUserHome
3213+
0 telemetry.StatePathOther
3214+
0 telemetry.DMSUndeclaredDeployingUser
3215+
0 telemetry.DMSUndeclaredOtherUser
3216+
0 telemetry.DMSUndeclaredServicePrincipal
3217+
0 telemetry.DMSUndeclaredGroup
3218+
0 telemetry.DMSCompatAuto
3219+
0 telemetry.DMSCompatOnlySelfUndeclared
3220+
0 telemetry.DMSCompatNot
3221+
0 telemetry.DirectMigrateError
3222+
0 telemetry.DirectMigrateCommitError
3223+
0 telemetry.DirectMigrateWarnings
3224+
0 telemetry.DirectMigratedViaConfig
3225+
0 telemetry.DirectMigratedViaEnv
3226+
0 telemetry.EngineTerraformConfig
3227+
0 telemetry.EngineTerraformEnv
3228+
0 telemetry.SkipArtifactCleanupTrue
3229+
0 telemetry.SkipArtifactCleanupFalse
3230+
0 telemetry.HasServerlessComputeTrue
3231+
0 telemetry.HasServerlessComputeFalse
3232+
0 telemetry.HasClassicJobComputeTrue
3233+
0 telemetry.HasClassicJobComputeFalse
3234+
0 telemetry.HasClassicInteractiveComputeTrue
3235+
0 telemetry.HasClassicInteractiveComputeFalse
3236+
0 telemetry.ArtifactBuildCommandIsSetTrue
3237+
0 telemetry.ArtifactBuildCommandIsSetFalse
3238+
0 telemetry.ArtifactFilesIsSetTrue
3239+
0 telemetry.ArtifactFilesIsSetFalse
3240+
0 telemetry.SourceLinkedSetForNonDevelopmentTrue
3241+
0 telemetry.SourceLinkedSetForNonDevelopmentFalse
32423242
1 telemetry.PresetsNamePrefixIsSetTrue
3243-
1 telemetry.PresetsNamePrefixIsSetFalse
3244-
1 telemetry.UseLegacyRunAsTrue
3243+
0 telemetry.PresetsNamePrefixIsSetFalse
3244+
0 telemetry.UseLegacyRunAsTrue
32453245
1 telemetry.UseLegacyRunAsFalse
3246-
1 telemetry.RunAsSetTrue
3246+
0 telemetry.RunAsSetTrue
32473247
1 telemetry.RunAsSetFalse
3248-
1 telemetry.PermissionsSectionSetTrue
3249-
1 telemetry.PermissionsSectionSetFalse
3250-
1 telemetry.PythonWheelWrapperIsSetTrue
3251-
1 telemetry.PythonWheelWrapperIsSetFalse
3252-
1 telemetry.AppLifecycleStartedTrue
3253-
1 telemetry.AppLifecycleStartedFalse
3254-
1 telemetry.ClusterLifecycleStartedTrue
3255-
1 telemetry.ClusterLifecycleStartedFalse
3256-
1 telemetry.SqlWarehouseLifecycleStartedTrue
3257-
1 telemetry.SqlWarehouseLifecycleStartedFalse
3258-
1 telemetry.DirectDryMigrateSuccessTrue
3259-
1 telemetry.DirectDryMigrateSuccessFalse
3260-
1 telemetry.DirectDryMigrateWarningsTrue
3261-
1 telemetry.DirectDryMigrateWarningsFalse
3248+
0 telemetry.PermissionsSectionSetTrue
3249+
0 telemetry.PermissionsSectionSetFalse
3250+
0 telemetry.PythonWheelWrapperIsSetTrue
3251+
0 telemetry.PythonWheelWrapperIsSetFalse
3252+
0 telemetry.AppLifecycleStartedTrue
3253+
0 telemetry.AppLifecycleStartedFalse
3254+
0 telemetry.ClusterLifecycleStartedTrue
3255+
0 telemetry.ClusterLifecycleStartedFalse
3256+
0 telemetry.SqlWarehouseLifecycleStartedTrue
3257+
0 telemetry.SqlWarehouseLifecycleStartedFalse
3258+
0 telemetry.DirectDryMigrateSuccessTrue
3259+
0 telemetry.DirectDryMigrateSuccessFalse
3260+
0 telemetry.DirectDryMigrateWarningsTrue
3261+
0 telemetry.DirectDryMigrateWarningsFalse
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cnEKcWJg4NnLwHCCQU6JgYWBnYGBoYH9AcMDbgUGBgUGNCDBzMDDMApoCizYwFT9fzD4AQgAAP//
1+
cnEKcWJg4NnLwHCCQU6JgYWBnYGBoYH9AcMDbgUGBgUGNCDBzMDDMApoCizYEGwvBgZAAAAA//8=

‎acceptance/bundle/templates/default-python/classic/out.bitmap.txt‎

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -118,63 +118,8 @@
118118
1 presets.artifacts_dynamic_version
119119
1 presets.tags
120120
1 presets.tags.*
121-
1 telemetry.ArtifactDynamicVersionIsSet
122-
1 telemetry.HasTfOnlyReferences
123-
1 telemetry.SelectUsed
124-
1 telemetry.ArtifactsReferenceUsed
125-
1 telemetry.ConfigHasDoubleDollarBrace
126-
1 telemetry.ConfigHasDoubleDollar
127-
1 telemetry.ConfigHasBackslashDollarBrace
128-
1 telemetry.ConfigHasBackslashDollar
129-
1 telemetry.StatePathIsShared
130-
1 telemetry.StatePathInDeployerHome
131-
1 telemetry.StatePathInOtherUserHome
132-
1 telemetry.StatePathOther
133-
1 telemetry.DMSUndeclaredDeployingUser
134-
1 telemetry.DMSUndeclaredOtherUser
135-
1 telemetry.DMSUndeclaredServicePrincipal
136-
1 telemetry.DMSUndeclaredGroup
137-
1 telemetry.DMSCompatAuto
138-
1 telemetry.DMSCompatOnlySelfUndeclared
139-
1 telemetry.DMSCompatNot
140-
1 telemetry.DirectMigrateError
141-
1 telemetry.DirectMigrateCommitError
142-
1 telemetry.DirectMigrateWarnings
143-
1 telemetry.DirectMigratedViaConfig
144-
1 telemetry.DirectMigratedViaEnv
145-
1 telemetry.EngineTerraformConfig
146-
1 telemetry.EngineTerraformEnv
147-
1 telemetry.SkipArtifactCleanupTrue
148-
1 telemetry.SkipArtifactCleanupFalse
149-
1 telemetry.HasServerlessComputeTrue
150-
1 telemetry.HasServerlessComputeFalse
151-
1 telemetry.HasClassicJobComputeTrue
152-
1 telemetry.HasClassicJobComputeFalse
153-
1 telemetry.HasClassicInteractiveComputeTrue
154-
1 telemetry.HasClassicInteractiveComputeFalse
155121
1 telemetry.ArtifactBuildCommandIsSetTrue
156-
1 telemetry.ArtifactBuildCommandIsSetFalse
157-
1 telemetry.ArtifactFilesIsSetTrue
158122
1 telemetry.ArtifactFilesIsSetFalse
159-
1 telemetry.SourceLinkedSetForNonDevelopmentTrue
160-
1 telemetry.SourceLinkedSetForNonDevelopmentFalse
161123
1 telemetry.PresetsNamePrefixIsSetTrue
162-
1 telemetry.PresetsNamePrefixIsSetFalse
163-
1 telemetry.UseLegacyRunAsTrue
164124
1 telemetry.UseLegacyRunAsFalse
165-
1 telemetry.RunAsSetTrue
166125
1 telemetry.RunAsSetFalse
167-
1 telemetry.PermissionsSectionSetTrue
168-
1 telemetry.PermissionsSectionSetFalse
169-
1 telemetry.PythonWheelWrapperIsSetTrue
170-
1 telemetry.PythonWheelWrapperIsSetFalse
171-
1 telemetry.AppLifecycleStartedTrue
172-
1 telemetry.AppLifecycleStartedFalse
173-
1 telemetry.ClusterLifecycleStartedTrue
174-
1 telemetry.ClusterLifecycleStartedFalse
175-
1 telemetry.SqlWarehouseLifecycleStartedTrue
176-
1 telemetry.SqlWarehouseLifecycleStartedFalse
177-
1 telemetry.DirectDryMigrateSuccessTrue
178-
1 telemetry.DirectDryMigrateSuccessFalse
179-
1 telemetry.DirectDryMigrateWarningsTrue
180-
1 telemetry.DirectDryMigrateWarningsFalse

‎acceptance/bundle/templates/default-python/classic/output.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Workspace:
3333
Validation OK!
3434

3535
>>> [CLI] bundle bitmap bitmap -t dev
36-
cnEKcWJg4NnLwHCCQU6p246BnYGBoYH9/dMH3AoMDAoMDN8ZGBgYOBjAJBODxGcGfgYIkGIgHRSATEQCnEwgk9NhXA4GRgY5uGSCAEIh63oGCgHPAQEGJQOGIQAs2O+AqPr/YPADEAAA//8=
36+
cnEKcWJg4NnLwHCCQU6p246BnYGBoYH9/dMH3AoMDAoMDN8ZGBgYOBjAJBODxGcGfgYIkGIgHRSATEQCnEwgk9NhXA4GRgY5uGSCAEIh63oGCgHPAQEGJQOGIQAs2O/AmEJeDAyAAAAA//8=
3737

3838
>>> [CLI] bundle plan -t dev
3939
Building python_artifact...

‎bundle/bitmap/bitmap.go‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func Bits(cfg config.Root, telemetry any, schema []string) ([]bool, error) {
132132
}
133133

134134
bits := make([]bool, len(schema))
135-
set := func(prefix string, path *structpath.PathNode) {
135+
setBit := func(prefix string, path *structpath.PathNode) {
136136
for _, pattern := range normalizePrefixes(path) {
137137
if i, ok := index[prefix+pattern]; ok {
138138
bits[i] = true
@@ -141,13 +141,19 @@ func Bits(cfg config.Root, telemetry any, schema []string) ([]bool, error) {
141141
}
142142

143143
err := structwalk.Walk(cfg, func(path *structpath.PathNode, _ any, _ *reflect.StructField) {
144-
set("", path)
144+
setBit("", path)
145145
})
146146
if err != nil {
147147
return nil, err
148148
}
149-
err = structwalk.Walk(telemetry, func(path *structpath.PathNode, _ any, _ *reflect.StructField) {
150-
set(telemetryPrefix+".", path)
149+
// The telemetry struct's fields have no json tags, so Walk does not honor
150+
// omitempty and visits every field regardless of value. Presence in the
151+
// struct is meaningless here (all fields always exist), so gate on the
152+
// visited bool value: a field maps to a bit only when it is true.
153+
err = structwalk.Walk(telemetry, func(path *structpath.PathNode, val any, _ *reflect.StructField) {
154+
if set, ok := val.(bool); ok && set {
155+
setBit(telemetryPrefix+".", path)
156+
}
151157
})
152158
if err != nil {
153159
return nil, err
@@ -250,9 +256,14 @@ func splitLines(b []byte) []string {
250256
// the same clean field paths as WalkType produces; otherwise Merge's dedup
251257
// never matches and the schema doubles.
252258
s := strings.ReplaceAll(string(b), "\r\n", "\n")
253-
s = strings.TrimRight(s, "\n")
254-
if s == "" {
255-
return nil
259+
var lines []string
260+
for line := range strings.SplitSeq(s, "\n") {
261+
// Drop blank lines defensively: a stray one (bad edit, merge artifact)
262+
// would otherwise become a real schema entry and shift every following
263+
// bit index, silently breaking append-only stability.
264+
if line != "" {
265+
lines = append(lines, line)
266+
}
256267
}
257-
return strings.Split(s, "\n")
268+
return lines
258269
}

‎bundle/bitmap/bitmap_test.go‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ import (
1313
)
1414

1515
// testTelemetry stands in for bundle.Telemetry so this package's tests stay
16-
// decoupled from the bundle package.
16+
// decoupled from the bundle package. Like the real struct, its fields have no
17+
// json tags, so structwalk.Walk visits every field regardless of value and Bits
18+
// must gate on the visited bool value rather than mere presence.
1719
type testTelemetry struct {
18-
SelectUsed bool `json:"select_used"`
20+
SelectUsed bool
21+
RunAsSet bool
1922
}
2023

2124
func TestMergeAppendOnly(t *testing.T) {
@@ -51,8 +54,9 @@ func TestWalkSchemaPrunesTargets(t *testing.T) {
5154

5255
assert.Contains(t, schema, "bundle.name")
5356
assert.Contains(t, schema, "resources.jobs.*.name")
54-
// Telemetry fields are namespaced under "telemetry.".
55-
assert.Contains(t, schema, "telemetry.select_used")
57+
// Telemetry fields are namespaced under "telemetry." and, having no json
58+
// tag, keep their Go field name.
59+
assert.Contains(t, schema, "telemetry.SelectUsed")
5660
}
5761

5862
func TestBitsSetsLeafAndPrefixes(t *testing.T) {
@@ -105,13 +109,28 @@ func TestSplitLinesStripsCRLF(t *testing.T) {
105109
// paths as an LF one, so Merge's dedup matches and the schema does not double.
106110
assert.Equal(t, []string{"variables", "bundle.name"}, splitLines([]byte("variables\r\nbundle.name\r\n")))
107111
assert.Equal(t, []string{"variables", "bundle.name"}, splitLines([]byte("variables\nbundle.name\n")))
112+
113+
// Blank lines (leading, internal, trailing) are dropped so they can never
114+
// shift bit indices in the append-only schema.
115+
assert.Equal(t, []string{"variables", "bundle.name"}, splitLines([]byte("\nvariables\n\nbundle.name\n\n")))
116+
assert.Empty(t, splitLines([]byte("")))
117+
assert.Empty(t, splitLines([]byte("\n\n")))
108118
}
109119

110-
func TestBitsSetsTelemetryField(t *testing.T) {
111-
schema := []string{"telemetry.select_used"}
120+
func TestBitsSetsTelemetryFieldByValue(t *testing.T) {
121+
schema := []string{"telemetry.SelectUsed", "telemetry.RunAsSet"}
122+
123+
// Only the true-valued field sets its bit. A false telemetry field must stay
124+
// 0: its Go-named field has no json tag, so structwalk.Walk visits it
125+
// regardless of value, and Bits must not treat mere presence as set.
112126
bits, err := Bits(config.Root{}, testTelemetry{SelectUsed: true}, schema)
113127
require.NoError(t, err)
114-
assert.Equal(t, []bool{true}, bits)
128+
assert.Equal(t, []bool{true, false}, bits)
129+
130+
// A zero-valued telemetry struct sets no bits.
131+
bits, err = Bits(config.Root{}, testTelemetry{}, schema)
132+
require.NoError(t, err)
133+
assert.Equal(t, []bool{false, false}, bits)
115134
}
116135

117136
func TestEncodeDecodeRoundTrip(t *testing.T) {

0 commit comments

Comments
 (0)