@@ -509,7 +509,7 @@ func newFakePlugin(ctx customContext, pluginVersion int) externalPlugin {
509
509
Context : ctx ,
510
510
},
511
511
pluginInstance : & PluginV1Instance {
512
- Labels : map [string ]string {"role" : "fileserver" , "environment" : "development" , "agent_role" : "overwrite agent role" },
512
+ Labels : map [string ]string {"role" : "fileserver" , "environment" : "development" },
513
513
plugin : & Plugin {
514
514
Name : "new-plugin" ,
515
515
ProtocolVersion : pluginVersion ,
@@ -573,7 +573,7 @@ func newFakePluginWithEnvVars(pluginVersion int) externalPlugin {
573
573
Context : ctx ,
574
574
},
575
575
pluginInstance : & PluginV1Instance {
576
- Labels : map [string ]string {"role" : "fileserver" , "environment" : "development" , "agent_role" : "overwrite agent role" },
576
+ Labels : map [string ]string {"role" : "fileserver" , "environment" : "development" },
577
577
plugin : & Plugin {
578
578
Name : "new-plugin" ,
579
579
ProtocolVersion : pluginVersion ,
@@ -676,36 +676,22 @@ func (rs *RunnerSuite) TestPluginHandleOutputV1(c *C) {
676
676
c .Assert (err , IsNil )
677
677
678
678
c .Assert (rd , NotNil )
679
+ c .Assert (len (rd .Data ), Equals , 4 )
680
+ c .Assert (rd .Data [0 ].SortKey (), Equals , "first" )
681
+
682
+ invData := rd .Data [3 ].(protocol.InventoryData )
683
+ c .Assert (invData ["id" ], Equals , "integrationUser" )
684
+ c .Assert (invData ["value" ], Equals , "test" )
679
685
680
686
c .Assert (event , NotNil )
681
687
c .Assert (event ["event_type" ], Equals , "LoadBalancerSample" )
682
688
c .Assert (event ["id" ], Equals , "first" )
683
689
c .Assert (event ["value" ], Equals , "random" )
684
690
c .Assert (event ["integrationUser" ], Equals , "test" )
685
691
686
- expectedLabelValues := map [string ]string {
687
- "first" : "fake" ,
688
- "labels/my_group" : "test group" ,
689
- "labels/role" : "fileserver" ,
690
- "labels/environment" : "development" ,
691
- "labels/agent_role" : "overwrite agent role" ,
692
- "integrationUser" : "test" ,
693
- "integrationName" : "test" ,
694
- "integrationVersion" : "1.0.0" ,
695
- }
696
-
697
- c .Assert (len (rd .Data ), Equals , 8 )
698
-
699
- for _ , item := range rd .Data {
700
- if invData , ok := item .(protocol.InventoryData ); ok {
701
- id , _ := invData ["id" ].(string )
702
- value , _ := invData ["value" ].(string )
703
-
704
- if expectedValue , exists := expectedLabelValues [id ]; exists {
705
- c .Assert (value , Equals , expectedValue )
706
- } else {
707
- c .Fatalf ("Expected label: %v not found in Inventory" , id )
708
- }
692
+ for _ , labelKey := range labelKeys {
693
+ if rd .Data [1 ].SortKey () != labelKey && rd .Data [2 ].SortKey () != labelKey {
694
+ c .Errorf ("There isn't label '%s'' in the inventory" , labelKey )
709
695
}
710
696
}
711
697
}
@@ -740,7 +726,6 @@ func (rs *RunnerSuite) TestPluginHandleOutputEventsV1(c *C) {
740
726
// labels from pluginInstance
741
727
c .Assert (event ["label.environment" ], Equals , "development" )
742
728
c .Assert (event ["label.role" ], Equals , "fileserver" )
743
- c .Assert (event ["label.agent_role" ], Equals , "overwrite agent role" )
744
729
745
730
// labels from databind
746
731
c .Assert (event ["label.expected" ], Equals , "extra label" )
@@ -846,7 +831,7 @@ func (rs *RunnerSuite) TestEventsPluginRunV1(c *C) {
846
831
c .Assert (err , IsNil )
847
832
848
833
c .Assert (rd , NotNil )
849
- c .Assert (len (rd .Data ), Equals , 7 )
834
+ c .Assert (len (rd .Data ), Equals , 3 )
850
835
c .Assert (rd .Data [0 ].SortKey (), Equals , "first" )
851
836
852
837
c .Assert (event , NotNil )
@@ -1045,7 +1030,7 @@ func (rs *RunnerSuite) TestHandleOutputV1(c *C) {
1045
1030
c .Assert (err , IsNil )
1046
1031
1047
1032
// labels are added as inventory
1048
- c .Assert (len (rd .Data )- len (labelKeys ), Equals , 7 )
1033
+ c .Assert (len (rd .Data )- len (labelKeys ), Equals , 3 )
1049
1034
1050
1035
firstData := rd .Data [0 ]
1051
1036
inv := firstData .(protocol.InventoryData )
@@ -1560,16 +1545,12 @@ func TestParsePayloadV3(t *testing.T) {
1560
1545
type fakeEmitter struct {
1561
1546
lastEventData map [string ]interface {}
1562
1547
lastEntityKey string
1563
- inventory types.PluginInventoryDataset
1564
1548
}
1565
1549
1566
1550
func (f * fakeEmitter ) EmitInventoryWithPluginId (data types.PluginInventoryDataset , entityKey string , pluginId ids.PluginID ) {
1567
- f .inventory = data
1568
1551
}
1569
1552
1570
- func (f * fakeEmitter ) EmitInventory (data types.PluginInventoryDataset , entity entity.Entity ) {
1571
- f .inventory = data
1572
- }
1553
+ func (f * fakeEmitter ) EmitInventory (data types.PluginInventoryDataset , entity entity.Entity ) {}
1573
1554
1574
1555
func (f * fakeEmitter ) EmitEvent (eventData map [string ]interface {}, entityKey entity.Key ) {
1575
1556
f .lastEventData = eventData
@@ -1605,29 +1586,6 @@ func TestEmitPayloadV2NoDisplayNameNoEntityName(t *testing.T) {
1605
1586
assert .EqualValues (t , "Motorbike" , emitter .lastEventData ["entityName" ])
1606
1587
assert .EqualValues (t , "motorbike:street_hawk" , emitter .lastEventData ["entityKey" ])
1607
1588
1608
- expectedLabelValues := map [string ]string {
1609
- "integrationUser" : "testuser" ,
1610
- "integrationName" : "test/test" ,
1611
- "integrationVersion" : "x.y.z" ,
1612
- "reportingAgent" : "my-agent-id" ,
1613
- "motor" : "" , // we are type converting to string so motor does not have a value
1614
- }
1615
-
1616
- assert .EqualValues (t , len (emitter .inventory ), 5 )
1617
-
1618
- for _ , item := range emitter .inventory {
1619
- if invData , ok := item .(protocol.InventoryData ); ok {
1620
- id , _ := invData ["id" ].(string )
1621
- value , _ := invData ["value" ].(string )
1622
-
1623
- if expectedValue , exists := expectedLabelValues [id ]; exists {
1624
- assert .EqualValues (t , value , expectedValue )
1625
- } else {
1626
- assert .Fail (t , "Expected label not found in Inventory" , "Label: %s not found in inventory" , id )
1627
- }
1628
- }
1629
- }
1630
-
1631
1589
// Local entity, no displayName, no entityName
1632
1590
assert .NoError (t , EmitDataSet (ctx , & emitter , "test/test" , "x.y.z" , "testuser" , rd .DataSets [2 ], extraAnnotations , labels , entityRewrite , version ))
1633
1591
_ , ok := emitter .lastEventData ["displayName" ]
@@ -1636,27 +1594,6 @@ func TestEmitPayloadV2NoDisplayNameNoEntityName(t *testing.T) {
1636
1594
assert .False (t , ok )
1637
1595
// but entityKey is the agent key
1638
1596
assert .EqualValues (t , "my-agent-id" , emitter .lastEventData ["entityKey" ])
1639
-
1640
- // Check inventory data
1641
- assert .EqualValues (t , len (emitter .inventory ), 5 )
1642
-
1643
- for _ , item := range emitter .inventory {
1644
- if invData , ok := item .(protocol.InventoryData ); ok {
1645
- id , _ := invData ["id" ].(string )
1646
- value , _ := invData ["value" ].(string )
1647
-
1648
- if expectedValue , exists := expectedLabelValues [id ]; exists {
1649
- assert .EqualValues (t , value , expectedValue )
1650
- } else {
1651
- assert .Fail (t , "Expected label not found in Inventory" , "Label: %s not found in inventory" , id )
1652
- }
1653
- }
1654
- }
1655
- }
1656
-
1657
- func createMockConfigWithDataMap (attrs map [string ]interface {}) * config.Config {
1658
- customAttrs := config .CustomAttributeMap (attrs )
1659
- return & config.Config {CustomAttributes : customAttrs } //nolint:all
1660
1597
}
1661
1598
1662
1599
func TestEmitDataSet_OnAddHostnameDecoratesWithHostname (t * testing.T ) {
@@ -1689,7 +1626,6 @@ func TestEmitDataSet_OnAddHostnameDecoratesWithHostname(t *testing.T) {
1689
1626
ctx .On ("EntityKey" ).Return (agentIdentifier )
1690
1627
ctx .On ("HostnameResolver" ).Return (newFixedHostnameResolver (hn , "short" ))
1691
1628
ctx .On ("IDLookup" ).Return (newFixedIDLookup ())
1692
- ctx .On ("Config" ).Return (createMockConfigWithDataMap (make (map [string ]interface {})))
1693
1629
1694
1630
em := & fakeEmitter {}
1695
1631
extraAnnotations := map [string ]string {}
@@ -1741,7 +1677,6 @@ func TestEmitDataSet_EntityNameLocalhostIsNotReplacedWithHostnameV2(t *testing.T
1741
1677
ctx .On ("EntityKey" ).Return (agID )
1742
1678
ctx .On ("HostnameResolver" ).Return (newFixedHostnameResolver ("foo.bar" , "short" ))
1743
1679
ctx .On ("IDLookup" ).Return (newFixedIDLookup ())
1744
- ctx .On ("Config" ).Return (createMockConfigWithDataMap (make (map [string ]interface {})))
1745
1680
1746
1681
em := & fakeEmitter {}
1747
1682
extraAnnotations := map [string ]string {}
@@ -1789,7 +1724,6 @@ func TestEmitDataSet_EntityNameLocalhostIsReplacedWithHostnameV3(t *testing.T) {
1789
1724
ctx .On ("EntityKey" ).Return (agID )
1790
1725
ctx .On ("HostnameResolver" ).Return (newFixedHostnameResolver ("foo.bar" , "short" ))
1791
1726
ctx .On ("IDLookup" ).Return (newFixedIDLookup ())
1792
- ctx .On ("Config" ).Return (createMockConfigWithDataMap (make (map [string ]interface {})))
1793
1727
1794
1728
em := & fakeEmitter {}
1795
1729
extraAnnotations := map [string ]string {}
@@ -1838,7 +1772,6 @@ func TestEmitDataSet_MetricHostnameIsReplacedIfLocalhostV3(t *testing.T) {
1838
1772
ctx .On ("EntityKey" ).Return (agID )
1839
1773
ctx .On ("HostnameResolver" ).Return (newFixedHostnameResolver ("foo.bar" , "short" ))
1840
1774
ctx .On ("IDLookup" ).Return (newFixedIDLookup ())
1841
- ctx .On ("Config" ).Return (createMockConfigWithDataMap (make (map [string ]interface {})))
1842
1775
1843
1776
em := & fakeEmitter {}
1844
1777
extraAnnotations := map [string ]string {}
@@ -1888,7 +1821,6 @@ func TestEmitDataSet_ReportingFieldsAreReplacedIfLocalhostV3(t *testing.T) {
1888
1821
ctx .On ("EntityKey" ).Return (agID )
1889
1822
ctx .On ("HostnameResolver" ).Return (newFixedHostnameResolver ("foo.bar" , "short" ))
1890
1823
ctx .On ("IDLookup" ).Return (newFixedIDLookup ())
1891
- ctx .On ("Config" ).Return (createMockConfigWithDataMap (make (map [string ]interface {})))
1892
1824
1893
1825
em := & fakeEmitter {}
1894
1826
extraAnnotations := map [string ]string {}
@@ -1937,7 +1869,6 @@ func TestEmitDataSet_LogsEntityViolationsOncePerEntity(t *testing.T) {
1937
1869
ctx .On ("EntityKey" ).Return (agID )
1938
1870
ctx .On ("HostnameResolver" ).Return (newFixedHostnameResolver ("foo.bar" , "short" ))
1939
1871
ctx .On ("IDLookup" ).Return (newFixedIDLookup ())
1940
- ctx .On ("Config" ).Return (createMockConfigWithDataMap (make (map [string ]interface {})))
1941
1872
1942
1873
em := & fakeEmitter {}
1943
1874
extraAnnotations := map [string ]string {}
@@ -1975,7 +1906,6 @@ func TestEmitDataSet_DoNotOverrideExistingMetrics(t *testing.T) {
1975
1906
ctx .On ("EntityKey" ).Return ("agent-id" )
1976
1907
ctx .On ("HostnameResolver" ).Return (newFixedHostnameResolver ("long" , "short" ))
1977
1908
ctx .On ("IDLookup" ).Return (newFixedIDLookup ())
1978
- ctx .On ("Config" ).Return (createMockConfigWithDataMap (make (map [string ]interface {})))
1979
1909
em := & fakeEmitter {}
1980
1910
extraAnnotations := map [string ]string {
1981
1911
"cluster_name" : "K8sDiscoveredCluster" ,
@@ -2277,7 +2207,8 @@ func TestLogFields(t *testing.T) {
2277
2207
"TEMP_DIR" : "a/path" ,
2278
2208
})
2279
2209
assert .Equal (t , fields ["labels" ], map [string ]string {
2280
- "agent_role" : "overwrite agent role" , "environment" : "development" , "role" : "fileserver" ,
2210
+ "role" : "fileserver" ,
2211
+ "environment" : "development" ,
2281
2212
})
2282
2213
2283
2214
if runtime .GOOS == "windows" {
0 commit comments