From 3d2e3413c5e1be92fa33462de01a9b474e47b404 Mon Sep 17 00:00:00 2001 From: naman-jain-15 Date: Fri, 28 Jun 2024 10:41:45 +0530 Subject: [PATCH] sync reciver commits --- .../metricsv2translator.go | 15 +- receiver/datadogmetricreceiver/roles/roles.go | 178 ------------------ 2 files changed, 14 insertions(+), 179 deletions(-) diff --git a/receiver/datadogmetricreceiver/metricsv2translator.go b/receiver/datadogmetricreceiver/metricsv2translator.go index cfc4dca9912a..8531174e0e5a 100644 --- a/receiver/datadogmetricreceiver/metricsv2translator.go +++ b/receiver/datadogmetricreceiver/metricsv2translator.go @@ -79,7 +79,7 @@ func GetOtlpExportReqFromDatadogV2Metrics(origin, key string, ddReq metricsV2.Me if helpers.SkipDatadogMetrics(s.GetMetric(), int32(s.GetType())) { continue } - + rm := resourceMetrics.AppendEmpty() resourceAttributes := rm.Resource().Attributes() commonResourceAttributes := helpers.CommonResourceAttributes{ @@ -105,6 +105,19 @@ func GetOtlpExportReqFromDatadogV2Metrics(origin, key string, ddReq metricsV2.Me return pmetricotlp.NewExportRequestFromMetrics(metrics), nil } +func tagsToMap(tags []string) map[string]string { + tagMap := make(map[string]string) + + for _, tag := range tags { + parts := strings.Split(tag, ":") + if len(parts) == 2 { + tagMap[parts[0]] = parts[1] + } + } + + return tagMap +} + func translateMetric(s *metricsV2.MetricPayload_MetricSeries, metricHost string, tagMap map[string]string, resourceAttributes, metricAttributes pcommon.Map) { for _, translator := range translators { if translator(s, metricHost, tagMap, resourceAttributes, metricAttributes) { diff --git a/receiver/datadogmetricreceiver/roles/roles.go b/receiver/datadogmetricreceiver/roles/roles.go index eabadbe56581..5b3f685d2a2f 100644 --- a/receiver/datadogmetricreceiver/roles/roles.go +++ b/receiver/datadogmetricreceiver/roles/roles.go @@ -133,181 +133,3 @@ func convertRulesToString(rules []*processv1.PolicyRule) string { return result.String() } - -// func getOtlpExportReqFromDatadogRolesData(origin string, key string, ddReq *processv1.CollectorRole) (pmetricotlp.ExportRequest, error) { -// // assumption is that host is same for all the metrics in a given request - -// roles := ddReq.GetRoles() - -// if len(roles) == 0 { -// log.Println("no roles found so skipping") -// return pmetricotlp.ExportRequest{}, ErrNoMetricsInPayload -// } - -// metrics := pmetric.NewMetrics() -// resourceMetrics := metrics.ResourceMetrics() - -// for _, role := range roles { -// rm := resourceMetrics.AppendEmpty() -// resourceAttributes := rm.Resource().Attributes() - -// cluster_name := ddReq.GetClusterName() -// cluster_id := ddReq.GetClusterId() - -// commonResourceAttributes := commonResourceAttributes{ -// origin: origin, -// ApiKey: key, -// mwSource: "datadog", -// //host: "trial", -// } -// setMetricResourceAttributes(resourceAttributes, commonResourceAttributes) - -// scopeMetrics := rm.ScopeMetrics().AppendEmpty() -// instrumentationScope := scopeMetrics.Scope() -// instrumentationScope.SetName("mw") -// instrumentationScope.SetVersion("v0.0.1") -// scopeMetric := scopeMetrics.Metrics().AppendEmpty() -// //scopeMetric.SetName("kubernetes_state.role.count") -// scopeMetric.SetName("ddk8s.role.count") -// //scopeMetric.SetUnit(s.GetUnit()) - -// metricAttributes := pcommon.NewMap() - -// metadata := role.GetMetadata() -// resourceAttributes.PutStr("ddk8s.role.uid", metadata.GetUid()) -// metricAttributes.PutStr("ddk8s.role.namespace", metadata.GetNamespace()) -// metricAttributes.PutStr("ddk8s.role.cluster.id", cluster_id) -// metricAttributes.PutStr("ddk8s.role.cluster.name", cluster_name) -// metricAttributes.PutStr("ddk8s.role.name", metadata.GetName()) - -// currentTime := time.Now() -// milliseconds := (currentTime.UnixNano() / int64(time.Millisecond)) * 1000000 -// // fmt.Println("milliseconds",milliseconds) -// // fmt.Println("creation",metadata.GetCreationTimestamp() * 1000) -// createtime := (int64(milli//"time" -// //fmt.Println("diff is " , diff) - -// for _, tag := range role.GetTags() { - -// parts := strings.Split(tag, ":") -// if len(parts) != 2 { -// continue -// } - -// metricAttributes.PutStr(parts[0], parts[1]) -// } - -// rules := role.GetRules() -// metricAttributes.PutStr("ddk8s.role.rules", convertRulesToString(rules)) -// metricAttributes.PutStr("ddk8s.role.type", "Roles") -// metricAttributes.PutStr("ddk8s.role.labels", strings.Join(metadata.GetLabels(), "&")) -// metricAttributes.PutStr("ddk8s.role.annotations", strings.Join(metadata.GetAnnotations(), "&")) -// // current time in millis -// //fmt.Println("string is", convertRulesToString(rules)) -// var dataPoints pmetric.NumberDataPointSlice -// gauge := scopeMetric.SetEmptyGauge() -// dataPoints = gauge.DataPoints() - -// dp := dataPoints.AppendEmpty() -// dp.SetTimestamp(pcommon.Timestamp(milliseconds)) - -// dp.SetIntValue(int64(len(rules))) // setting a dummy value for this metric as only resource attribute needed -// attributeMap := dp.Attributes() -// metricAttributes.CopyTo(attributeMap) -// } - -// // metrics := pmetric.NewMetrics() -// // resourceMetrics := metrics.ResourceMetrics() -// // rm := resourceMetrics.AppendEmpty() -// // resourceAttributes := rm.Resource().Attributes() - -// // // assumption is that host is same for all the metrics in a given request -// // // var metricHost string -// // // metricHost = input.hostname - -// // // var metricHost string - -// // // for _, tag := range ddReq.GetTags() { - -// // // parts := strings.Split(tag, ":") -// // // if len(parts) != 2 { -// // // continue -// // // } - -// // // resourceAttributes.PutStr(parts[0], parts[1]) -// // // } - -// // // resourceAttributes.PutStr("kube_cluster_name", ddReq.GetClusterName()) -// // // resourceAttributes.PutStr("kube_cluster_id", ddReq.GetClusterId()) - -// // cluster_name := ddReq.GetClusterName() -// // cluster_id := ddReq.GetClusterId() - -// // commonResourceAttributes := commonResourceAttributes{ -// // origin: origin, -// // ApiKey: key, -// // mwSource: "datadog", -// // //host: "trial", -// // } -// // setMetricResourceAttributes(resourceAttributes, commonResourceAttributes) - -// // scopeMetrics := rm.ScopeMetrics().AppendEmpty() -// // instrumentationScope := scopeMetrics.Scope() -// // instrumentationScope.SetName("mw") -// // instrumentationScope.SetVersion("v0.0.1") - -// // for _, role := range roles { - -// // scopeMetric := scopeMetrics.Metrics().AppendEmpty() -// // //scopeMetric.SetName("kubernetes_state.role.count") -// // scopeMetric.SetName("ddk8s.role.count") -// // //scopeMetric.SetUnit(s.GetUnit()) - -// // metricAttributes := pcommon.NewMap() - -// // metadata := role.GetMetadata() -// // metricAttributes.PutStr("ddk8s.role.namespace", metadata.GetNamespace()) -// // metricAttributes.PutStr("ddk8s.role.cluster.id", cluster_id) -// // metricAttributes.PutStr("ddk8s.role.cluster.name", cluster_name) -// // metricAttributes.PutStr("ddk8s.role.uid", metadata.GetUid()) -// // metricAttributes.PutStr("ddk8s.role.name", metadata.GetName()) - -// // currentTime := time.Now() -// // milliseconds := (currentTime.UnixNano() / int64(time.Millisecond)) * 1000000 -// // // fmt.Println("milliseconds",milliseconds) -// // // fmt.Println("creation",metadata.GetCreationTimestamp() * 1000) -// // createtime := (int64(milliseconds/1000000000) - metadata.GetCreationTimestamp()) -// // //diff := milliseconds - (metadata.GetCreationTimestamp() * 1000) -// // fmt.Println("diff is ",createtime) -// // metricAttributes.PutInt("ddk8s.role.create.time", createtime) - -// // //fmt.Println("diff is " , diff) - -// // for _, tag := range role.GetTags() { - -// // parts := strings.Split(tag, ":") -// // if len(parts) != 2 { -// // continue -// // } - -// // metricAttributes.PutStr(parts[0], parts[1]) -// // } - -// // rules := role.GetRules() -// // metricAttributes.PutStr("ddk8s.role.rules", convertRulesToString(rules)) -// // // current time in millis -// // //fmt.Println("string is", convertRulesToString(rules)) -// // var dataPoints pmetric.NumberDataPointSlice -// // gauge := scopeMetric.SetEmptyGauge() -// // dataPoints = gauge.DataPoints() - -// // dp := dataPoints.AppendEmpty() -// // dp.SetTimestamp(pcommon.Timestamp(milliseconds)) - -// // dp.SetIntValue(int64(len(rules))) // setting a dummy value for this metric as only resource attribute needed -// // attributeMap := dp.Attributes() -// // metricAttributes.CopyTo(attributeMap) -// // } - -// return pmetricotlp.NewExportRequestFromMetrics(metrics), nil -// }