func()

in translator/translate/otel/processor/metricstransformprocessor/translator.go [86:230]


func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) {
	cfg := t.factory.CreateDefaultConfig().(*metricstransformprocessor.Config)
	if t.name == common.PipelineNameContainerInsightsJmx {
		return common.GetYamlFileToYamlConfig(cfg, metricTransformJmxConfig)
	} else if t.name == common.AppSignals {
		return common.GetYamlFileToYamlConfig(cfg, appSignalsRuntimeConfig)
	}

	var transformRules []map[string]interface{}
	if t.name == common.PipelineNameContainerInsights {
		transformRules = []map[string]interface{}{
			{
				"include":                   "apiserver_request_total",
				"match_type":                "regexp",
				"experimental_match_labels": map[string]string{"code": "^5.*"},
				"action":                    "insert",
				"new_name":                  "apiserver_request_total_5xx",
			},
		}

		if awscontainerinsight.EnhancedContainerInsightsEnabled(conf) {
			for oldNvmeMetric, newNvmeMetric := range renameMapForNvme {
				transformRules = append(transformRules, map[string]interface{}{
					"include":  oldNvmeMetric,
					"action":   "update",
					"new_name": containerinsightscommon.MetricName(containerinsightscommon.TypeNode, newNvmeMetric),
					"operations": []map[string]interface{}{{
						"action":    "add_label",
						"new_label": containerinsightscommon.MetricType,
						"new_value": containerinsightscommon.TypeNodeEBS,
					}},
				})
			}

		}

		if awscontainerinsight.AcceleratedComputeMetricsEnabled(conf) {
			// appends DCGM metric transform rules for each metric type (container/pod/node) with following format:
			// {
			//		"include":  "DCGM_FI_DEV_GPU_UTIL",
			//		"action":   "insert",
			//		"new_name": "container_gpu_utilization",
			//		"operations": [
			//     		{
			//				"action":   "add_label",
			//				"new_label": "Type",
			//				"new_value": "ContainerGPU",
			//			},
			//			<additional operations>...
			//      ]
			//	},
			for old, new := range renameMapForDcgm {
				var operations []map[string]interface{}
				// convert decimals to percent
				if new == containerinsightscommon.GpuMemUtilization {
					operations = append(operations, map[string]interface{}{
						"action":             "experimental_scale_value",
						"experimental_scale": 100,
					})
				} else if new == containerinsightscommon.GpuMemTotal || new == containerinsightscommon.GpuMemUsed {
					operations = append(operations, map[string]interface{}{
						"action":             "experimental_scale_value",
						"experimental_scale": 1024 * 1024,
					})
				}
				for _, t := range metricDuplicateTypes {
					transformRules = append(transformRules, map[string]interface{}{
						"include":  old,
						"action":   "insert",
						"new_name": containerinsightscommon.MetricName(t, new),
						"operations": append([]map[string]interface{}{
							{
								"action":    "add_label",
								"new_label": containerinsightscommon.MetricType,
								"new_value": t,
							},
						}, operations...),
					})
				}
			}

			for oldName, newName := range renameMapForNeuronMonitor {
				var operations []map[string]interface{}
				if newName == containerinsightscommon.NeuronCoreUtilization {
					operations = append(operations, map[string]interface{}{
						"action":             "experimental_scale_value",
						"experimental_scale": 100,
					})
				}

				transformRules = append(transformRules, map[string]interface{}{
					"include":  oldName,
					"action":   "update",
					"new_name": newName,
					"operations": append([]map[string]interface{}{},
						operations...),
				})
			}
		}
	} else if t.name == common.PipelineNameJmx {
		transformRules = []map[string]interface{}{
			{
				"include": "tomcat.sessions",
				"action":  "update",
				"operations": []map[string]interface{}{
					{
						"action":           "aggregate_labels",
						"aggregation_type": "sum",
					},
					{
						"action": "delete_label_value",
						"label":  "context",
					},
				},
			},
			{
				"include": "tomcat.rejected_sessions",
				"action":  "update",
				"operations": []map[string]interface{}{
					{
						"action":           "aggregate_labels",
						"aggregation_type": "sum",
					},
					{
						"action": "delete_label_value",
						"label":  "context",
					},
				},
			},
		}
	}

	if len(transformRules) == 0 {
		return nil, fmt.Errorf("no transform rules for %s", t.name)
	}

	c := confmap.NewFromStringMap(map[string]interface{}{
		"transforms": transformRules,
	})
	if err := c.Unmarshal(&cfg); err != nil {
		return nil, fmt.Errorf("unable to unmarshal into metricstransform config: %w", err)
	}

	return cfg, nil
}