diff --git a/receiver/ntpreceiver/documentation.md b/receiver/ntpreceiver/documentation.md index b999ef23396d..01463c1de0cf 100644 --- a/receiver/ntpreceiver/documentation.md +++ b/receiver/ntpreceiver/documentation.md @@ -14,11 +14,11 @@ metrics: ### ntp.offset -Time difference between local and NTP server clocks in seconds. +Time difference between local and NTP server clocks | Unit | Metric Type | Value Type | | ---- | ----------- | ---------- | -| s | Gauge | Double | +| ns | Gauge | Int | ## Resource Attributes diff --git a/receiver/ntpreceiver/generated_package_test.go b/receiver/ntpreceiver/generated_package_test.go index 02b7cfbd4e87..4fd492418ffd 100644 --- a/receiver/ntpreceiver/generated_package_test.go +++ b/receiver/ntpreceiver/generated_package_test.go @@ -3,9 +3,8 @@ package ntpreceiver import ( - "testing" - "go.uber.org/goleak" + "testing" ) func TestMain(m *testing.M) { diff --git a/receiver/ntpreceiver/internal/metadata/generated_metrics.go b/receiver/ntpreceiver/internal/metadata/generated_metrics.go index 3c3db06adf0a..0b77e5ddfea6 100644 --- a/receiver/ntpreceiver/internal/metadata/generated_metrics.go +++ b/receiver/ntpreceiver/internal/metadata/generated_metrics.go @@ -21,19 +21,19 @@ type metricNtpOffset struct { // init fills ntp.offset metric with initial data. func (m *metricNtpOffset) init() { m.data.SetName("ntp.offset") - m.data.SetDescription("Time difference between local and NTP server clocks in seconds.") - m.data.SetUnit("s") + m.data.SetDescription("Time difference between local and NTP server clocks") + m.data.SetUnit("ns") m.data.SetEmptyGauge() } -func (m *metricNtpOffset) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val float64) { +func (m *metricNtpOffset) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { if !m.config.Enabled { return } dp := m.data.Gauge().DataPoints().AppendEmpty() dp.SetStartTimestamp(start) dp.SetTimestamp(ts) - dp.SetDoubleValue(val) + dp.SetIntValue(val) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -210,7 +210,7 @@ func (mb *MetricsBuilder) Emit(options ...ResourceMetricsOption) pmetric.Metrics } // RecordNtpOffsetDataPoint adds a data point to ntp.offset metric. -func (mb *MetricsBuilder) RecordNtpOffsetDataPoint(ts pcommon.Timestamp, val float64) { +func (mb *MetricsBuilder) RecordNtpOffsetDataPoint(ts pcommon.Timestamp, val int64) { mb.metricNtpOffset.recordDataPoint(mb.startTime, ts, val) } diff --git a/receiver/ntpreceiver/internal/metadata/generated_metrics_test.go b/receiver/ntpreceiver/internal/metadata/generated_metrics_test.go index 55106e571e49..4f92fc0d4c33 100644 --- a/receiver/ntpreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/ntpreceiver/internal/metadata/generated_metrics_test.go @@ -101,13 +101,13 @@ func TestMetricsBuilder(t *testing.T) { validatedMetrics["ntp.offset"] = true assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "Time difference between local and NTP server clocks in seconds.", ms.At(i).Description()) - assert.Equal(t, "s", ms.At(i).Unit()) + assert.Equal(t, "Time difference between local and NTP server clocks", ms.At(i).Description()) + assert.Equal(t, "ns", ms.At(i).Unit()) dp := ms.At(i).Gauge().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) - assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType()) - assert.InDelta(t, float64(1), dp.DoubleValue(), 0.01) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) } } }) diff --git a/receiver/ntpreceiver/metadata.yaml b/receiver/ntpreceiver/metadata.yaml index feded55ee316..f54de24bafdd 100644 --- a/receiver/ntpreceiver/metadata.yaml +++ b/receiver/ntpreceiver/metadata.yaml @@ -16,10 +16,10 @@ resource_attributes: metrics: ntp.offset: - description: Time difference between local and NTP server clocks in seconds. - unit: "s" + description: Time difference between local and NTP server clocks + unit: "ns" gauge: - value_type: double + value_type: int enabled: true tests: \ No newline at end of file diff --git a/receiver/ntpreceiver/receiver.go b/receiver/ntpreceiver/receiver.go index 4f0c4f359991..d52605431b46 100644 --- a/receiver/ntpreceiver/receiver.go +++ b/receiver/ntpreceiver/receiver.go @@ -30,8 +30,7 @@ func (s *scraper) scrape(context.Context) (pmetric.Metrics, error) { if err != nil { return pmetric.Metrics{}, err } - clockOffset := response.ClockOffset.Seconds() - s.mb.RecordNtpOffsetDataPoint(pcommon.NewTimestampFromTime(time.Now()), clockOffset) + s.mb.RecordNtpOffsetDataPoint(pcommon.NewTimestampFromTime(time.Now()), response.ClockOffset.Nanoseconds()) s.mb.NewResourceBuilder().SetNtpHost(s.endpoint) return s.mb.Emit(), nil }