@@ -251,7 +251,7 @@ func Test_splunkhecReceiver_handleReq(t *testing.T) {
251
251
{
252
252
name : "metric_msg_accepted" ,
253
253
req : func () * http.Request {
254
- msgBytes , err := json .Marshal (buildSplunkHecMetricsMsg (3 , 4 , 3 ))
254
+ msgBytes , err := json .Marshal (buildSplunkHecMetricsMsg ("metric" , 3 , 4 , 3 ))
255
255
require .NoError (t , err )
256
256
req := httptest .NewRequest (http .MethodPost , "http://localhost/foo" , bytes .NewReader (msgBytes ))
257
257
return req
@@ -368,7 +368,7 @@ func Test_consumer_err(t *testing.T) {
368
368
369
369
func Test_consumer_err_metrics (t * testing.T ) {
370
370
currentTime := float64 (time .Now ().UnixNano ()) / 1e6
371
- splunkMsg := buildSplunkHecMetricsMsg (currentTime , 13 , 2 )
371
+ splunkMsg := buildSplunkHecMetricsMsg ("metric" , currentTime , 13 , 2 )
372
372
assert .True (t , splunkMsg .IsMetric ())
373
373
config := createDefaultConfig ().(* Config )
374
374
config .Endpoint = "localhost:0" // Actually not creating the endpoint\
@@ -570,7 +570,7 @@ func Test_splunkhecReceiver_AccessTokenPassthrough(t *testing.T) {
570
570
currentTime := float64 (time .Now ().UnixNano ()) / 1e6
571
571
var splunkhecMsg * splunk.Event
572
572
if tt .metric {
573
- splunkhecMsg = buildSplunkHecMetricsMsg (currentTime , 1.0 , 3 )
573
+ splunkhecMsg = buildSplunkHecMetricsMsg ("metric" , currentTime , 1.0 , 3 )
574
574
} else {
575
575
splunkhecMsg = buildSplunkHecMsg (currentTime , 3 )
576
576
}
@@ -738,18 +738,29 @@ func Test_Metrics_splunkhecReceiver_IndexSourceTypePassthrough(t *testing.T) {
738
738
name string
739
739
index string
740
740
sourcetype string
741
+ event string
741
742
}{
742
743
{
743
- name : "No index, no source type" ,
744
+ name : "No index, no source type" ,
745
+ event : "metric" ,
744
746
},
745
747
{
746
748
name : "Index, no source type" ,
747
749
index : "myindex" ,
750
+ event : "metric" ,
748
751
},
749
752
{
750
753
name : "Index and source type" ,
751
754
index : "myindex" ,
752
755
sourcetype : "source:type" ,
756
+ event : "metric" ,
757
+ },
758
+ {
759
+ name : "empty event" ,
760
+ event : "" ,
761
+ },
762
+ {
763
+ name : "nil event" ,
753
764
},
754
765
}
755
766
@@ -786,7 +797,7 @@ func Test_Metrics_splunkhecReceiver_IndexSourceTypePassthrough(t *testing.T) {
786
797
rcv .metricsConsumer = exporter
787
798
788
799
currentTime := float64 (time .Now ().UnixNano ()) / 1e6
789
- splunkhecMsg := buildSplunkHecMetricsMsg (currentTime , 42 , 3 )
800
+ splunkhecMsg := buildSplunkHecMetricsMsg (tt . event , currentTime , 42 , 3 )
790
801
splunkhecMsg .Index = tt .index
791
802
splunkhecMsg .SourceType = tt .sourcetype
792
803
msgBytes , _ := json .Marshal (splunkhecMsg )
@@ -834,10 +845,10 @@ func Test_Metrics_splunkhecReceiver_IndexSourceTypePassthrough(t *testing.T) {
834
845
}
835
846
}
836
847
837
- func buildSplunkHecMetricsMsg (time float64 , value int64 , dimensions uint ) * splunk.Event {
848
+ func buildSplunkHecMetricsMsg (event any , time float64 , value int64 , dimensions uint ) * splunk.Event {
838
849
ev := & splunk.Event {
839
850
Time : time ,
840
- Event : "metric" ,
851
+ Event : event ,
841
852
Fields : map [string ]any {
842
853
"metric_name:foo" : value ,
843
854
},
0 commit comments