This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-satellite.git


The following commit(s) were added to refs/heads/main by this push:
     new 6ca2be9  Setup full configuration, each config could be setup from 
environment (#86)
6ca2be9 is described below

commit 6ca2be91d9800fd93b1ce072ba16e2888cfd20bb
Author: mrproliu <[email protected]>
AuthorDate: Tue Nov 23 10:50:56 2021 +0800

    Setup full configuration, each config could be setup from environment (#86)
---
 configs/satellite_config.yaml                      | 47 ++++++++++++++++++++++
 .../examples/grpc-load-balance-client/README.md    | 10 +++--
 docs/en/setup/plugins/client_grpc-client.md        | 18 ++++++++-
 internal/satellite/config/loader_test.go           | 28 +++++++++++++
 internal/satellite/config/override_by_env.go       |  2 +-
 plugins/client/grpc/client.go                      | 15 +++++++
 .../client/grpc/resolvers/kubernetes_clients.go    |  4 +-
 plugins/client/grpc/resolvers/kubernetes_config.go |  8 +---
 plugins/client/grpc/resolvers/resolvers.go         |  9 +++--
 plugins/client/grpc/resolvers/static_clients.go    |  4 +-
 10 files changed, 125 insertions(+), 20 deletions(-)

diff --git a/configs/satellite_config.yaml b/configs/satellite_config.yaml
index db9fcef..f08a72e 100644
--- a/configs/satellite_config.yaml
+++ b/configs/satellite_config.yaml
@@ -37,8 +37,55 @@ telemetry:
 sharing:
   clients:
     - plugin_name: "grpc-client"
+      # The gRPC server address finder type
+      finder_type: ${SATELLITE_GRPC_CLIENT_FINDER:static}
       # The gRPC server address (default localhost:11800).
       server_addr: ${SATELLITE_GRPC_CLIENT:127.0.0.1:11800}
+      # The gRPC kubernetes server address finder
+      kubernetes_config:
+        # The kubernetes API server address, If not define means using in 
kubernetes mode to connect
+        api_server: ${SATELLITE_GRPC_CLIENT_KUBERNETES_API_SERVER:}
+        # The HTTP basic authentication credentials for the targets.
+        basic_auth:
+          # The username for auth.
+          username: ${SATELLITE_GRPC_CLIENT_KUBERNETES_BASIC_AUTH_USERNAME:}
+          # The password for auth.
+          password: ${SATELLITE_GRPC_CLIENT_KUBERNETES_BASIC_AUTH_PASSWORD:}
+          # The password file path for auth.
+          password_file: 
${SATELLITE_GRPC_CLIENT_KUBERNETES_BASIC_AUTH_PASSWORD_FILE:}
+        # The bearer token for the targets.
+        bearer_token: ${SATELLITE_GRPC_CLIENT_KUBERNETES_BEARER_TOKEN:}
+        # The bearer token file for the targets.
+        bearer_token_file: 
${SATELLITE_GRPC_CLIENT_KUBERNETES_BEARER_TOKEN_FILE:}
+        # HTTP proxy server to use to connect to the targets.
+        proxy_url: ${SATELLITE_GRPC_CLIENT_KUBERNETES_PROXY_URL:}
+        # Used to connect to the targets.
+        tls_config:
+          # The CA cert to use for the targets.
+          ca_file: ${SATELLITE_GRPC_CLIENT_KUBERNETES_TLS_CONFIG_CA_FILE:}
+          # The client cert file for the targets.
+          cert_file: ${SATELLITE_GRPC_CLIENT_KUBERNETES_TLS_CONFIG_CERT_FILE:}
+          # The client key file for the targets.
+          key_file: ${SATELLITE_GRPC_CLIENT_KUBERNETES_TLS_CONFIG_KEY_FILE:}
+          # Used to verify the hostname for the targets.
+          server_name: 
${SATELLITE_GRPC_CLIENT_KUBERNETES_TLS_CONFIG_SERVER_NAME:}
+          # Disable target certificate validation.
+          insecure_skip_verify: 
${SATELLITE_GRPC_CLIENT_KUBERNETES_TLS_CONFIG_INSECURE_SKIP_VERIFY:}
+        namespaces:
+          # Support to lookup namespaces.
+          - ${SATELLITE_GRPC_CLIENT_KUBERNETES_NAMESPACE:default}
+        # The kind of resource
+        kind: ${SATELLITE_GRPC_CLIENT_KUBERNETES_KIND:pod}
+        # The kind selector
+        selector:
+          # Label selector
+          label: ${SATELLITE_GRPC_CLIENT_KUBERNETES_SELECTOR_LABEL:}
+          # Field selector
+          field: ${SATELLITE_GRPC_CLIENT_KUBERNETES_SELECTOR_FIELD:}
+        # How to get the address exported port
+        extra_port:
+          # Resource target port
+          port: ${SATELLITE_GRPC_CLIENT_KUBERNETES_EXTRA_PORT_PORT:11800}
       # The TLS switch
       enable_TLS: ${SATELLITE_GRPC_ENABLE_TLS:false}
       # The file path of client.pem. The config only works when opening the 
TLS switch.
diff --git a/docs/en/setup/examples/grpc-load-balance-client/README.md 
b/docs/en/setup/examples/grpc-load-balance-client/README.md
index d21aa3f..3e2d573 100644
--- a/docs/en/setup/examples/grpc-load-balance-client/README.md
+++ b/docs/en/setup/examples/grpc-load-balance-client/README.md
@@ -4,9 +4,9 @@ GRPC client support connect to multiple server address, and use 
`round-robin` po
 
 ## Server Discovery
 
-Support two ways to locate the server list:
-1. Static server list: Define the server address list.
-2. Kubernetes selector: Define kubernetes pod/service/endpoint, it could be 
found addresses and dynamic update automatically.
+Support two ways to locate the server list, using `finder_type` to change the 
type to find:
+1. `static`: Define the server address list.
+2. `kubernetes`: Define kubernetes pod/service/endpoint, it could be found 
addresses and dynamic update automatically.
 
 ### Static server list
 
@@ -16,6 +16,8 @@ You could see there define two server address and split by 
",".
 sharing:
   clients:
     - plugin_name: "grpc-client"
+      # The gRPC server address finder type
+      finder_type: ${SATELLITE_GRPC_CLIENT_FINDER:static}
       # The gRPC server address (default localhost:11800).
       server_addr: ${SATELLITE_GRPC_CLIENT:127.0.0.1:11800,127.0.0.2:11800}
       # The TLS switch
@@ -47,6 +49,8 @@ Using `kubernetes_config` to define the address's finder.
 sharing:
   clients:
     - plugin_name: "grpc-client"
+      # The gRPC server address finder type
+      finder_type: ${SATELLITE_GRPC_CLIENT_FINDER:kubernetes}
       # The kubernetes config to lookup addresses
       kubernetes_config:
         # The kubernetes API server address, If not define means using in 
kubernetes mode to connect
diff --git a/docs/en/setup/plugins/client_grpc-client.md 
b/docs/en/setup/plugins/client_grpc-client.md
index 3b33e48..9bc0846 100755
--- a/docs/en/setup/plugins/client_grpc-client.md
+++ b/docs/en/setup/plugins/client_grpc-client.md
@@ -3,9 +3,24 @@
 The gRPC client is a sharing plugin to keep connection with the gRPC server 
and delivery the data to it.
 ## DefaultConfig
 ```yaml
+# The gRPC client finder type
+finder_type: "static"
+
 # The gRPC server address (default localhost:11800), multiple addresses are 
split by ",".
 server_addr: localhost:11800
 
+# The gRPC kubernetes server address finder
+kubernetes_config:
+  # The kind of resource
+  kind: pod
+  # The resource namespaces
+  namespaces:
+    - default
+  # How to get the address exported port
+  extra_port:
+    # Resource target port
+    port: 11800
+
 # The TLS switch (default false).
 enable_TLS: false
 
@@ -30,6 +45,7 @@ check_period: 5
 ## Configuration
 |Name|Type|Description|
 |----|----|-----------|
+| finder_type | string | The gRPC server address finder type |
 | server_addr | string | The gRPC server address |
 | kubernetes_config | *resolvers.KubernetesConfig | The kubernetes config to 
lookup addresses |
 | kubernetes_config.api_server | string | The kubernetes API server address, 
If not define means using in kubernetes mode to connect |
@@ -39,7 +55,7 @@ check_period: 5
 | kubernetes_config.basic_auth.password_file | string |  |
 | kubernetes_config.bearer_token | resolvers.Secret | The bearer token for the 
targets. |
 | kubernetes_config.bearer_token_file | string | The bearer token file for the 
targets. |
-| kubernetes_config.proxy_url | resolvers.URL | HTTP proxy server to use to 
connect to the targets. |
+| kubernetes_config.proxy_url | string | HTTP proxy server to use to connect 
to the targets. |
 | kubernetes_config.tls_config | resolvers.TLSConfig | TLSConfig to use to 
connect to the targets. |
 | kubernetes_config.namespaces | []string | Support to lookup namespaces |
 | kubernetes_config.kind | string | The kind of api |
diff --git a/internal/satellite/config/loader_test.go 
b/internal/satellite/config/loader_test.go
index d2492af..e8fafb6 100644
--- a/internal/satellite/config/loader_test.go
+++ b/internal/satellite/config/loader_test.go
@@ -97,6 +97,34 @@ func sharing() *SharingConfig {
                                "insecure_skip_verify":   false,
                                "check_period":           5,
                                "authentication":         "",
+                               "finder_type":            "static",
+                               "kubernetes_config": map[string]interface{}{
+                                       "api_server": "",
+                                       "basic_auth": map[string]interface{}{
+                                               "username":      "",
+                                               "password":      "",
+                                               "password_file": "",
+                                       },
+                                       "bearer_token":      "",
+                                       "bearer_token_file": "",
+                                       "proxy_url":         "",
+                                       "tls_config": map[string]interface{}{
+                                               "ca_file":              "",
+                                               "cert_file":            "",
+                                               "key_file":             "",
+                                               "server_name":          "",
+                                               "insecure_skip_verify": "",
+                                       },
+                                       "namespaces": []interface{}{"default"},
+                                       "kind":       "pod",
+                                       "selector": map[string]interface{}{
+                                               "label": "",
+                                               "field": "",
+                                       },
+                                       "extra_port": map[string]interface{}{
+                                               "port": 11800,
+                                       },
+                               },
                        },
                },
                Servers: []plugin.Config{
diff --git a/internal/satellite/config/override_by_env.go 
b/internal/satellite/config/override_by_env.go
index f8b4858..07f0387 100644
--- a/internal/satellite/config/override_by_env.go
+++ b/internal/satellite/config/override_by_env.go
@@ -71,7 +71,7 @@ func overrideSlice(m []interface{}, regex *regexp.Regexp) 
[]interface{} {
                case map[interface{}]interface{}:
                        res = append(res, overrideMapInterfaceInterface(val, 
regex))
                case string:
-                       res = append(res, val)
+                       res = append(res, overrideString(val, regex))
                }
        }
        return res
diff --git a/plugins/client/grpc/client.go b/plugins/client/grpc/client.go
index d946502..d5c9ea8 100644
--- a/plugins/client/grpc/client.go
+++ b/plugins/client/grpc/client.go
@@ -71,9 +71,24 @@ func (c *Client) Description() string {
 
 func (c *Client) DefaultConfig() string {
        return `
+# The gRPC client finder type
+finder_type: "static"
+
 # The gRPC server address (default localhost:11800), multiple addresses are 
split by ",".
 server_addr: localhost:11800
 
+# The gRPC kubernetes server address finder
+kubernetes_config:
+  # The kind of resource
+  kind: pod
+  # The resource namespaces
+  namespaces:
+    - default
+  # How to get the address exported port
+  extra_port:
+    # Resource target port
+    port: 11800
+
 # The TLS switch (default false).
 enable_TLS: false
 
diff --git a/plugins/client/grpc/resolvers/kubernetes_clients.go 
b/plugins/client/grpc/resolvers/kubernetes_clients.go
index 3bbe5ef..2cfd127 100644
--- a/plugins/client/grpc/resolvers/kubernetes_clients.go
+++ b/plugins/client/grpc/resolvers/kubernetes_clients.go
@@ -32,8 +32,8 @@ var kubernetesServerSchema = "kubernetes"
 type kubernetesServerResolver struct {
 }
 
-func (k *kubernetesServerResolver) IsSupport(c *ServerFinderConfig) bool {
-       return c.KubernetesConfig != nil
+func (k *kubernetesServerResolver) Type() string {
+       return kubernetesServerSchema
 }
 
 func (k *kubernetesServerResolver) BuildTarget(c *ServerFinderConfig) (string, 
error) {
diff --git a/plugins/client/grpc/resolvers/kubernetes_config.go 
b/plugins/client/grpc/resolvers/kubernetes_config.go
index b3a1f93..1dbf75d 100644
--- a/plugins/client/grpc/resolvers/kubernetes_config.go
+++ b/plugins/client/grpc/resolvers/kubernetes_config.go
@@ -19,7 +19,6 @@ package resolvers
 
 import (
        "fmt"
-       "net/url"
 
        "github.com/prometheus/common/config"
        "gopkg.in/yaml.v3"
@@ -49,16 +48,11 @@ type HTTPClientConfig struct {
        // The bearer token file for the targets.
        BearerTokenFile string `mapstructure:"bearer_token_file" 
yaml:"bearer_token_file,omitempty"`
        // HTTP proxy server to use to connect to the targets.
-       ProxyURL URL `mapstructure:"proxy_url" yaml:"proxy_url,omitempty"`
+       ProxyURL string `mapstructure:"proxy_url" yaml:"proxy_url,omitempty"`
        // TLSConfig to use to connect to the targets.
        TLSConfig TLSConfig `mapstructure:"tls_config" 
yaml:"tls_config,omitempty"`
 }
 
-// URL is a custom URL type that allows validation at configuration load time.
-type URL struct {
-       *url.URL
-}
-
 // BasicAuth contains basic HTTP authentication credentials.
 type BasicAuth struct {
        Username     string `mapstructure:"username" yaml:"username"`
diff --git a/plugins/client/grpc/resolvers/resolvers.go 
b/plugins/client/grpc/resolvers/resolvers.go
index cb84260..7db211b 100644
--- a/plugins/client/grpc/resolvers/resolvers.go
+++ b/plugins/client/grpc/resolvers/resolvers.go
@@ -30,6 +30,7 @@ var rs = []GrpcResolver{
 }
 
 type ServerFinderConfig struct {
+       FinderType       string            `mapstructure:"finder_type"`       
// The gRPC server address finder type, support "static" and "kubernetes"
        ServerAddr       string            `mapstructure:"server_addr"`       
// The gRPC server address
        KubernetesConfig *KubernetesConfig `mapstructure:"kubernetes_config"` 
// The kubernetes config to lookup addresses
 }
@@ -37,8 +38,8 @@ type ServerFinderConfig struct {
 type GrpcResolver interface {
        resolver.Builder
 
-       // IsSupport client config
-       IsSupport(c *ServerFinderConfig) bool
+       // Type of resolver
+       Type() string
        // BuildTarget address by client config
        BuildTarget(c *ServerFinderConfig) (string, error)
 }
@@ -51,9 +52,9 @@ func RegisterAllGrpcResolvers() {
 
 func BuildTarget(client *ServerFinderConfig) (string, error) {
        for _, r := range rs {
-               if r.IsSupport(client) {
+               if client.FinderType == r.Type() {
                        return r.BuildTarget(client)
                }
        }
-       return "", fmt.Errorf("could not build grpc target")
+       return "", fmt.Errorf("could not find client finder: %s", 
client.FinderType)
 }
diff --git a/plugins/client/grpc/resolvers/static_clients.go 
b/plugins/client/grpc/resolvers/static_clients.go
index 0abe1e3..c09121f 100644
--- a/plugins/client/grpc/resolvers/static_clients.go
+++ b/plugins/client/grpc/resolvers/static_clients.go
@@ -31,8 +31,8 @@ var staticServerSchema = "static"
 type staticServerResolver struct {
 }
 
-func (s *staticServerResolver) IsSupport(c *ServerFinderConfig) bool {
-       return c.KubernetesConfig == nil && c.ServerAddr != ""
+func (s *staticServerResolver) Type() string {
+       return staticServerSchema
 }
 
 func (s *staticServerResolver) BuildTarget(c *ServerFinderConfig) (string, 
error) {

Reply via email to