You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by li...@apache.org on 2021/02/13 15:37:21 UTC

[skywalking-satellite] branch add-start-up-script created (now fb7020f)

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

liujiapeng pushed a change to branch add-start-up-script
in repository https://gitbox.apache.org/repos/asf/skywalking-satellite.git.


      at fb7020f  add start up script

This branch includes the following new commits:

     new fb7020f  add start up script

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking-satellite] 01/01: add start up script

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujiapeng pushed a commit to branch add-start-up-script
in repository https://gitbox.apache.org/repos/asf/skywalking-satellite.git

commit fb7020f8f28f31234aaf894cbd7286fa902d6595
Author: Evan <ev...@outlook.com>
AuthorDate: Sat Feb 13 23:36:28 2021 +0800

    add start up script
---
 .gitignore                                        |  1 +
 Makefile                                          |  4 +-
 configs/satellite_config.yaml                     |  2 -
 dist/bin/startup.bat                              | 25 ++++++++++++
 dist/bin/startup.sh                               | 47 +++++++++++++++++++++++
 docs/en/setup/README.md                           |  5 +--
 internal/satellite/config/loader.go               | 17 ++++----
 internal/satellite/config/loader_test.go          | 10 ++---
 internal/satellite/config/satellite_config.go     | 29 ++++++++++++--
 internal/satellite/module/gatherer/api/config.go  |  2 +-
 internal/satellite/module/processor/api/config.go |  2 +-
 internal/satellite/module/sender/api/config.go    |  2 +-
 12 files changed, 121 insertions(+), 25 deletions(-)

diff --git a/.gitignore b/.gitignore
index 51f1814..3161f6d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
 bin/
 coverage.txt
 
+!/dist/bin/
diff --git a/Makefile b/Makefile
index 0230b7a..71b25bf 100644
--- a/Makefile
+++ b/Makefile
@@ -71,9 +71,10 @@ verify: clean lint test
 .PHONY: clean
 clean: tools
 	-rm -rf coverage.txt
+	-rm -rf bin
 
 .PHONY: build
-build: deps linux darwin windows
+build: clean deps linux darwin windows
 
 .PHONY: check
 check: clean
@@ -100,6 +101,7 @@ release-src: clean
 release-bin: build
 	-mkdir $(RELEASE_BIN)
 	-cp -R bin $(RELEASE_BIN)
