config/config.go
func resolveFilepaths(baseDir string, cfg *Config) {
	join := func(fp string) string {
		if len(fp) > 0 && !filepath.IsAbs(fp) {
			fp = filepath.Join(baseDir, fp)
		}
		return fp
	}

	for i, rf := range cfg.RuleFiles {
		cfg.RuleFiles[i] = join(rf)
	}

	tlsPaths := func(cfg *config_util.TLSConfig) {
		cfg.CAFile = join(cfg.CAFile)
		cfg.CertFile = join(cfg.CertFile)
		cfg.KeyFile = join(cfg.KeyFile)
	}
	clientPaths := func(scfg *config_util.HTTPClientConfig) {
		if scfg.BasicAuth != nil {
			scfg.BasicAuth.PasswordFile = join(scfg.BasicAuth.PasswordFile)
		}
		scfg.BearerTokenFile = join(scfg.BearerTokenFile)
		tlsPaths(&scfg.TLSConfig)
	}
	sdPaths := func(cfg *sd_config.ServiceDiscoveryConfig) {
		for _, kcfg := range cfg.KubernetesSDConfigs {
			clientPaths(&kcfg.HTTPClientConfig)
		}
		for _, mcfg := range cfg.MarathonSDConfigs {
			mcfg.AuthTokenFile = join(mcfg.AuthTokenFile)
			clientPaths(&mcfg.HTTPClientConfig)
		}
		for _, consulcfg := range cfg.ConsulSDConfigs {
			tlsPaths(&consulcfg.TLSConfig)
		}
		for _, cfg := range cfg.OpenstackSDConfigs {
			tlsPaths(&cfg.TLSConfig)
		}
		for _, cfg := range cfg.TritonSDConfigs {
			tlsPaths(&cfg.TLSConfig)
		}
		for _, filecfg := range cfg.FileSDConfigs {
			for i, fn := range filecfg.Files {
				filecfg.Files[i] = join(fn)
			}
		}
	}

	for _, cfg := range cfg.ScrapeConfigs {
		clientPaths(&cfg.HTTPClientConfig)
		sdPaths(&cfg.ServiceDiscoveryConfig)
	}
	for _, cfg := range cfg.AlertingConfig.AlertmanagerConfigs {
		clientPaths(&cfg.HTTPClientConfig)
		sdPaths(&cfg.ServiceDiscoveryConfig)
	}
	for _, cfg := range cfg.RemoteReadConfigs {
		clientPaths(&cfg.HTTPClientConfig)
	}
	for _, cfg := range cfg.RemoteWriteConfigs {
		clientPaths(&cfg.HTTPClientConfig)
	}
}
func resolveFilepaths(baseDir string, cfg *Config) {
	join := func(fp string) string {
		if len(fp) > 0 && !filepath.IsAbs(fp) {
			fp = filepath.Join(baseDir, fp)
		}
		return fp
	}

	for i, rf := range cfg.RuleFiles {
		cfg.RuleFiles[i] = join(rf)
	}

	tlsPaths := func(cfg *config_util.TLSConfig) {
		cfg.CAFile = join(cfg.CAFile)
		cfg.CertFile = join(cfg.CertFile)
		cfg.KeyFile = join(cfg.KeyFile)
	}
	clientPaths := func(scfg *config_util.HTTPClientConfig) {
		if scfg.BasicAuth != nil {
			scfg.BasicAuth.PasswordFile = join(scfg.BasicAuth.PasswordFile)
		}
		scfg.BearerTokenFile = join(scfg.BearerTokenFile)
		tlsPaths(&scfg.TLSConfig)
	}
	sdPaths := func(cfg *sd_config.ServiceDiscoveryConfig) {
		for _, kcfg := range cfg.KubernetesSDConfigs {
			clientPaths(&kcfg.HTTPClientConfig)
		}
		for _, mcfg := range cfg.MarathonSDConfigs {
			mcfg.AuthTokenFile = join(mcfg.AuthTokenFile)
			clientPaths(&mcfg.HTTPClientConfig)
		}
		for _, consulcfg := range cfg.ConsulSDConfigs {
			tlsPaths(&consulcfg.TLSConfig)
		}
		for _, cfg := range cfg.OpenstackSDConfigs {
			tlsPaths(&cfg.TLSConfig)
		}
		for _, cfg := range cfg.TritonSDConfigs {
			tlsPaths(&cfg.TLSConfig)
		}
		for _, filecfg := range cfg.FileSDConfigs {
			for i, fn := range filecfg.Files {
				filecfg.Files[i] = join(fn)
			}
		}
	}

	for _, cfg := range cfg.ScrapeConfigs {
		clientPaths(&cfg.HTTPClientConfig)
		sdPaths(&cfg.ServiceDiscoveryConfig)
	}
	for _, cfg := range cfg.AlertingConfig.AlertmanagerConfigs {
		clientPaths(&cfg.HTTPClientConfig)
		sdPaths(&cfg.ServiceDiscoveryConfig)
	}
	for _, cfg := range cfg.RemoteReadConfigs {
		clientPaths(&cfg.HTTPClientConfig)
	}
	for _, cfg := range cfg.RemoteWriteConfigs {
		clientPaths(&cfg.HTTPClientConfig)
	}
}
// resolveFilepaths joins all relative paths in a configuration
// with a given base directory.