@@ -534,3 +534,167 @@ func TestAddPoint_v1_untypedSummary(t *testing.T) {
534534
535535 assertMetricsEqual (t , expect , b .GetMetrics ())
536536}
537+
538+ func TestAddPoint_v1_gauge_separator (t * testing.T ) {
539+ // Use a dot to separate name and fields
540+ c , err := influx2otel .NewLineProtocolToOtelMetricsWithSeparator (new (common.NoopLogger ), "." )
541+ require .NoError (t , err )
542+
543+ b := c .NewBatch ()
544+ err = b .AddPoint ("cache_age_seconds" ,
545+ map [string ]string {
546+ "container.name" : "42" ,
547+ "otel.library.name" : "My Library" ,
548+ "otel.library.version" : "latest" ,
549+ "engine_id" : "0" ,
550+ },
551+ map [string ]interface {}{
552+ "gauge" : float64 (23.9 ),
553+ },
554+ time .Unix (0 , 1395066363000000123 ).UTC (),
555+ common .InfluxMetricValueTypeGauge )
556+ require .NoError (t , err )
557+
558+ err = b .AddPoint ("cache_age_seconds" ,
559+ map [string ]string {
560+ "container.name" : "42" ,
561+ "otel.library.name" : "My Library" ,
562+ "otel.library.version" : "latest" ,
563+ "engine_id" : "1" ,
564+ },
565+ map [string ]interface {}{
566+ "custom_gauge" : float64 (11.9 ),
567+ },
568+ time .Unix (0 , 1395066363000000123 ).UTC (),
569+ common .InfluxMetricValueTypeGauge )
570+ require .NoError (t , err )
571+
572+ expect := pmetric .NewMetrics ()
573+ rm := expect .ResourceMetrics ().AppendEmpty ()
574+ rm .Resource ().Attributes ().PutStr ("container.name" , "42" )
575+ isMetrics := rm .ScopeMetrics ().AppendEmpty ()
576+ isMetrics .Scope ().SetName ("My Library" )
577+ isMetrics .Scope ().SetVersion ("latest" )
578+ m := isMetrics .Metrics ().AppendEmpty ()
579+ m .SetName ("cache_age_seconds" )
580+ m .SetEmptyGauge ()
581+ dp := m .Gauge ().DataPoints ().AppendEmpty ()
582+ dp .Attributes ().PutStr ("engine_id" , "0" )
583+ dp .SetTimestamp (pcommon .NewTimestampFromTime (time .Unix (0 , 1395066363000000123 )))
584+ dp .SetDoubleValue (23.9 )
585+ m = isMetrics .Metrics ().AppendEmpty ()
586+ m .SetName ("cache_age_seconds.custom_gauge" ) // Uses a dot to separate name and fields
587+ m .SetEmptyGauge ()
588+ dp = m .Gauge ().DataPoints ().AppendEmpty ()
589+ dp .Attributes ().PutStr ("engine_id" , "1" )
590+ dp .SetTimestamp (pcommon .NewTimestampFromTime (time .Unix (0 , 1395066363000000123 )))
591+ dp .SetDoubleValue (11.9 )
592+
593+ assertMetricsEqual (t , expect , b .GetMetrics ())
594+ }
595+ func TestAddPoint_v1_sum_separator (t * testing.T ) {
596+ // Use a dot to separate name and fields
597+ c , err := influx2otel .NewLineProtocolToOtelMetricsWithSeparator (new (common.NoopLogger ), "." )
598+ require .NoError (t , err )
599+
600+ b := c .NewBatch ()
601+ err = b .AddPoint ("http_requests_total" ,
602+ map [string ]string {
603+ "container.name" : "42" ,
604+ "otel.library.name" : "My Library" ,
605+ "otel.library.version" : "latest" ,
606+ "method" : "post" ,
607+ "code" : "200" ,
608+ },
609+ map [string ]interface {}{
610+ "counter" : float64 (1027 ),
611+ },
612+ time .Unix (0 , 1395066363000000123 ).UTC (),
613+ common .InfluxMetricValueTypeSum )
614+ require .NoError (t , err )
615+
616+ err = b .AddPoint ("http_requests_total" ,
617+ map [string ]string {
618+ "container.name" : "42" ,
619+ "otel.library.name" : "My Library" ,
620+ "otel.library.version" : "latest" ,
621+ "method" : "post" ,
622+ "code" : "400" ,
623+ },
624+ map [string ]interface {}{
625+ "custom_counter" : float64 (3 ),
626+ },
627+ time .Unix (0 , 1395066363000000123 ).UTC (),
628+ common .InfluxMetricValueTypeSum )
629+ require .NoError (t , err )
630+
631+ expect := pmetric .NewMetrics ()
632+ rm := expect .ResourceMetrics ().AppendEmpty ()
633+ rm .Resource ().Attributes ().PutStr ("container.name" , "42" )
634+ isMetrics := rm .ScopeMetrics ().AppendEmpty ()
635+ isMetrics .Scope ().SetName ("My Library" )
636+ isMetrics .Scope ().SetVersion ("latest" )
637+ m := isMetrics .Metrics ().AppendEmpty ()
638+ m .SetName ("http_requests_total" )
639+ m .SetEmptySum ()
640+ m .Sum ().SetIsMonotonic (true )
641+ m .Sum ().SetAggregationTemporality (pmetric .AggregationTemporalityCumulative )
642+ dp := m .Sum ().DataPoints ().AppendEmpty ()
643+ dp .Attributes ().PutStr ("code" , "200" )
644+ dp .Attributes ().PutStr ("method" , "post" )
645+ dp .SetTimestamp (pcommon .NewTimestampFromTime (time .Unix (0 , 1395066363000000123 )))
646+ dp .SetDoubleValue (1027 )
647+ m = isMetrics .Metrics ().AppendEmpty ()
648+ m .SetName ("http_requests_total.custom_counter" ) // Uses a dot to separate name and fields
649+ m .SetEmptySum ()
650+ m .Sum ().SetIsMonotonic (true )
651+ m .Sum ().SetAggregationTemporality (pmetric .AggregationTemporalityCumulative )
652+ dp = m .Sum ().DataPoints ().AppendEmpty ()
653+ dp .Attributes ().PutStr ("code" , "400" )
654+ dp .Attributes ().PutStr ("method" , "post" )
655+ dp .SetTimestamp (pcommon .NewTimestampFromTime (time .Unix (0 , 1395066363000000123 )))
656+ dp .SetDoubleValue (3 )
657+
658+ assertMetricsEqual (t , expect , b .GetMetrics ())
659+ }
660+ func TestAddPoint_v1_untyped_separator (t * testing.T ) {
661+ // Use a dot to separate name and fields
662+ c , err := influx2otel .NewLineProtocolToOtelMetricsWithSeparator (new (common.NoopLogger ), "." )
663+ require .NoError (t , err )
664+
665+ b := c .NewBatch ()
666+ err = b .AddPoint ("some_custom_metric" ,
667+ map [string ]string {
668+ "container.name" : "42" ,
669+ "otel.library.name" : "My Library" ,
670+ "otel.library.version" : "latest" ,
671+ },
672+ map [string ]any {
673+ "count" : int64 (1 ),
674+ "something_else" : float64 (2.3 ),
675+ },
676+ time .Unix (0 , 1395066363000000123 ).UTC (),
677+ common .InfluxMetricValueTypeUntyped )
678+ require .NoError (t , err )
679+
680+ expect := pmetric .NewMetrics ()
681+ rm := expect .ResourceMetrics ().AppendEmpty ()
682+ rm .Resource ().Attributes ().PutStr ("container.name" , "42" )
683+ isMetrics := rm .ScopeMetrics ().AppendEmpty ()
684+ isMetrics .Scope ().SetName ("My Library" )
685+ isMetrics .Scope ().SetVersion ("latest" )
686+ m := isMetrics .Metrics ().AppendEmpty ()
687+ m .SetName ("some_custom_metric.count" ) // Uses a dot to separate name and fields
688+ m .SetEmptyGauge ()
689+ dp := m .Gauge ().DataPoints ().AppendEmpty ()
690+ dp .SetTimestamp (pcommon .NewTimestampFromTime (time .Unix (0 , 1395066363000000123 )))
691+ dp .SetIntValue (1 )
692+ m = isMetrics .Metrics ().AppendEmpty ()
693+ m .SetName ("some_custom_metric.something_else" ) // Uses a dot to separate name and fields
694+ m .SetEmptyGauge ()
695+ dp = m .Gauge ().DataPoints ().AppendEmpty ()
696+ dp .SetTimestamp (pcommon .NewTimestampFromTime (time .Unix (0 , 1395066363000000123 )))
697+ dp .SetDoubleValue (2.3 )
698+
699+ assertMetricsEqual (t , expect , b .GetMetrics ())
700+ }
0 commit comments