func()

in confgenerator/otel/modular.go [54:103]


func (c ModularConfig) Generate() (string, error) {
	receivers := map[string]interface{}{}
	processors := map[string]interface{}{}
	exporters := map[string]interface{}{}
	pipelines := map[string]interface{}{}
	service := map[string]map[string]interface{}{
		"pipelines": pipelines,
		"telemetry": {
			"metrics": map[string]interface{}{
				"address": fmt.Sprintf("0.0.0.0:%d", c.SelfMetricsPort),
			},
		},
	}

	configMap := map[string]interface{}{
		"receivers":  receivers,
		"processors": processors,
		"exporters":  exporters,
		"service":    service,
	}

	for key, receiverPipeline := range c.ReceiverPipelines {
		receiverName := receiverPipeline.Receiver.name(key)
		var receiverProcessorNames []string
		for i, processor := range receiverPipeline.Processors {
			name := processor.name(fmt.Sprintf("%s_%d", key, i))
			receiverProcessorNames = append(receiverProcessorNames, name)
			processors[name] = processor.Config
		}
		receivers[receiverName] = receiverPipeline.Receiver.Config

		// Keep track of all the processors we're adding to the config.
		var processorNames []string
		processorNames = append(processorNames, receiverProcessorNames...)

		exporters["googlemanagedprometheus"] = c.Exporter.Config
		pipelines["metrics/"+key] = map[string]interface{}{
			"receivers":  []string{receiverName},
			"processors": processorNames,
			"exporters":  []string{"googlemanagedprometheus"},
		}
	}

	out, err := configToYaml(configMap)
	// TODO: Return []byte
	if err != nil {
		return "", err
	}
	return string(out), nil
}