func getPrometheusAddress()

in action/prometheus/metrics.go [55:79]


func getPrometheusAddress() (string, error) {
	file, err := os.ReadFile(utils.ConfigFileName)
	if err != nil {
		return "", fmt.Errorf("failed to read config.yml: %v", err)
	}

	// Parse the configuration
	var config model.Config
	if err = yaml.Unmarshal(file, &config); err != nil {
		return "", fmt.Errorf("failed to unmarshal YAML: %v", err)
	}

	// Extract Prometheus address based on context
	contextName := config.Context.Prometheus
	var contextPath string
	for _, server := range config.Prometheus.Servers {
		if server.Name == contextName {
			contextPath = server.Address
		}
	}
	if contextPath == "" {
		return "", fmt.Errorf("failed to find Prometheus context in config.yml")
	}
	return contextPath, nil
}