You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2021/10/01 06:59:59 UTC

[skywalking-infra-e2e] 01/01: Some enhancements

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

kezhenxu94 pushed a commit to branch enhancements
in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git

commit 8572dc2f0d7eab18c92fdf286e035b1e9a996e1a
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Fri Oct 1 14:59:48 2021 +0800

    Some enhancements
    
    - Adjust the env var logs for convenient copy and test.
    - Support `body` and `headers` in http trigger.
    - Add `install` target in makefile.
    - Add some unit tests for verifier.
---
 Makefile                                      |  8 +++
 commands/trigger/trigger.go                   |  5 +-
 internal/components/setup/compose.go          |  2 +-
 internal/components/trigger/http.go           | 18 ++++++-
 internal/components/verifier/verifier_test.go | 77 +++++++++++++++++++++++++++
 internal/config/e2eConfig.go                  | 12 +++--
 6 files changed, 113 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index 673441a..00494e7 100644
--- a/Makefile
+++ b/Makefile
@@ -97,3 +97,11 @@ release: verify release-src release-bin
 	shasum -a 512 $(RELEASE_SRC).tgz > $(RELEASE_SRC).tgz.sha512
 	gpg --batch --yes --armor --detach-sig $(RELEASE_BIN).tgz
 	shasum -a 512 $(RELEASE_BIN).tgz > $(RELEASE_BIN).tgz.sha512
+
+.PHONY: install
+install: $(OSNAME)
+	-cp $(OUT_DIR)/$(OSNAME)/$(PROJECT) $(DESTDIR)
+
+.PHONY: uninstall
+uninstall: $(OSNAME)
+	-rm $(DESTDIR)/$(PROJECT)
diff --git a/commands/trigger/trigger.go b/commands/trigger/trigger.go
index 7d86776..80410f4 100644
--- a/commands/trigger/trigger.go
+++ b/commands/trigger/trigger.go
@@ -50,7 +50,10 @@ func DoActionAccordingE2E() error {
 		action := trigger.NewHTTPAction(e2eConfig.Trigger.Interval,
 			e2eConfig.Trigger.Times,
 			e2eConfig.Trigger.URL,
-			e2eConfig.Trigger.Method)
+			e2eConfig.Trigger.Method,
+			e2eConfig.Trigger.Body,
+			e2eConfig.Trigger.Headers,
+		)
 		if action == nil {
 			return fmt.Errorf("trigger [%+v] parse error", e2eConfig.Trigger)
 		}
diff --git a/internal/components/setup/compose.go b/internal/components/setup/compose.go
index d73c14e..14b47bb 100644
--- a/internal/components/setup/compose.go
+++ b/internal/components/setup/compose.go
@@ -154,7 +154,7 @@ func exportComposeEnv(key, value, service string) error {
 	if err != nil {
 		return fmt.Errorf("could not set env for %s, %v", service, err)
 	}
-	logger.Log.Infof("expose env : %s : %s", key, value)
+	logger.Log.Infof("export %s=%s", key, value)
 	return nil
 }
 
