16
16
errNoStartTimeMetrics = errors .New ("start_time metric is missing" )
17
17
errNoDataPointsStartTimeMetric = errors .New ("start time metric with no data points" )
18
18
errUnsupportedTypeStartTimeMetric = errors .New ("unsupported data type for start time metric" )
19
+
20
+ // approximateCollectorStartTime is the approximate start time of the collector. Used
21
+ // as a fallback start time for metrics that don't have a start time set.
22
+ // Set when the component is initialized.
23
+ approximateCollectorStartTime * time.Time
19
24
)
20
25
26
+ func init () {
27
+ now := time .Now ()
28
+ approximateCollectorStartTime = & now
29
+ }
30
+
21
31
type startTimeMetricAdjuster struct {
22
32
startTimeMetricRegex * regexp.Regexp
23
33
fallbackStartTime * time.Time
@@ -28,8 +38,7 @@ type startTimeMetricAdjuster struct {
28
38
func NewStartTimeMetricAdjuster (logger * zap.Logger , startTimeMetricRegex * regexp.Regexp , useCollectorStartTimeFallback bool ) MetricsAdjuster {
29
39
var fallbackStartTime * time.Time
30
40
if useCollectorStartTimeFallback {
31
- now := time .Now ()
32
- fallbackStartTime = & now
41
+ fallbackStartTime = approximateCollectorStartTime
33
42
}
34
43
return & startTimeMetricAdjuster {
35
44
startTimeMetricRegex : startTimeMetricRegex ,
@@ -44,7 +53,7 @@ func (stma *startTimeMetricAdjuster) AdjustMetrics(metrics pmetric.Metrics) erro
44
53
if stma .fallbackStartTime == nil {
45
54
return err
46
55
}
47
- stma .logger .Warn ("Couldn't get start time for metrics. Using fallback start time." , zap .Error (err ))
56
+ stma .logger .Info ("Couldn't get start time for metrics. Using fallback start time." , zap .Error (err ))
48
57
startTime = float64 (stma .fallbackStartTime .Unix ())
49
58
}
50
59
0 commit comments