@@ -197,20 +197,32 @@ func Test_ProcessProfiles_InferredScopeContext(t *testing.T) {
197197 }
198198}
199199
200- // The commented test cases require these PRs to be merged:
201- // - https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/39681
200+ // The commented test cases require this PR to be merged:
202201// - https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/39416
203202func Test_ProcessProfiles_ProfileContext (t * testing.T ) {
204203 tests := []struct {
205204 statement string
206205 want func (td pprofile.Profiles )
207206 }{
207+ {
208+ statement : `set(attributes["test"], "pass") where original_payload_format == "operationA"` ,
209+ want : func (td pprofile.Profiles ) {
210+ putProfileAttribute (t , td , 0 , "test" , "pass" )
211+ },
212+ },
208213 {
209214 statement : `set(original_payload_format, "pass") where original_payload_format == "operationA"` ,
210215 want : func (td pprofile.Profiles ) {
211216 td .ResourceProfiles ().At (0 ).ScopeProfiles ().At (0 ).Profiles ().At (0 ).SetOriginalPayloadFormat ("pass" )
212217 },
213218 },
219+ {
220+ statement : `set(attributes["test"], "pass") where resource.attributes["host.name"] == "localhost"` ,
221+ want : func (td pprofile.Profiles ) {
222+ putProfileAttribute (t , td , 0 , "test" , "pass" )
223+ putProfileAttribute (t , td , 1 , "test" , "pass" )
224+ },
225+ },
214226 {
215227 statement : `set(original_payload_format, "pass") where resource.attributes["host.name"] == "localhost"` ,
216228 want : func (td pprofile.Profiles ) {
@@ -330,18 +342,16 @@ func Test_ProcessProfiles_ProfileContext(t *testing.T) {
330342 td .ResourceProfiles ().At (0 ).ScopeProfiles ().At (0 ).Profiles ().At (0 ).SetOriginalPayloadFormat ("rat" )
331343 },
332344 },
333- /*
334- {
335- statement: `set(original_payload_format, Substring(attributes["not_exist"], 3, 3))`,
336- want: func(_ pprofile.Profiles) {},
337- },
338- {
339- statement: `set(attributes["test"], ["A", "B", "C"]) where original_payload_format == "operationA"`,
340- want: func(td pprofile.Profiles) {
341- putProfileAttribute(t, td, 0, "test", []any{"A", "B", "C"})
342- },
345+ {
346+ statement : `set(original_payload_format, Substring(attributes["not_exist"], 3, 3))` ,
347+ want : func (_ pprofile.Profiles ) {},
348+ },
349+ {
350+ statement : `set(attributes["test"], ["A", "B", "C"]) where original_payload_format == "operationA"` ,
351+ want : func (td pprofile.Profiles ) {
352+ putProfileAttribute (t , td , 0 , "test" , []any {"A" , "B" , "C" })
343353 },
344- */
354+ },
345355 {
346356 statement : `set(original_payload_format, ConvertCase(original_payload_format, "lower")) where original_payload_format == "operationA"` ,
347357 want : func (td pprofile.Profiles ) {
@@ -412,20 +422,32 @@ func Test_ProcessProfiles_ProfileContext(t *testing.T) {
412422 }
413423}
414424
415- // The commented test cases require these PRs to be merged:
416- // - https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/39681
425+ // The commented test cases require this PR to be merged:
417426// - https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/39416
418427func Test_ProcessProfiles_InferredProfileContext (t * testing.T ) {
419428 tests := []struct {
420429 statement string
421430 want func (td pprofile.Profiles )
422431 }{
432+ {
433+ statement : `set(profile.attributes["test"], "pass") where profile.original_payload_format == "operationA"` ,
434+ want : func (td pprofile.Profiles ) {
435+ putProfileAttribute (t , td , 0 , "test" , "pass" )
436+ },
437+ },
423438 {
424439 statement : `set(profile.original_payload_format, "pass") where profile.original_payload_format == "operationA"` ,
425440 want : func (td pprofile.Profiles ) {
426441 td .ResourceProfiles ().At (0 ).ScopeProfiles ().At (0 ).Profiles ().At (0 ).SetOriginalPayloadFormat ("pass" )
427442 },
428443 },
444+ {
445+ statement : `set(profile.attributes["test"], "pass") where resource.attributes["host.name"] == "localhost"` ,
446+ want : func (td pprofile.Profiles ) {
447+ putProfileAttribute (t , td , 0 , "test" , "pass" )
448+ putProfileAttribute (t , td , 1 , "test" , "pass" )
449+ },
450+ },
429451 {
430452 statement : `set(profile.original_payload_format, "pass") where resource.attributes["host.name"] == "localhost"` ,
431453 want : func (td pprofile.Profiles ) {
@@ -507,21 +529,19 @@ func Test_ProcessProfiles_InferredProfileContext(t *testing.T) {
507529 td .ResourceProfiles ().At (0 ).ScopeProfiles ().At (0 ).Profiles ().At (0 ).SetOriginalPayloadFormat ("operationA: operationA" )
508530 },
509531 },
510- /*
511- {
512- statement: `set(profile.attributes["test"], Split(profile.attributes["flags"], "|"))`,
513- want: func(td pprofile.Profiles) {
514- putProfileAttribute(t, td, 0, "test", []any{"A", "B", "C"})
515- putProfileAttribute(t, td, 1, "test", []any{"C", "D"})
516- },
532+ {
533+ statement : `set(profile.attributes["test"], Split(profile.attributes["flags"], "|"))` ,
534+ want : func (td pprofile.Profiles ) {
535+ putProfileAttribute (t , td , 0 , "test" , []any {"A" , "B" , "C" })
536+ putProfileAttribute (t , td , 1 , "test" , []any {"C" , "D" })
517537 },
518- {
519- statement: `set(profile.attributes["test"], Split(profile.attributes["flags"], "|")) where profile.original_payload_format == "operationA"`,
520- want: func(td pprofile.Profiles) {
521- putProfileAttribute(t, td, 0, "test", []any{"A", "B", "C"})
522- },
538+ },
539+ {
540+ statement : `set(profile.attributes["test"], Split(profile.attributes["flags"], "|")) where profile.original_payload_format == "operationA"` ,
541+ want : func ( td pprofile. Profiles ) {
542+ putProfileAttribute ( t , td , 0 , "test" , [] any { "A" , "B" , "C" })
523543 },
524- */
544+ },
525545 {
526546 statement : `set(profile.original_payload_format, Split(resource.attributes["not_exist"], "|"))` ,
527547 want : func (_ pprofile.Profiles ) {},
@@ -1341,3 +1361,19 @@ func constructTestProfiles() pprofiletest.Profiles {
13411361 },
13421362 }
13431363}
1364+
1365+ func putProfileAttribute (t * testing.T , td pprofile.Profiles , profileIndex int , key string , value any ) {
1366+ t .Helper ()
1367+ dic := td .ProfilesDictionary ()
1368+ profile := td .ResourceProfiles ().At (0 ).ScopeProfiles ().At (0 ).Profiles ().At (profileIndex )
1369+ switch v := value .(type ) {
1370+ case string :
1371+ require .NoError (t , pprofile .PutAttribute (dic .AttributeTable (), profile , key , pcommon .NewValueStr (v )))
1372+ case []any :
1373+ sl := pcommon .NewValueSlice ()
1374+ require .NoError (t , sl .FromRaw (v ))
1375+ require .NoError (t , pprofile .PutAttribute (dic .AttributeTable (), profile , key , sl ))
1376+ default :
1377+ t .Fatalf ("unsupported value type: %T" , v )
1378+ }
1379+ }
0 commit comments