Skip to content

Commit 8ad6d5e

Browse files
authored
feat: force disable (#22)
check FORCE_DISABLE_PINPOINT_AGENT env * split build.yml into aop and libraries * v1.0.2 -> v1.0.3
1 parent 6934aee commit 8ad6d5e

File tree

22 files changed

+235
-151
lines changed

22 files changed

+235
-151
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Test libraries
2+
3+
on: [workflow_dispatch,published,pull_request]
4+
5+
jobs:
6+
go16:
7+
runs-on: ubuntu-latest
8+
container: ghcr.io/pinpoint-apm/pinpoint-c-agent/golang-build-env-1.16:latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: libs test
12+
run: |
13+
cd libs
14+
for dir in * ; do cd $dir; go mod tidy; go test -v; cd ..; done
15+
16+
- name: compile test mux apps
17+
run: |
18+
cd testapps/mux
19+
GOOS=linux GOARCH=amd64 go mod tidy
20+
GOOS=linux GOARCH=amd64 go build -o testapp
21+
- name: compile test echo apps
22+
run: |
23+
cd testapps/echo
24+
GOOS=linux GOARCH=amd64 go mod tidy
25+
GOOS=linux GOARCH=amd64 go build -o testapp
26+
go13:
27+
runs-on: ubuntu-latest
28+
container: ghcr.io/pinpoint-apm/pinpoint-c-agent/golang-build-env-1.13:latest
29+
steps:
30+
- uses: actions/checkout@v2
31+
- name: libs test
32+
run: |
33+
cd libs
34+
for dir in * ; do cd $dir; go mod tidy; go test -v; cd ..; done
35+
36+
- name: compile test mux apps
37+
run: |
38+
cd testapps/mux
39+
GOOS=linux GOARCH=amd64 go mod tidy
40+
GOOS=linux GOARCH=amd64 go build -o testapp
41+
- name: compile test echo apps
42+
run: |
43+
cd testapps/echo
44+
GOOS=linux GOARCH=amd64 go mod tidy
45+
GOOS=linux GOARCH=amd64 go build -o testapp

.github/workflows/main.yml

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build
1+
name: Test Aop,asm,common
22

33
on: [push, pull_request, workflow_dispatch]
44

@@ -12,37 +12,18 @@ jobs:
1212
run : |
1313
cd asm && mkdir build && cd build && cmake .. && make
1414
ctest -T Test
15-
ctest -T Coverage
1615
- name: test asm-go
1716
run: |
1817
cd asm
19-
go test -v -coverprofile cover.out .
18+
go test -v .
2019
- name: api test
2120
run: |
2221
cd common
23-
go test -v -coverprofile cover.out .
22+
go test -v .
2423
- name: aop test
2524
run: |
2625
cd aop
27-
go test -v -coverprofile cover.out .
28-
- name: libs test
29-
run: |
30-
cd libs
31-
for dir in * ; do cd $dir; go mod tidy; go test -v; cd ..; done
32-
33-
# - uses: actions/checkout@master
34-
# - uses: codecov/codecov-action@v2
35-
36-
- name: compile test mux apps
37-
run: |
38-
cd testapps/mux
39-
GOOS=linux GOARCH=amd64 go mod tidy
40-
GOOS=linux GOARCH=amd64 go build -o testapp
41-
- name: compile test echo apps
42-
run: |
43-
cd testapps/echo
44-
GOOS=linux GOARCH=amd64 go mod tidy
45-
GOOS=linux GOARCH=amd64 go build -o testapp
26+
go test -v .
4627
4728
go13:
4829
runs-on: ubuntu-latest
@@ -68,23 +49,7 @@ jobs:
6849
cd aop
6950
go test -v -coverprofile cover.out .
7051
71-
- name: libs test
72-
run: |
73-
cd libs
74-
for dir in * ; do cd $dir; go mod tidy; go test -v; cd ..; done
75-
7652
- name: Upload coverage to Codecov
7753
uses: codecov/codecov-action@v2
7854
# with:
79-
# files:*.gcov,cover.out
80-
81-
- name: compile test mux apps
82-
run: |
83-
cd testapps/mux
84-
GOOS=linux GOARCH=amd64 go mod tidy
85-
GOOS=linux GOARCH=amd64 go build -o testapp
86-
- name: compile test echo apps
87-
run: |
88-
cd testapps/echo
89-
GOOS=linux GOARCH=amd64 go mod tidy
90-
GOOS=linux GOARCH=amd64 go build -o testapp
55+
# files:*.gcov,cover.out

aop/pinpoint.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"errors"
2121
"reflect"
2222
"unsafe"
23+
24+
"github.com/pinpoint-apm/go-aop-agent/common"
2325
)
2426

2527
// #cgo CFLAGS: -DNTEST
@@ -33,6 +35,11 @@ func init() {
3335
}
3436

