Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] template for trace #144

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 82 additions & 3 deletions go-plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ TRANSCODER_OUTPUT = ${TRANSCODER_PREFIX}-${OUTPUT}

STEAM_FILTER_PREFIX = filter

TRACE_PREFIX = trace

GIT_VERSION = $(shell git log -1 --pretty=format:%H | head -c 8)
PROJECT_NAME = $(shell head -1 go.mod | cut -d' ' -f2)
FULL_PROJECT_NAME = $(shell pwd)
Expand All @@ -26,8 +28,8 @@ FULL_PROJECT_NAME = $(shell pwd)
SIDECAR_GITLAB_PROJECT_NAME = gitlab.alipay-inc.com/ant-mesh/mosn

SIDECAR_BUILD_IMAGE = mosn-builder
BUILD_IMAGE = golang:1.17.9
BASE_IMAGE = zonghaishang/delve:v1.7.3
BUILD_IMAGE = golang:1.20.1
BASE_IMAGE = zonghaishang/delve:v1.20.1

os_arch:=$(shell uname)_$(shell arch)

Expand Down Expand Up @@ -70,6 +72,15 @@ transcoder.amd64:
transcoder.arm64:
GOOS=linux GOARCH=arm64 DOCKER_BUILD_OPTS="--platform=linux/arm64" make transcoder.arch

trace:
make trace.arch

trace.amd64:
GOOS=linux GOARCH=amd64 DOCKER_BUILD_OPTS="--platform=linux/amd64" make trace.arch

trace.arm64:
GOOS=linux GOARCH=arm64 DOCKER_BUILD_OPTS="--platform=linux/arm64" make trace.arch

ant:
make ant.arch

Expand Down Expand Up @@ -124,6 +135,22 @@ pkg-trans.amd64:
pkg-trans.arm64:
GOOS=linux GOARCH=arm64 DOCKER_BUILD_OPTS="--platform=linux/arm64" make pkg-trans.arch

##
pkg-trace:
ifeq ("$(os_arch)","Darwin_arm64")
make pkg-trace.amd64
else ifeq ("$(os_arch)","Darwin_i386")
make pkg-trace.amd64
else
make pkg-trace.arch
endif

pkg-trace.amd64:
GOOS=linux GOARCH=amd64 DOCKER_BUILD_OPTS="--platform=linux/amd64" make pkg-trace.arch

pkg-trace.arm64:
GOOS=linux GOARCH=arm64 DOCKER_BUILD_OPTS="--platform=linux/arm64" make pkg-trace.arch

pkg-ant:
make pkg-ant.arch

Expand Down Expand Up @@ -207,6 +234,21 @@ transcoder.arch:
-w /go/src/${PROJECT_NAME} ${BUILD_IMAGE} \
bash /go/src/${PROJECT_NAME}/etc/script/compile-transcoder.sh

trace.arch:
mkdir -p /tmp/go-build-cache
docker run --rm ${DOCKER_BUILD_OPTS} \
-e PLUGIN_TRACE=${TARGET} \
-e PLUGIN_TRACE_PREFIX=${TRACE_PREFIX} \
-e PLUGIN_PROJECT_NAME=${PROJECT_NAME} \
-e PLUGIN_OS=${PLUGIN_GOOS} \
-e PLUGIN_ARCH=${PLUGIN_GOARCH} \
-e PLUGIN_GIT_VERSION=${GIT_VERSION} \
-v $(shell go env GOPATH)/pkg/mod/:/go/pkg/mod/ \
-v ${FULL_PROJECT_NAME}:/go/src/${PROJECT_NAME} \
-v /tmp/go-build-cache:/root/.cache/go-build \
-w /go/src/${PROJECT_NAME} ${BUILD_IMAGE} \
bash /go/src/${PROJECT_NAME}/etc/script/compile-trace.sh

