From 018a96410520755f5f19d02ce770c273dd040721 Mon Sep 17 00:00:00 2001 From: Rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Tue, 26 Sep 2023 14:00:51 +0800 Subject: [PATCH] feat: support passing skywalking server in podman service (#220) --- cmd/service.go | 28 ++++++++++++++++++++-------- cmd/service_test.go | 4 +++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cmd/service.go b/cmd/service.go index 0bb2488..6f0a418 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -46,9 +46,16 @@ Mirror Images: docker.m.daocloud.io/linuxsuren/api-testing`, flags.StringVarP(&opt.localStorage, "local-storage", "", "/var/data/atest", "The local storage path which will be mounted into the container") flags.StringVarP(&opt.secretServer, "secret-server", "", "", "The secret server URL") + flags.StringVarP(&opt.skyWalking, "skywalking", "", "", "Push the browser tracing data to the Apache SkyWalking URL") return } +type serverFeatureOption struct { + secretServer string + skyWalking string + localStorage string +} + type serviceOption struct { action string scriptPath string @@ -56,11 +63,10 @@ type serviceOption struct { image string version string fakeruntime.Execer - mode string - localStorage string - pull string - secretServer string + mode string + pull string + serverFeatureOption stdOut io.Writer } @@ -215,7 +221,7 @@ func (o *serviceOption) getContainerService() (service Service, err error) { clientPath = client } service = newContainerService(o.Execer, clientPath, - o.image, o.version, o.pull, o.localStorage, o.secretServer, o.stdOut) + o.image, o.version, o.pull, o.serverFeatureOption, o.stdOut) } return } @@ -322,13 +328,15 @@ type containerService struct { pull string localStorage string secretServer string + skyWalking string stdOut io.Writer errOut io.Writer } const defaultImage = "ghcr.io/linuxsuren/api-testing" -func newContainerService(execer fakeruntime.Execer, client, image, tag, pull, localStorage string, secretServer string, writer io.Writer) (svc Service) { +func newContainerService(execer fakeruntime.Execer, client, image, tag, pull string, + featureOption serverFeatureOption, writer io.Writer) (svc Service) { if tag == "" { tag = "latest" } @@ -343,8 +351,9 @@ func newContainerService(execer fakeruntime.Execer, client, image, tag, pull, lo image: image, tag: tag, pull: pull, - localStorage: localStorage, - secretServer: secretServer, + localStorage: featureOption.localStorage, + secretServer: featureOption.secretServer, + skyWalking: featureOption.skyWalking, stdOut: writer, errOut: writer, } @@ -414,6 +423,9 @@ func (s *containerService) getStartArgs() []string { if s.secretServer != "" { args = append(args, "--secret-server="+s.secretServer) } + if s.skyWalking != "" { + args = append(args, "--skywalking="+s.skyWalking) + } args = append(args, "--console-path=/var/www/html") return args } diff --git a/cmd/service_test.go b/cmd/service_test.go index 5c9673d..0377ce2 100644 --- a/cmd/service_test.go +++ b/cmd/service_test.go @@ -173,7 +173,9 @@ func TestService(t *testing.T) { NewFakeGRPCServer(), server.NewFakeHTTPServer()) normalRoot.SetOut(buf) normalRoot.SetArgs([]string{"service", "--action", tt.action, - "--script-path", tmpFile.Name(), "--mode", tt.mode, "--image="}) + "--script-path", tmpFile.Name(), "--mode", tt.mode, "--image=", + "--skywalking=http://localhost:8080", + "--secret-server=http://localhost:9090"}) err = normalRoot.Execute() assert.Nil(t, err) assert.Equal(t, tt.expectOutput, strings.TrimSpace(buf.String()))