parent
beba9b9228
commit
1585ea3734
|
@ -280,6 +280,8 @@ func (c *BootstrapConfig) generateStatsSinkJSON(name string, typeName string, ad
|
|||
// Resolve address ENV var
|
||||
if len(addr) > 2 && addr[0] == '$' {
|
||||
addr = os.Getenv(addr[1:])
|
||||
} else {
|
||||
addr = os.Expand(addr, statsSinkEnvMapping)
|
||||
}
|
||||
|
||||
u, err := url.Parse(addr)
|
||||
|
@ -318,6 +320,18 @@ func (c *BootstrapConfig) generateStatsSinkJSON(name string, typeName string, ad
|
|||
}`, 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.
|
||||
func resourceTagSpecifiers(omitDeprecatedTags bool) ([]string, error) {
|
||||
const (
|
||||
|
|
|
@ -485,6 +485,40 @@ func TestBootstrapConfig_ConfigureArgs(t *testing.T) {
|
|||
},
|
||||
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",
|
||||
input: BootstrapConfig{
|
||||
|
|
Loading…
Reference in New Issue