compile-codec:
@rm -rf build/codecs/${PLUGIN_TARGET}
GO111MODULE=on ${BUILD_OPTS} go build \
Expand Down Expand Up @@ -243,15 +285,34 @@ compile-transcoder:
cp configs/transcoders/${PLUGIN_TARGET}/*.json build/transcoders/${PLUGIN_TARGET}
@echo "compile transcoder ${PLUGIN_TARGET} complete"

compile-trace:
@rm -rf build/traces/${PLUGIN_TARGET}
@rm -rf build/codecs/bundle/support/traces/${PLUGIN_TARGET}
GO111MODULE=on ${BUILD_OPTS} go build \
--buildmode=plugin -mod=mod \
-gcflags "all=-N -l" \
-o ${PLUGIN_TRACE_OUTPUT} ${PLUGIN_PROJECT_NAME}/plugins/traces/${PLUGIN_TARGET}/main
@mkdir -p build/traces/${PLUGIN_TARGET}
mkdir -p build/codecs/bundle/support/traces/${PLUGIN_TARGET}
@mv ${PLUGIN_TRACE_OUTPUT} build/traces/${PLUGIN_TARGET}
@cd build/traces/${PLUGIN_TARGET} && $(shell which md5sum) -b ${PLUGIN_TRACE_OUTPUT} | cut -d' ' -f1 > ${PLUGIN_TRACE_PREFIX}-${PLUGIN_TARGET}.md5
@cp configs/traces/${PLUGIN_TARGET}/*.json build/traces/${PLUGIN_TARGET}
cp -r build/traces/${PLUGIN_TARGET} build/codecs/bundle/support/traces/
@echo "compile trace ${PLUGIN_TARGET} complete"

ant.arch:
bash ${FULL_PROJECT_NAME}/etc/ant/stop.sh
docker run --rm ${DOCKER_BUILD_OPTS} \
@test ! -f ~/.netrc && touch ~/.netrc || true
docker run -it --rm ${DOCKER_BUILD_OPTS} \
-e PLUGIN_OS=${PLUGIN_GOOS} \
-e PLUGIN_ARCH=${PLUGIN_GOARCH} \
-e PROJECT_NAME=${PROJECT_NAME} \
-e GIT_TERMINAL_PROMPT=1 \
-e SIDECAR_PROJECT_NAME=${SIDECAR_GITLAB_PROJECT_NAME} \
-v $(shell go env GOPATH)/pkg/mod/:/go/pkg/mod/ \
-v ${FULL_PROJECT_NAME}:/go/src/${PROJECT_NAME} \
-v $(shell go env GOCACHE):/root/.cache/go-build \
-v ~/.netrc:/root/.netrc \
-v $(shell go env GOPATH)/src/${SIDECAR_GITLAB_PROJECT_NAME}:/go/src/${SIDECAR_GITLAB_PROJECT_NAME} \
-w /go/src/${SIDECAR_GITLAB_PROJECT_NAME} ${BUILD_IMAGE} \
bash /go/src/${PROJECT_NAME}/etc/script/compile.sh
Expand Down Expand Up @@ -310,6 +371,24 @@ pkg-trans.arch:
bash /go/src/${PROJECT_NAME}/etc/script/package-transcoder.sh
@echo "package transcoder ${TARGET} complete"

pkg-trace.arch:
mkdir -p /tmp/go-build-cache
docker run --rm ${DOCKER_BUILD_OPTS} \
-e PLUGIN_TRACE=${TARGET} \
-e PLUGIN_TRACE_PREFIX=${TRACE_PREFIX} \
-e PLUGIN_PROJECT_NAME=${PROJECT_NAME} \
-e PLUGIN_OS=${PLUGIN_GOOS} \
-e PLUGIN_ARCH=${PLUGIN_GOARCH} \
-e PLUGIN_BUILD_PLATFORM=$(shell uname) \
-e PLUGIN_BUILD_PLATFORM_ARCH=$(shell arch) \
-e PLUGIN_GIT_VERSION=${GIT_VERSION} \
-v ${FULL_PROJECT_NAME}:/go/src/${PROJECT_NAME} \
-v /tmp/go-build-cache:/root/.cache/go-build \
-v $(shell go env GOPATH)/pkg/mod/:/go/pkg/mod/ \
-w /go/src/${PROJECT_NAME} ${BASE_IMAGE} \
bash /go/src/${PROJECT_NAME}/etc/script/package-trace.sh
@echo "package trace ${TARGET} complete"

pkg-ant.arch:
docker run --rm ${DOCKER_BUILD_OPTS} \
-e PLUGIN_OS=${PLUGIN_GOOS} \
Expand Down
8 changes: 4 additions & 4 deletions go-plugin/build/image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM golang:1.17.9
FROM golang:1.20.1
MAINTAINER [email protected]

ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn,direct

RUN go install github.com/go-delve/delve/cmd/dlv@v1.7.3
RUN go install github.com/go-delve/delve/cmd/dlv@v1.20.1

# install tools.
RUN apt update && apt -y install net-tools sudo openbsd-inetd telnet tcpdump zip iptables neovim sysstat iproute2 iftop
Expand All @@ -18,8 +18,8 @@ WORKDIR /go

# how to use this Dockefile ?
# docker buildx create --use --name=builder --driver docker-container
# docker buildx build --platform linux/arm64,linux/amd64,linux/386 -t zonghaishang/delve:v1.7.3 . --push
# docker buildx build --platform linux/arm64,linux/amd64,linux/386 -t zonghaishang/delve:v1.20.1 . --push
# docker buildx rm builder

# how to use this Dockefile build local image for development ?
# docker build -t zonghaishang/delve:v1.7.3 .
# docker build -t zonghaishang/delve:v1.20.1 .
10 changes: 10 additions & 0 deletions go-plugin/configs/traces/skywalking/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"reporter": "gRPC",
"plugin_type": "skywalking",
"backend_service": "${SKY_WALKING_ADDRESS}",
"service_name": "${APPNAME}",
"max_send_queue_size":"${MAX_SEND_QUEUE_SIZE}",
"mosn_generator_span_enabled" :"${MOSN_GENERATOR_SAPN_ENABLED}",
"vmmode":"${VMMODE}",
"pod_name":"${POD_NAME}"
}
8 changes: 8 additions & 0 deletions go-plugin/configs/traces/skywalking/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name" : "skywalking",
"kind": "trace",
"dependencies": [{
"mosn_api": "v0.0.0-20211217011300-b851d129be01",
"mosn_pkg": "v0.0.0-20211217101631-d914102d1baf"
}]
}
13 changes: 13 additions & 0 deletions go-plugin/configs/traces/zipkin/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"reporter": "http",
"service_name": "${APPNAME}",
"mosn_generator_span_enabled": "${MOSN_GENERATOR_SAPN_ENABLED}",
"http": {
"batch_size": "${BATCH_SIZE}",
"address": "${ZIPKIN_ADDRESS}"
},
"kafka": {
"topic": "${KAFKA_TOPIC}",
"address": "${ZIPKIN_ADDRESS}"
}
}
8 changes: 8 additions & 0 deletions go-plugin/configs/traces/zipkin/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name" : "zipkin",
"kind": "trace",
"dependencies": [{
"mosn_api": "v0.0.0-20211217011300-b851d129be01",
"mosn_pkg": "v0.0.0-20211217101631-d914102d1baf"
}]
}
30 changes: 30 additions & 0 deletions go-plugin/etc/script/compile-trace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash


SHELL=/bin/bash

go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOPRIVATE=gitlab.alipay-inc.com,code.alipay.com

# build trace plugins
if [[ -n "${PLUGIN_TRACE}" ]]; then
tracers=(${PLUGIN_TRACE//,/ })
rm -rf /go/src/${PLUGIN_PROJECT_NAME}/build/traces
for name in "${tracers[@]}"; do
export PLUGIN_TARGET=${name}
export PLUGIN_TRACE_OUTPUT=${PLUGIN_TRACE_PREFIX}-${PLUGIN_TARGET}.so
if [[ -n "${PLUGIN_GIT_VERSION}" ]]; then
export PLUGIN_TRACE_OUTPUT=${PLUGIN_TRACE_PREFIX}-${PLUGIN_TARGET}-${PLUGIN_GIT_VERSION}.so
fi
# check BUILD_OPTS
if [[ -n ${PLUGIN_OS} && -n ${PLUGIN_ARCH} ]]; then
build_opts="GOOS=${PLUGIN_OS} GOARCH=${PLUGIN_ARCH}"
export BUILD_OPTS=${build_opts}
echo "compiling trace ${name} for ${PLUGIN_OS} ${PLUGIN_ARCH} ..."
else
echo "compiling trace ${name} for linux $(dpkg --print-architecture) ..."
fi
make compile-trace
done
fi
5 changes: 1 addition & 4 deletions go-plugin/etc/script/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ go env -w GOPRIVATE=gitlab.alipay-inc.com,code.alipay.com
export PLUGIN_PROJECT=${PROJECT_NAME}
export SIDECAR_PROJECT=${SIDECAR_PROJECT_NAME}

# update sidecar dependency.
go mod tidy
go mod download

MAJOR_VERSION=$(cat VERSION)
GIT_VERSION=$(git log -1 --pretty=format:%h)

Expand Down Expand Up @@ -44,6 +40,7 @@ if [ -f mosn ]; then
md5sum -b mosn | cut -d' ' -f1 >mosn-${MAJOR_VERSION}-${GIT_VERSION}.md5
mv mosn-${MAJOR_VERSION}-${GIT_VERSION}.md5 "/go/src/${PLUGIN_PROJECT}/build/sidecar/binary/mosn-${MAJOR_VERSION}-${GIT_VERSION}.md5"
mv mosn "/go/src/${PLUGIN_PROJECT}/build/sidecar/binary/mosn"
cp "/go/src/${SIDECAR_PROJECT}/go.mod" "/go/src/${PLUGIN_PROJECT}/build/sidecar/binary/local.mod"
echo "compile success"
else
echo "compile failed"
Expand Down
1 change: 0 additions & 1 deletion go-plugin/etc/script/copy-upgrade-mod.sh

This file was deleted.

37 changes: 37 additions & 0 deletions go-plugin/etc/script/package-trace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# package trace plugins
if [[ -n "${PLUGIN_TRACE}" ]]; then
if [[ -n ${PLUGIN_OS} && -n ${PLUGIN_ARCH} ]]; then
bash /go/src/"${PLUGIN_PROJECT_NAME}"/etc/script/compile-trace.sh
elif [[ "${PLUGIN_BUILD_PLATFORM}" == "Darwin" && "${PLUGIN_BUILD_PLATFORM_ARCH}" == "arm64" ]]; then
# apple m1 chip compile plugin(amd64)
export PLUGIN_OS="linux"
export PLUGIN_ARCH="amd64"
bash /go/src/"${PLUGIN_PROJECT_NAME}"/etc/script/compile-trace.sh
fi
fi

pkg_version=
if [[ -f "/go/src/${PLUGIN_PROJECT_NAME}/VERSION.txt" ]]; then
pkg_version=$(cat /go/src/${PLUGIN_PROJECT_NAME}/VERSION.txt)
fi

# package transcoder plugins
if [[ -n "${PLUGIN_TRACE}" ]]; then
tracers=(${PLUGIN_TRACE//,/ })
for name in "${tracers[@]}"; do
PLUGIN_TRACE_ZIP_OUTPUT=${name}.zip
if [[ -n "${pkg_version}" ]]; then
PLUGIN_TRACE_ZIP_OUTPUT=${name}-${pkg_version}.zip
fi
rm -rf /go/src/${PLUGIN_PROJECT_NAME}/build/target/traces/${PLUGIN_TRACE_ZIP_OUTPUT}
mkdir -p /go/src/${PLUGIN_PROJECT_NAME}/build/target/traces/
if [ -d "/go/src/${PLUGIN_PROJECT_NAME}/build/traces/${name}/" ]; then
cd /go/src/${PLUGIN_PROJECT_NAME}/build/traces/
echo "packaging trace ${name}..."
zip -r /go/src/${PLUGIN_PROJECT_NAME}/build/target/traces/${PLUGIN_TRACE_ZIP_OUTPUT} ${name} \
-x "stream_filters/*" -x "transcoders/*" -x "mosn_config.json"
fi
done
fi
54 changes: 46 additions & 8 deletions go-plugin/go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,59 @@
module mosn.io/extensions/go-plugin

go 1.14
go 1.18

require (
github.com/SkyAPM/go2sky v0.5.0
github.com/apache/dubbo-go-hessian2 v1.9.2 // dubbo
github.com/dubbogo/gost v1.11.25 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/stretchr/testify v1.7.0
github.com/valyala/fasthttp v1.31.0
github.com/openzipkin/zipkin-go v0.4.1
github.com/satori/go.uuid v1.2.0
github.com/stretchr/testify v1.8.1
github.com/valyala/fasthttp v1.40.0
google.golang.org/grpc v1.53.0
mosn.io/api v1.3.0
mosn.io/pkg v1.3.1-0.20230104081003-9c747062328a
)

require (
github.com/Shopify/sarama v1.37.2 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dubbogo/gost v1.11.25 // indirect
github.com/eapache/go-resiliency v1.3.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-syslog v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.3 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
mosn.io/api v0.0.0-20211217011300-b851d129be01
mosn.io/pkg v0.0.0-20211217101631-d914102d1baf
golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace (
github.com/klauspost/compress => github.com/klauspost/compress v1.13.5

github.com/rcrowley/go-metrics => github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
)
Loading