diff --git a/internal/components/trigger/http.go b/internal/components/trigger/http.go
index 2af36a3..4a3ddce 100644
--- a/internal/components/trigger/http.go
+++ b/internal/components/trigger/http.go
@@ -20,6 +20,7 @@ package trigger
 import (
 	"context"
 	"fmt"
+	"io/ioutil"
 	"net/http"
 	"os"
 	"strings"
@@ -33,10 +34,12 @@ type httpAction struct {
 	times         int
 	url           string
 	method        string
+	body          string
+	headers       map[string]string
 	executedCount int
 }
 
-func NewHTTPAction(intervalStr string, times int, url, method string) Action {
+func NewHTTPAction(intervalStr string, times int, url, method, body string, headers map[string]string) Action {
 	interval, err := time.ParseDuration(intervalStr)
 	if err != nil {
 		logger.Log.Errorf("interval [%s] parse error: %s.", intervalStr, err)
@@ -56,6 +59,8 @@ func NewHTTPAction(intervalStr string, times int, url, method string) Action {
 		times:         times,
 		url:           url,
 		method:        strings.ToUpper(method),
+		body:          body,
+		headers:       headers,
 		executedCount: 0,
 	}
 }
@@ -65,7 +70,16 @@ func (h *httpAction) Do() error {
 	t := time.NewTicker(h.interval)
 	h.executedCount = 0
 	client := &http.Client{}
-	request, err := http.NewRequest(h.method, h.url, nil)
+
+	r := strings.NewReader(h.body)
+	rc := ioutil.NopCloser(r)
+
+	request, err := http.NewRequest(h.method, h.url, rc)
+	headers := http.Header{}
+	for k, v := range h.headers {
+		headers[k] = []string{v}
+	}
+	request.Header = headers
 	if err != nil {
 		logger.Log.Errorf("new request error %v", err)
 		return err
diff --git a/internal/components/verifier/verifier_test.go b/internal/components/verifier/verifier_test.go
index d2a287c..09da74c 100644
--- a/internal/components/verifier/verifier_test.go
+++ b/internal/components/verifier/verifier_test.go
@@ -195,6 +195,83 @@ metrics:
 			},
 			wantErr: true,
 		},
+		{
+			name: "multiple level attribute and contains greater 2",
+			args: args{
+				actualData: `
+metrics:
+  key:
+  - name: business-zone::projectA
+    id: YnVzaW5lc3Mtem9uZTo6cHJvamVjdEE=.1
+    value: 1
+`,
+				expectedTemplate: `
+metrics:
+  key:
+  {{- contains .metrics.key }}
+    - name: {{ notEmpty .name }}
+      id: {{ notEmpty .id }}
+      value: {{ gt .value 0 }}
+    - name: {{ notEmpty .name }}
+      id: {{ notEmpty .id }}
+      value: {{ gt .value 2 }}
+  {{- end }}
+`,
+			},
+			wantErr: true,
+		},
+		{
+			name: "contains unordered slices",
+			args: args{
+				actualData: `
+- id: ZTJlLXNlcnZpY2UtcHJvdmlkZXI=.1_cHJvdmlkZXIx
+  name: whatever
+  attributes:
+  - name: JVM Arguments
+    value: abcde
+  - name: OS Name
+    value: Linux
+  - name: hostname
+    value: 127.0.0.1
+  - name: Process No.
+    value: "1"
+  - name: Start Time
+    value: "12345"
+  - name: Jar Dependencies
+    value: abcde
+  - name: ipv4s
+    value: abcde
+  language: JAVA
+  instanceuuid: ZTJlLXNlcnZpY2UtcHJvdmlkZXI=.1_cHJvdmlkZXIx
+`,
+				expectedTemplate: `
+{{- contains . }}
+- id: {{ b64enc "e2e-service-provider" }}.1_{{ b64enc "provider1" }}
+  name: {{ notEmpty .name }}
+  attributes:
+  {{- contains .attributes }}
+  - name: Jar Dependencies
+    value: '{{ notEmpty .value }}'
+  - name: OS Name
+    value: Linux
+  - name: hostname
+    value: {{ notEmpty .value }}
+  - name: ipv4s
+    value: {{ notEmpty .value }}
+  - name: Process No.
+    value: "1"
+  - name: Start Time
+    value: {{ notEmpty .value }}
+  - name: JVM Arguments
+    value: '{{ notEmpty .value }}'
+  {{- end}}
+  language: JAVA
+  instanceuuid: {{ b64enc "e2e-service-provider" }}.1_{{ b64enc "provider1" }}
+{{- end}}
+`,
+			},
+			wantErr: false,
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
diff --git a/internal/config/e2eConfig.go b/internal/config/e2eConfig.go
index 1fad94c..db89f61 100644
--- a/internal/config/e2eConfig.go
+++ b/internal/config/e2eConfig.go
@@ -74,11 +74,13 @@ type Wait struct {
 }
 
 type Trigger struct {
-	Action   string `yaml:"action"`
-	Interval string `yaml:"interval"`
-	Times    int    `yaml:"times"`
-	URL      string `yaml:"url"`
-	Method   string `yaml:"method"`
+	Action   string            `yaml:"action"`
+	Interval string            `yaml:"interval"`
+	Times    int               `yaml:"times"`
+	URL      string            `yaml:"url"`
+	Method   string            `yaml:"method"`
+	Body     string            `yaml:"body"`
+	Headers  map[string]string `yaml:"headers"`
 }
 
 type VerifyCase struct {