func newSourceConfig()

in prometheus-to-sd/config/source_config.go [52:92]


func newSourceConfig(component, protocol, host, port, path string, auth AuthConfig, whitelisted, metricsPrefix string, podConfig PodConfig, whitelistedLabelsMap map[string]map[string]bool, customResourceType string, customLabels map[string]string) (*SourceConfig, error) {
	if port == "" {
		return nil, fmt.Errorf("No port provided.")
	}
	if path == "" || path == "/" {
		path = defaultMetricsPath
	}

	portNum, err := strconv.ParseUint(port, 10, 32)
	if err != nil {
		return nil, err
	}

	if len(protocol) == 0 {
		if portNum == 443 {
			protocol = "https"
		} else {
			protocol = "http"
		}
	}

	var whitelistedList []string
	if whitelisted != "" {
		whitelistedList = strings.Split(whitelisted, ",")
	}

	return &SourceConfig{
		Component:            component,
		Protocol:             protocol,
		Host:                 host,
		Port:                 uint(portNum),
		Path:                 path,
		AuthConfig:           auth,
		Whitelisted:          whitelistedList,
		WhitelistedLabelsMap: whitelistedLabelsMap,
		PodConfig:            podConfig,
		MetricsPrefix:        metricsPrefix,
		CustomResourceType:   customResourceType,
		CustomLabels:         customLabels,
	}, nil
}