You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/01/24 09:37:52 UTC
[GitHub] [skywalking-satellite] EvanLjp opened a new pull request #20: override config by env
EvanLjp opened a new pull request #20:
URL: https://github.com/apache/skywalking-satellite/pull/20
override config by env
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-satellite] wu-sheng merged pull request #20: override config by env
Posted by GitBox <gi...@apache.org>.
wu-sheng merged pull request #20:
URL: https://github.com/apache/skywalking-satellite/pull/20
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-satellite] gxthrj commented on a change in pull request #20: override config by env
Posted by GitBox <gi...@apache.org>.
gxthrj commented on a change in pull request #20:
URL: https://github.com/apache/skywalking-satellite/pull/20#discussion_r563289607
##########
File path: configs/satellite_config.yaml
##########
@@ -45,18 +49,18 @@ pipes:
plugin_name: "grpc-nativelog-receiver"
queue:
plugin_name: "mmap-queue"
- segment_size: 524288
- max_in_mem_segments: 6
+ segment_size: ${SATELLITE_MMAP_QUEUE_SIZE:524288}
+ max_in_mem_segments: ${SATELLITE_MMAP_QUEUE_MAX_IN_MEM_SEGMENTS:6}
queue_dir: "pipe1-log-grpc-receiver-queue"
processor:
filters:
sender:
fallbacker:
plugin_name: none-fallbacker
- flush_time: 1000
- max_buffer_size: 200
- min_flush_events: 100
+ flush_time: ${SATELLITE_PIPE1_SENDER_FLUSH_TIME:1000}
+ max_buffer_size: ${SATELLITE_PIPE1_SENDER_MAX_BUFFER_SIZE:200}
+ min_flush_events: ${SATELLITE_PIPE1_SENDER_MIN_FLUSH_EVENTS:100}
client_name: kafka-client
forwarders:
- plugin_name: nativelog-kafka-forwarder
- topic: log-topic
\ No newline at end of file
+ topic: ${SATELLITE_NATIVELOG-TOPIC:log-topic}
Review comment:
No new line at the end of the file.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-satellite] EvanLjp commented on a change in pull request #20: override config by env
Posted by GitBox <gi...@apache.org>.
EvanLjp commented on a change in pull request #20:
URL: https://github.com/apache/skywalking-satellite/pull/20#discussion_r564593938
##########
File path: internal/satellite/config/override_by_env_test.go
##########
@@ -0,0 +1,200 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package config
+
+import (
+ "os"
+ "reflect"
+ "regexp"
+ "strings"
+ "testing"
+
+ "github.com/google/go-cmp/cmp"
+)
+
+func Test_overrideString(t *testing.T) {
Review comment:
fixed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-satellite] kezhenxu94 commented on a change in pull request #20: override config by env
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #20:
URL: https://github.com/apache/skywalking-satellite/pull/20#discussion_r563677687
##########
File path: internal/satellite/config/override_by_env_test.go
##########
@@ -0,0 +1,200 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package config
+
+import (
+ "os"
+ "reflect"
+ "regexp"
+ "strings"
+ "testing"
+
+ "github.com/google/go-cmp/cmp"
+)
+
+func Test_overrideString(t *testing.T) {
Review comment:
Seems the test doesn't cover the double quoted value (`"10"`) case
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-satellite] EvanLjp commented on a change in pull request #20: override config by env
Posted by GitBox <gi...@apache.org>.
EvanLjp commented on a change in pull request #20:
URL: https://github.com/apache/skywalking-satellite/pull/20#discussion_r563306735
##########
File path: internal/satellite/config/override_by_env.go
##########
@@ -0,0 +1,114 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package config
+
+import (
+ "os"
+ "regexp"
+ "strconv"
+ "strings"
+
+ "github.com/spf13/viper"
+)
+
+// ${ENV:defaultVal} pattern is supported to override the default value by the env config.
+// And the value would be converted to the different types, such as int, float64 ana string.
+// If you want to keep it as the string value, please decorate it with `"`.
+const RegularExpression = "${_|[A-Z]+:.*}"
+
+func overrideConfigByEnv(v *viper.Viper) error {
+ regex, err := regexp.Compile(RegularExpression)
+ if err != nil {
+ return err
+ }
+ overrideCfg := overrideMapStringInterface(v.AllSettings(), regex)
+ for key, val := range overrideCfg {
+ v.Set(key, val)
+ }
+ return nil
+}
+
+func overrideMapStringInterface(cfg map[string]interface{}, regex *regexp.Regexp) map[string]interface{} {
+ res := make(map[string]interface{})
+ for key, val := range cfg {
+ switch val := val.(type) {
+ case string:
+ res[key] = overrideString(val, regex)
+ case []interface{}:
+ res[key] = overrideSlice(val, regex)
+ case map[string]interface{}:
+ res[key] = overrideMapStringInterface(val, regex)
+ case map[interface{}]interface{}:
+ res[key] = overrideMapInterfaceInterface(val, regex)
+ default:
+ res[key] = val
+ }
+ }
+ return res
+}
+
+func overrideSlice(m []interface{}, regex *regexp.Regexp) []interface{} {
+ res := make([]interface{}, 0)
+ for _, val := range m {
+ switch val := val.(type) {
+ case map[string]interface{}:
+ res = append(res, overrideMapStringInterface(val, regex))
+ case map[interface{}]interface{}:
+ res = append(res, overrideMapInterfaceInterface(val, regex))
+ }
+ }
+ return res
+}
+
+func overrideMapInterfaceInterface(m map[interface{}]interface{}, regex *regexp.Regexp) interface{} {
+ cfg := make(map[string]interface{})
+ for key, val := range m {
+ cfg[key.(string)] = val
+ }
+ return overrideMapStringInterface(cfg, regex)
+}
+
+func overrideString(s string, regex *regexp.Regexp) interface{} {
+ if regex.MatchString(s) {
+ index := strings.Index(s, ":")
+ envName := s[2:index]
+ defaultVal := s[index+1 : len(s)-1]
+ envVal := os.Getenv(envName)
+ if envVal != "" {
+ defaultVal = envVal
+ }
+ return parseVal(defaultVal)
+ }
+ return s
+}
+
+func parseVal(val string) interface{} {
+ if intVal, err := strconv.Atoi(val); err == nil {
+ return intVal
+ } else if floatVal, err := strconv.ParseFloat(val, 64); err == nil {
+ return floatVal
+ } else if strings.EqualFold(val, "true") {
+ return true
+ } else if strings.EqualFold(val, "false") {
+ return false
+ } else if strings.HasPrefix(val, "\"") && strings.HasSuffix(val, "\"") {
+ return val[1 : len(val)-1]
Review comment:
the comment is `If you want to keep it as the string value, please decorate it with `"`.`
For example, 2.1.1 is a string rather than a float.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-satellite] kezhenxu94 commented on a change in pull request #20: override config by env
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #20:
URL: https://github.com/apache/skywalking-satellite/pull/20#discussion_r563677687
##########
File path: internal/satellite/config/override_by_env_test.go
##########
@@ -0,0 +1,200 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package config
+
+import (
+ "os"
+ "reflect"
+ "regexp"
+ "strings"
+ "testing"
+
+ "github.com/google/go-cmp/cmp"
+)
+
+func Test_overrideString(t *testing.T) {
Review comment:
Seems the test doesn't cover the double quoted value (`"10"`) case
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [skywalking-satellite] nic-chen commented on a change in pull request #20: override config by env
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #20:
URL: https://github.com/apache/skywalking-satellite/pull/20#discussion_r563276171
##########
File path: internal/satellite/config/override_by_env.go
##########
@@ -0,0 +1,114 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package config
+
+import (
+ "os"
+ "regexp"
+ "strconv"
+ "strings"
+
+ "github.com/spf13/viper"
+)
+
+// ${ENV:defaultVal} pattern is supported to override the default value by the env config.
+// And the value would be converted to the different types, such as int, float64 ana string.
+// If you want to keep it as the string value, please decorate it with `"`.
+const RegularExpression = "${_|[A-Z]+:.*}"
+
+func overrideConfigByEnv(v *viper.Viper) error {
+ regex, err := regexp.Compile(RegularExpression)
+ if err != nil {
+ return err
+ }
+ overrideCfg := overrideMapStringInterface(v.AllSettings(), regex)
+ for key, val := range overrideCfg {
+ v.Set(key, val)
+ }
+ return nil
+}
+
+func overrideMapStringInterface(cfg map[string]interface{}, regex *regexp.Regexp) map[string]interface{} {
+ res := make(map[string]interface{})
+ for key, val := range cfg {
+ switch val := val.(type) {
+ case string:
+ res[key] = overrideString(val, regex)
+ case []interface{}:
+ res[key] = overrideSlice(val, regex)
+ case map[string]interface{}:
+ res[key] = overrideMapStringInterface(val, regex)
+ case map[interface{}]interface{}:
+ res[key] = overrideMapInterfaceInterface(val, regex)
+ default:
+ res[key] = val
+ }
+ }
+ return res
+}
+
+func overrideSlice(m []interface{}, regex *regexp.Regexp) []interface{} {
+ res := make([]interface{}, 0)
+ for _, val := range m {
+ switch val := val.(type) {
+ case map[string]interface{}:
+ res = append(res, overrideMapStringInterface(val, regex))
+ case map[interface{}]interface{}:
+ res = append(res, overrideMapInterfaceInterface(val, regex))
+ }
+ }
+ return res
+}
+
+func overrideMapInterfaceInterface(m map[interface{}]interface{}, regex *regexp.Regexp) interface{} {
+ cfg := make(map[string]interface{})
+ for key, val := range m {
+ cfg[key.(string)] = val
+ }
+ return overrideMapStringInterface(cfg, regex)
+}
+
+func overrideString(s string, regex *regexp.Regexp) interface{} {
+ if regex.MatchString(s) {
+ index := strings.Index(s, ":")
+ envName := s[2:index]
+ defaultVal := s[index+1 : len(s)-1]
+ envVal := os.Getenv(envName)
+ if envVal != "" {
+ defaultVal = envVal
+ }
+ return parseVal(defaultVal)
+ }
+ return s
+}
+
+func parseVal(val string) interface{} {
+ if intVal, err := strconv.Atoi(val); err == nil {
+ return intVal
+ } else if floatVal, err := strconv.ParseFloat(val, 64); err == nil {
+ return floatVal
+ } else if strings.EqualFold(val, "true") {
+ return true
+ } else if strings.EqualFold(val, "false") {
+ return false
+ } else if strings.HasPrefix(val, "\"") && strings.HasSuffix(val, "\"") {
+ return val[1 : len(val)-1]
Review comment:
should we `parseVal` again here?
##########
File path: internal/satellite/config/satellite_config.go
##########
@@ -30,9 +30,9 @@ import (
// SatelliteConfig is to initialize Satellite.
type SatelliteConfig struct {
Logger *log.LoggerConfig `mapstructure:"logger"`
- Pipes []*PipeConfig `mapstructure:"pipes"`
- Sharing *SharingConfig `mapstructure:"sharing"`
Telemetry *telemetry.Config `mapstructure:"telemetry"`
+ Sharing *SharingConfig `mapstructure:"sharing"`
+ Pipes []*PipeConfig `mapstructure:"pipes"`
Review comment:
we should keep the alphabetical order ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org