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

Document, test, and fix required environment variables for CUA #71

Merged
merged 8 commits into from
Jun 14, 2022
5 changes: 4 additions & 1 deletion cmd/circonus-unified-agent/circonus-unified-agent_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ func (p *program) Stop(s service.Service) error {

func runAsWindowsService(inputFilters, outputFilters, aggregatorFilters, processorFilters []string) {
programFiles := os.Getenv("ProgramFiles")
if programFiles == "" { // Should never happen
if programFiles == "" {
programFiles = "C:\\Program Files"
log.Print("I! ProgramFiles environment variable is unset")
} else {
log.Print("I! ProgramFiles found with value: " + programFiles)
}
svcConfig := &service.Config{
Name: *fServiceName,
Expand Down
6 changes: 5 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ var (

func init() {
defaultPluginsEnabled = strings.ToLower(os.Getenv("ENABLE_DEFAULT_PLUGINS")) != "false"
if !defaultPluginsEnabled {
log.Print("I! Default plugins disabled")
}
}

// Config specifies the URL/user/password for the database that circonus-unified-agent
Expand Down Expand Up @@ -772,7 +775,8 @@ func getDefaultConfigPath() (string, error) {
etcfile := "/opt/circonus/unified-agent/etc/circonus-unified-agent.conf"
if runtime.GOOS == "windows" {
programFiles := os.Getenv("ProgramFiles")
if programFiles == "" { // Should never happen
if programFiles == "" {
log.Print("I! ProgramFiles Environment var is unset")
programFiles = `C:\Program Files`
}
etcfile = programFiles + `\Circonus\Circonus-Unified-Agent\etc\circonus-unified-agent.conf`
Expand Down
19 changes: 19 additions & 0 deletions docs/ENVIRONMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# CUA Env vars


## Windows

- "ProgramFiles" - if unset, logs an error
- "WINDIR" - if unset, logs an error

## Linux

- "HOST_PROC" - returns "/proc" if unset.
- "HOST_MOUNT_PREFIX" - plugins/inputs/system/ps used for host volume mounts

## Universal

- "ENABLE_DEFAULT_PLUGINS" - if set to "false", disables default plugins
- "CUA_CONFIG_PATH" - if set, overrides any other config file
- "ECS_CONTAINER_METADATA_URI" - if set, enables ecs v3 endpoint. if unset, v2 is used.
- "DOCKER_HOST" - if unset, defaults to "localhost"
3 changes: 3 additions & 0 deletions plugins/common/shim/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func expandEnvVars(contents []byte) string {

func getEnv(key string) string {
v := os.Getenv(key)
if v == "" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it matters for this or not, but os.Getenv() will return an empty string whether the environment variable is set to an empty string or just does not exist. If you need to distinguish these two cases there is os.LookupEnv().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to hit "comment" on my PR about this function heh.

This is a pretty generic function. Are we expecting ENV vars to always be set? If someone is driving this off config, rather than env, this will be noisy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to hit "comment" on my PR about this function heh.

This is a pretty generic function. Are we expecting ENV vars to always be set? If someone is driving this off config, rather than env, this will be noisy.

my understanding of the shim is that it's used to expand ENV vars in the config. In this, it will notify if any env var in the config is empty or unset.

log.Print("I! Read empty Environment var: " + key)
}

return envVarEscaper.Replace(v)
}
Expand Down
3 changes: 3 additions & 0 deletions plugins/inputs/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ecs
import (
"context"
"fmt"
"log"
"os"
"strings"
"time"
Expand Down Expand Up @@ -163,6 +164,8 @@ func resolveEndpoint(ecs *Ecs) {
return
}

log.Print("I! ECS_CONTAINER_METADATA_URI Environment var is unset, using v2 ecs endpoint")

// Use v2 endpoint if nothing else is available.
ecs.EndpointURL = v2Endpoint
ecs.metadataVersion = 2
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/snmp_deprecated/snmp_mocks_generate.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build generate
// +build generate

package main
Expand Down
2 changes: 2 additions & 0 deletions plugins/inputs/synproxy/synproxy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package synproxy

import (
"log"
"os"
"path"

Expand Down Expand Up @@ -30,6 +31,7 @@ func getHostProc() string {
if os.Getenv("HOST_PROC") != "" {
procPath = os.Getenv("HOST_PROC")
}
log.Print("I! Using default procPath: " + procPath)
return procPath
}

Expand Down
Loading