+	-cp -R configs $(RELEASE_BIN)
 	-cp -R dist/* $(RELEASE_BIN)
 	-cp -R CHANGES.md $(RELEASE_BIN)
 	-cp -R README.md $(RELEASE_BIN)
diff --git a/configs/satellite_config.yaml b/configs/satellite_config.yaml
index 323e945..407b4bc 100644
--- a/configs/satellite_config.yaml
+++ b/configs/satellite_config.yaml
@@ -29,8 +29,6 @@ telemetry:
 
 # The sharing plugins referenced by the specific plugins in the different pipes.
 sharing:
-  common_config:
-    pipe_name: sharing
   clients:
     - plugin_name: "kafka-client"
       brokers: ${SATELLITE_KAFKA_CLIENT_BROKERS:127.0.0.1:9092}
diff --git a/dist/bin/startup.bat b/dist/bin/startup.bat
new file mode 100644
index 0000000..f4dba58
--- /dev/null
+++ b/dist/bin/startup.bat
@@ -0,0 +1,25 @@
+@REM
+@REM  Licensed to the Apache Software Foundation (ASF) under one or more
+@REM  contributor license agreements.  See the NOTICE file distributed with
+@REM  this work for additional information regarding copyright ownership.
+@REM  The ASF licenses this file to You under the Apache License, Version 2.0
+@REM  (the "License"); you may not use this file except in compliance with
+@REM  the License.  You may obtain a copy of the License at
+@REM
+@REM      http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM  Unless required by applicable law or agreed to in writing, software
+@REM  distributed under the License is distributed on an "AS IS" BASIS,
+@REM  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@REM  See the License for the specific language governing permissions and
+@REM  limitations under the License.
+
+
+@echo off
+setlocal
+
+set HOME_DIR=%~dp0%..
+set BIN_DIR=%HOME_DIR%\bin
+set LOG_DIR=%HOME_DIR%\logs
+set CONFIG_DIR=%HOME_DIR%\configs
+
diff --git a/dist/bin/startup.sh b/dist/bin/startup.sh
new file mode 100755
index 0000000..211e547
--- /dev/null
+++ b/dist/bin/startup.sh
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the 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.
+# The 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.
+#
+
+
+HOME_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)"
+BIN_DIR=${HOME_DIR}/bin
+LOG_DIR=${HOME_DIR}/logs
+CONFIG_DIR=${HOME_DIR}/configs
+LOG_FILE_LOCATION=${LOG_DIR}/satellite.log
+
+if [ ! -d "${LOG_DIR}" ]; then
+    mkdir -p "${LOG_DIR}"
+fi
+
+if uname -s | grep Darwin; then
+  START_UP_PROCESS=$(find "$BIN_DIR" -name "skywalking-satellite*darwin*")
+elif uname -s | grep Linux; then
+  START_UP_PROCESS=$(find "$BIN_DIR" -name "skywalking-satellite*linux*")
+else
+  echo "Sorry, the official startup process does not support your system."
+fi
+
+eval exec "$START_UP_PROCESS" start --config="$CONFIG_DIR"/satellite_config.yaml 1> "$LOG_FILE_LOCATION" 2>&1 &
+
+if [ $? -eq 0 ]; then
+  sleep 1
+	echo "SkyWalking Satellite started successfully!"
+else
+	echo "SkyWalking Satellite started failure!"
+	exit 1
+fi
\ No newline at end of file
diff --git a/docs/en/setup/README.md b/docs/en/setup/README.md
index 3c5ab09..699140f 100644
--- a/docs/en/setup/README.md
+++ b/docs/en/setup/README.md
@@ -2,10 +2,9 @@
 First and most important thing is, SkyWalking Satellite startup behaviours are driven by configs/satellite_config.yaml. Understanding the setting file will help you to read this document.
 
 ## Startup script
-The startup script is /bin/skywalking-satellite-{version}-{plateform}-amd64. 
-1. Start SkyWalking Satellite.
+Startup Script
 ```shell script
-./bin/skywalking-satellite-{version}-{plateform}-amd64 start --config=./configs/satellite_config.yaml
+/bin/startup.sh or /bin/startup.bat
 ```
 ## satellite_config.yaml
 The core concept behind this setting file is, SkyWalking Satellite is based on pure modularization design. End user can switch or assemble the collector features by their own requirements.
diff --git a/internal/satellite/config/loader.go b/internal/satellite/config/loader.go
index 11c6032..44f13f9 100644
--- a/internal/satellite/config/loader.go
+++ b/internal/satellite/config/loader.go
@@ -62,19 +62,19 @@ func load(configPath string) (*SatelliteConfig, error) {
 	}
 	v := viper.New()
 	v.SetConfigType("yaml")
-	cfg := SatelliteConfig{}
+	cfg := NewDefaultSatelliteConfig()
 	if err := v.ReadConfig(bytes.NewReader(content)); err != nil {
 		return nil, err
 	}
 	if err := overrideConfigByEnv(v); err != nil {
 		return nil, fmt.Errorf("cannot override value by env config: %v", err)
 	}
-	if err := v.Unmarshal(&cfg); err != nil {
+	if err := v.Unmarshal(cfg); err != nil {
 		return nil, err
 	}
 	propagateCommonFieldsInSharing(cfg.Sharing)
 	propagateCommonFieldsInPipes(cfg.Pipes)
-	return &cfg, nil
+	return cfg, nil
 }
 
 // propagate the common fields to every modules and the dependency plugins.
@@ -95,7 +95,7 @@ func propagateCommonFieldsInSharing(sharing *SharingConfig) {
 }
 
 // propagate the common fields to the fields that is one of `plugin.config` or `[]plugin.config` types.
-func propagateCommonFieldsInStruct(cfg interface{}, cf config.CommonFields) {
+func propagateCommonFieldsInStruct(cfg interface{}, commonFields *config.CommonFields) {
 	v := reflect.ValueOf(cfg)
 	if v.Kind() == reflect.Ptr {
 		v = v.Elem()
@@ -104,17 +104,20 @@ func propagateCommonFieldsInStruct(cfg interface{}, cf config.CommonFields) {
 		fieldVal := v.Field(i).Interface()
 		if arr, ok := fieldVal.([]plugin.Config); arr != nil && ok {
 			for _, pc := range arr {
-				propagateCommonFields(pc, cf)
+				propagateCommonFields(pc, commonFields)
 			}
 		} else if pc, ok := fieldVal.(plugin.Config); pc != nil && ok {
-			propagateCommonFields(pc, cf)
+			propagateCommonFields(pc, commonFields)
 		}
 	}
 }
 
 // propagate the common fields to the `plugin.config`.
-func propagateCommonFields(pc plugin.Config, cf config.CommonFields) {
+func propagateCommonFields(pc plugin.Config, cf *config.CommonFields) {
 	v := reflect.ValueOf(cf)
+	if v.Kind() == reflect.Ptr {
+		v = v.Elem()
+	}
 	t := v.Type()
 	for i := 0; i < t.NumField(); i++ {
 		if tagVal := t.Field(i).Tag.Get(config.TagName); tagVal != "" {
diff --git a/internal/satellite/config/loader_test.go b/internal/satellite/config/loader_test.go
index 1249e20..eabebf0 100644
--- a/internal/satellite/config/loader_test.go
+++ b/internal/satellite/config/loader_test.go
@@ -76,7 +76,7 @@ func params() *SatelliteConfig {
 			Instance: "instance1",
 		},
 		Sharing: &SharingConfig{
-			SharingCommonConfig: config.CommonFields{
+			SharingCommonConfig: &config.CommonFields{
 				PipeName: "sharing",
 			},
 			Clients: []plugin.Config{
@@ -101,13 +101,13 @@ func params() *SatelliteConfig {
 		},
 		Pipes: []*PipeConfig{
 			{
-				PipeCommonConfig: config.CommonFields{
+				PipeCommonConfig: &config.CommonFields{
 					PipeName: "pipe1",
 				},
 
 				Gatherer: &gatherer.GathererConfig{
 					ServerName: "grpc-server",
-					CommonFields: config.CommonFields{
+					CommonFields: &config.CommonFields{
 						PipeName: "pipe1",
 					},
 					ReceiverConfig: plugin.Config{
@@ -123,12 +123,12 @@ func params() *SatelliteConfig {
 					},
 				},
 				Processor: &processor.ProcessorConfig{
-					CommonFields: config.CommonFields{
+					CommonFields: &config.CommonFields{
 						PipeName: "pipe1",
 					},
 				},
 				Sender: &sender.SenderConfig{
-					CommonFields: config.CommonFields{
+					CommonFields: &config.CommonFields{
 						PipeName: "pipe1",
 					},
 					FallbackerConfig: plugin.Config{
diff --git a/internal/satellite/config/satellite_config.go b/internal/satellite/config/satellite_config.go
index 2828285..d5ed032 100644
--- a/internal/satellite/config/satellite_config.go
+++ b/internal/satellite/config/satellite_config.go
@@ -37,15 +37,36 @@ type SatelliteConfig struct {
 
 // SharingConfig contains some plugins,which could be shared by every namespace. That is useful to reduce resources cost.
 type SharingConfig struct {
-	Clients             []plugin.Config     `mapstructure:"clients"`
-	Servers             []plugin.Config     `mapstructure:"servers"`
-	SharingCommonConfig config.CommonFields `mapstructure:"common_config"`
+	Clients             []plugin.Config      `mapstructure:"clients"`
+	Servers             []plugin.Config      `mapstructure:"servers"`
+	SharingCommonConfig *config.CommonFields `mapstructure:"common_config"`
 }
 
 // PipeConfig initializes the different module in different namespace.
 type PipeConfig struct {
+	PipeCommonConfig *config.CommonFields       `mapstructure:"common_config"`
 	Gatherer         *gatherer.GathererConfig   `mapstructure:"gatherer"`
-	PipeCommonConfig config.CommonFields        `mapstructure:"common_config"`
 	Processor        *processor.ProcessorConfig `mapstructure:"processor"`
 	Sender           *sender.SenderConfig       `mapstructure:"sender"`
 }
+
+// Create a satellite config with default value.
+func NewDefaultSatelliteConfig() *SatelliteConfig {
+	return &SatelliteConfig{
+		Logger: &log.LoggerConfig{
+			LogPattern:  "%time [%level][%field] - %msg",
+			TimePattern: "2006-01-02 15:04:05.000",
+			Level:       "info",
+		},
+		Telemetry: &telemetry.Config{
+			Cluster:  "default_cluster",
+			Service:  "default_service",
+			Instance: "default_instance",
+		},
+		Sharing: &SharingConfig{
+			SharingCommonConfig: &config.CommonFields{
+				PipeName: "sharing",
+			},
+		},
+	}
+}
diff --git a/internal/satellite/module/gatherer/api/config.go b/internal/satellite/module/gatherer/api/config.go
index 9846ffe..e2275fc 100644
--- a/internal/satellite/module/gatherer/api/config.go
+++ b/internal/satellite/module/gatherer/api/config.go
@@ -25,7 +25,7 @@ import (
 // GathererConfig contains all implementation fields.
 type GathererConfig struct {
 	// common config
-	config.CommonFields
+	*config.CommonFields
 	QueueConfig plugin.Config `mapstructure:"queue"` // queue plugin config
 
 	// ReceiverGatherer
diff --git a/internal/satellite/module/processor/api/config.go b/internal/satellite/module/processor/api/config.go
index d8788ea..5b9e06d 100644
--- a/internal/satellite/module/processor/api/config.go
+++ b/internal/satellite/module/processor/api/config.go
@@ -24,7 +24,7 @@ import (
 
 // ProcessorConfig contains all implementation fields.
 type ProcessorConfig struct {
-	config.CommonFields
+	*config.CommonFields
 
 	FilterConfig []plugin.Config `mapstructure:"filters"` // filter plugins
 }
diff --git a/internal/satellite/module/sender/api/config.go b/internal/satellite/module/sender/api/config.go
index 04cfa4d..fb9ccce 100644
--- a/internal/satellite/module/sender/api/config.go
+++ b/internal/satellite/module/sender/api/config.go
@@ -23,7 +23,7 @@ import (
 )
 
 type SenderConfig struct {
-	config.CommonFields
+	*config.CommonFields
 	// plugins config
 	ForwardersConfig []plugin.Config `mapstructure:"forwarders"`  // forwarder plugins config
 	FallbackerConfig plugin.Config   `mapstructure:"fallbacker"`  // fallbacker plugins config