3537
func AddHookP_CALL(iSrc, iTarget, iTrampoline_func interface{}) error {
38+
39+
if common.AgentIsDisabled() {
40+
return errors.New("agent disabled")
41+
}
42+
3643
src := reflect.ValueOf(iSrc)
3744
target := reflect.ValueOf(iTarget)
3845
trampoline_func := reflect.ValueOf(iTrampoline_func)
@@ -70,6 +77,10 @@ func AddHookP_CALL(iSrc, iTarget, iTrampoline_func interface{}) error {
7077
}
7178

7279
func AddHookP_JMP(iSrc, iTarget, iTrampoline_func interface{}) error {
80+
if common.AgentIsDisabled() {
81+
return errors.New("agent disabled")
82+
}
83+
7384
src := reflect.ValueOf(iSrc)
7485
target := reflect.ValueOf(iTarget)
7586
trampoline_func := reflect.ValueOf(iTrampoline_func)
@@ -104,6 +115,11 @@ func AddHookP_JMP(iSrc, iTarget, iTrampoline_func interface{}) error {
104115
* @return {*}
105116
*/
106117
func AddHook(iSrc, iTarget, iTrampoline_func interface{}) error {
118+
119+
if common.AgentIsDisabled() {
120+
return errors.New("agent disabled")
121+
}
122+
107123
src := reflect.ValueOf(iSrc)
108124
target := reflect.ValueOf(iTarget)
109125
trampoline_func := reflect.ValueOf(iTrampoline_func)

aop/pinpoint_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package aop
1818

1919
import (
20+
"os"
2021
"runtime"
2122
"testing"
2223
)
@@ -436,3 +437,21 @@ func TestAddHookP_CALL(t *testing.T) {
436437
}
437438

438439
}
440+
441+
func TestAgentDisable(t *testing.T) {
442+
os.Setenv("FORCE_DISABLE_PINPOINT_AGENT", "True")
443+
444+
if err := AddHookP_CALL(callRaw, fakeRaw, hookRawTrampoline); err == nil {
445+
t.Log("AddHookP_CALL failed")
446+
t.Fail()
447+
}
448+
449+
if err := AddHook(callRaw, fakeRaw, hookRawTrampoline); err == nil {
450+
t.Log("AddHookP_CALL failed")
451+
t.Fail()
452+
}
453+
if err := AddHookP_JMP(callRaw, fakeRaw, hookRawTrampoline); err == nil {
454+
t.Log("AddHookP_CALL failed")
455+
t.Fail()
456+
}
457+
}

common/pinpointCommon.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,16 @@ func IsIgnore(url string) bool {
428428
_, OK := ignoreUrls[url]
429429
return OK
430430
}
431+
432+
/**
433+
* @description:
434+
* if FORCE_DISABLE_PINPOINT_AGENT ==true, aop,middleware could not working after restart
435+
* user can evn FORCE_DISABLE_PINPOINT_AGENT=true to disable pinpoint agent without recompiling binary program
436+
*/
437+
func AgentIsDisabled() bool {
438+
if flag := os.Getenv("FORCE_DISABLE_PINPOINT_AGENT"); strings.ToLower(flag) == "true" {
439+
return true
440+
} else {
441+
return false
442+
}
443+
}

libs/httpClient/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/pinpoint-apm/go-aop-agent/libs/httpClient
22

33
go 1.16
44

5-
require github.com/pinpoint-apm/go-aop-agent v1.0.2
5+
require github.com/pinpoint-apm/go-aop-agent v1.0.3

libs/mongo/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ module github.com/pinpoint-apm/go-aop-agent/libs/mongo
33
go 1.16
44

55
require (
6-
github.com/pinpoint-apm/go-aop-agent v1.0.2
6+
github.com/pinpoint-apm/go-aop-agent v1.0.3
77
go.mongodb.org/mongo-driver v1.5.3
88
)

libs/pinpointEtcd/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
1919
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
2020
github.com/jonboulle/clockwork v0.2.2 // indirect
21-
github.com/pinpoint-apm/go-aop-agent v1.0.2
21+
github.com/pinpoint-apm/go-aop-agent v1.0.3
2222
github.com/prometheus/client_golang v1.11.0 // indirect
2323
github.com/soheilhy/cmux v0.1.5 // indirect
2424
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect

libs/redisv8/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ go 1.16
44

55
require (
66
github.com/go-redis/redis/v8 v8.11.0
7-
github.com/pinpoint-apm/go-aop-agent v1.0.2
7+
github.com/pinpoint-apm/go-aop-agent v1.0.3
88
)

libs/sql/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/pinpoint-apm/go-aop-agent/libs/sql
22

33
go 1.16
44

5-
require github.com/pinpoint-apm/go-aop-agent v1.0.2
5+
require github.com/pinpoint-apm/go-aop-agent v1.0.3

0 commit comments

Comments
 (0)