Skip to content

Commit

Permalink
service updated
Browse files Browse the repository at this point in the history
  • Loading branch information
naman-jain-15 committed Jun 28, 2024
1 parent 3d2e341 commit 94ea14d
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions receiver/datadogmetricreceiver/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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()
Expand Down

0 comments on commit 94ea14d

Please sign in to comment.