From 94ea14d54082d241438ceb14fc8afd58a40e9403 Mon Sep 17 00:00:00 2001 From: naman-jain-15 Date: Fri, 28 Jun 2024 10:42:02 +0530 Subject: [PATCH] service updated --- .../datadogmetricreceiver/service/service.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/receiver/datadogmetricreceiver/service/service.go b/receiver/datadogmetricreceiver/service/service.go index d442656e979e..7027240e6531 100644 --- a/receiver/datadogmetricreceiver/service/service.go +++ b/receiver/datadogmetricreceiver/service/service.go @@ -2,15 +2,13 @@ package service import ( "fmt" - "log" - "strings" - "time" - processv1 "github.com/DataDog/agent-payload/v5/process" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogmetricreceiver/helpers" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp" + "log" + "strings" ) // Constants for Service metrics @@ -66,13 +64,13 @@ func GetOtlpExportReqFromDatadogServiceData(origin string, key string, Body inte scopeMetrics := helpers.AppendInstrScope(&rm) setHostK8sAttributes(metricAttributes, clusterName, clusterID) - appendServiceMetrics(&scopeMetrics, resourceAttributes, metricAttributes, service) + appendServiceMetrics(&scopeMetrics, resourceAttributes, metricAttributes, service, timestamp) } return pmetricotlp.NewExportRequestFromMetrics(metrics), nil } -func appendServiceMetrics(scopeMetrics *pmetric.ScopeMetrics, resourceAttributes pcommon.Map, metricAttributes pcommon.Map, service *processv1.Service) { +func appendServiceMetrics(scopeMetrics *pmetric.ScopeMetrics, resourceAttributes pcommon.Map, metricAttributes pcommon.Map, service *processv1.Service, timestamp int64) { scopeMetric := scopeMetrics.Metrics().AppendEmpty() scopeMetric.SetName(serviceMetricPortCount) @@ -93,17 +91,13 @@ func appendServiceMetrics(scopeMetrics *pmetric.ScopeMetrics, resourceAttributes metricAttributes.PutStr(serviceMetricType, specDetails.GetType()) metricAttributes.PutStr(serviceMetricClusterIP, specDetails.GetClusterIP()) metricAttributes.PutStr(serviceMetricPortsList, convertPortRulesToString(specDetails.GetPorts())) - - currentTime := time.Now() - milliseconds := (currentTime.UnixNano() / int64(time.Millisecond)) * 1000000 - createTime := (milliseconds / 1000000000) - metadata.GetCreationTimestamp() - metricAttributes.PutInt(serviceMetricCreateTime, createTime) + metricAttributes.PutInt(serviceMetricCreateTime, helpers.CalculateCreateTime(metadata.GetCreationTimestamp())) var dataPoints pmetric.NumberDataPointSlice gauge := scopeMetric.SetEmptyGauge() dataPoints = gauge.DataPoints() dp := dataPoints.AppendEmpty() - dp.SetTimestamp(pcommon.Timestamp(milliseconds)) + dp.SetTimestamp(pcommon.Timestamp(timestamp)) dp.SetIntValue(metricVal) attributeMap := dp.Attributes()