Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set INSTANCE name via environment variable #489

Closed
zerosoul13 opened this issue May 12, 2022 · 0 comments
Closed

Set INSTANCE name via environment variable #489

zerosoul13 opened this issue May 12, 2022 · 0 comments

Comments

@zerosoul13
Copy link

Hello,

Today I was looking to use ${INSTANCE} environment variable but only found support for ${HOST}. The reason being that ${INSTANCE} environment variable is declared in the examples/k8s/deployment.yaml file.

    spec:
      containers:
      - env:
        - name: INSTANCE
          valueFrom:
            fieldRef:
              fieldPath: metadata.name

After reading the carbon-relay-ng code https://github.com/grafana/carbon-relay-ng/blob/master/cmd/carbon-relay-ng/carbon-relay-ng.go#L74, only found support for ${HOST}

func expandVars(in string) (out string) {
	switch in {
	case "HOST":
		hostname, _ := os.Hostname()
		// in case hostname is an fqdn or has dots, only take first part
		parts := strings.SplitN(hostname, ".", 2)
		return parts[0]
	case "GRAFANA_NET_ADDR":
		return os.Getenv("GRAFANA_NET_ADDR")
	case "GRAFANA_NET_API_KEY":
		return os.Getenv("GRAFANA_NET_API_KEY")
	case "GRAFANA_NET_USER_ID":
		return os.Getenv("GRAFANA_NET_USER_ID")
	default:
		return "$" + in
	}

Would you be open to supporting a new variable instead of using the default ${HOST}?

func expandVars(in string) (out string) {
	switch in {
        case "INSTANCE":
                return os.Getenv("INSTANCE") 
	case "HOST":
		hostname, _ := os.Hostname()
		// in case hostname is an fqdn or has dots, only take first part
		parts := strings.SplitN(hostname, ".", 2)
		return parts[0]
	case "GRAFANA_NET_ADDR":
		return os.Getenv("GRAFANA_NET_ADDR")
	case "GRAFANA_NET_API_KEY":
		return os.Getenv("GRAFANA_NET_API_KEY")
	case "GRAFANA_NET_USER_ID":
		return os.Getenv("GRAFANA_NET_USER_ID")
	default:
		return "$" + in
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant