mirror of https://github.com/hashicorp/consul
parent
11f60c46a3
commit
39f448589d
|
@ -280,6 +280,8 @@ func (c *BootstrapConfig) generateStatsSinkJSON(name string, typeName string, ad
|
||||||
// Resolve address ENV var
|
// Resolve address ENV var
|
||||||
if len(addr) > 2 && addr[0] == '$' {
|
if len(addr) > 2 && addr[0] == '$' {
|
||||||
addr = os.Getenv(addr[1:])
|
addr = os.Getenv(addr[1:])
|
||||||
|
} else {
|
||||||
|
addr = os.Expand(addr, statsSinkEnvMapping)
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := url.Parse(addr)
|
u, err := url.Parse(addr)
|
||||||
|
@ -318,6 +320,18 @@ func (c *BootstrapConfig) generateStatsSinkJSON(name string, typeName string, ad
|
||||||
}`, nil
|
}`, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func statsSinkEnvMapping(s string) string {
|
||||||
|
allowedStatsSinkEnvVars := map[string]bool{
|
||||||
|
"HOST_IP": true,
|
||||||
|
}
|
||||||
|
|
||||||
|
if !allowedStatsSinkEnvVars[s] {
|
||||||
|
// if the specified env var isn't explicitly allowed, unexpand it
|
||||||
|
return fmt.Sprintf("${%s}", s)
|
||||||
|
}
|
||||||
|
return os.Getenv(s)
|
||||||
|
}
|
||||||
|
|
||||||
// resourceTagSpecifiers returns patterns used to generate tags from cluster and filter metric names.
|
// resourceTagSpecifiers returns patterns used to generate tags from cluster and filter metric names.
|
||||||
func resourceTagSpecifiers(omitDeprecatedTags bool) ([]string, error) {
|
func resourceTagSpecifiers(omitDeprecatedTags bool) ([]string, error) {
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -485,6 +485,40 @@ func TestBootstrapConfig_ConfigureArgs(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "simple-statsd-sink-inline-env-allowed",
|
||||||
|
input: BootstrapConfig{
|
||||||
|
StatsdURL: "udp://$HOST_IP:9125",
|
||||||
|
},
|
||||||
|
env: []string{"HOST_IP=127.0.0.1"},
|
||||||
|
wantArgs: BootstrapTplArgs{
|
||||||
|
StatsConfigJSON: defaultStatsConfigJSON,
|
||||||
|
StatsSinksJSON: `[{
|
||||||
|
"name": "envoy.stat_sinks.statsd",
|
||||||
|
"typedConfig": {
|
||||||
|
"@type": "type.googleapis.com/envoy.config.metrics.v3.StatsdSink",
|
||||||
|
"address": {
|
||||||
|
"socket_address": {
|
||||||
|
"address": "127.0.0.1",
|
||||||
|
"port_value": 9125
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]`,
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "simple-statsd-sink-inline-env-disallowed",
|
||||||
|
input: BootstrapConfig{
|
||||||
|
StatsdURL: "udp://$HOST_ADDRESS:9125",
|
||||||
|
},
|
||||||
|
env: []string{"HOST_ADDRESS=127.0.0.1"},
|
||||||
|
wantArgs: BootstrapTplArgs{
|
||||||
|
StatsConfigJSON: defaultStatsConfigJSON,
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "simple-dogstatsd-sink",
|
name: "simple-dogstatsd-sink",
|
||||||
input: BootstrapConfig{
|
input: BootstrapConfig{
|
||||||
|
|
Loading…
Reference in New Issue