Skip to content

Commit

Permalink
sync reciver commits
Browse files Browse the repository at this point in the history
  • Loading branch information
naman-jain-15 committed Jun 28, 2024
1 parent b10c9b3 commit 3d2e341
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 179 deletions.
15 changes: 14 additions & 1 deletion receiver/datadogmetricreceiver/metricsv2translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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) {
Expand Down
178 changes: 0 additions & 178 deletions receiver/datadogmetricreceiver/roles/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// }

0 comments on commit 3d2e341

Please sign in to comment.