Skip to content

Commit 436949c

Browse files
authored
Fix 658 panic (#660)
* update read me * fix(collector-agent): panic: send on closed channel > #658 * remove close(ch) * spread agent log * limit redis version 6.0.2
1 parent b2c6d2e commit 436949c

21 files changed

+202
-164
lines changed

Changes-CN.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

DOC/PHP/Readme-CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)
2+
13
## 安装参照
24

35
### 依赖组件

DOC/PHP/Readme-KR.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)
2+
13
## 시작 가이드
24

35
### 요구

DOC/PHP/Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)
2+
13
## Supported
24

35
[pinpoint-apm/pinpoint-php-aop#supported-librariesframework ](https://github.com/pinpoint-apm/pinpoint-php-aop?tab=readme-ov-file#supported-librariesframework)

DOC/PY/Readme-CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)
2+
13
# pinpoint-py agent 使用说明
24

35
## 入门指南

DOC/PY/Readme-KR.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)
2+
13
# pinpoint-py agent 가이드
24

35
## 시작 가이드

DOC/PY/Readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Tutorial for pinpoint-py agent
1+
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)
2+
23

34
## Getting Started
45

@@ -15,7 +16,7 @@
1516
$ pip install pinpointPy
1617
```
1718

18-
### How to Use
19+
### Choose your framework
1920

2021

2122
#### 1.1 Flask

README.md

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,91 @@
11
![pinpoint](images/logo.png)
22

3-
[![CI](https://github.com/pinpoint-apm/pinpoint-c-agent/actions/workflows/main.yml/badge.svg)](https://github.com/pinpoint-apm/pinpoint-c-agent/actions/workflows/main.yml) [![Gitter](https://badges.gitter.im/naver/pinpoint-c-agent.svg)](https://gitter.im/naver/pinpoint-c-agent?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![codecov](https://codecov.io/gh/pinpoint-apm/pinpoint-c-agent/branch/master/graph/badge.svg?token=KswbmFvWp3)](https://codecov.io/gh/pinpoint-apm/pinpoint-c-agent) [![License](https://img.shields.io/github/license/pinpoint-apm/pinpoint-c-agent)](LICENSE)
4-
3+
[![CI](https://github.com/pinpoint-apm/pinpoint-c-agent/actions/workflows/main.yml/badge.svg)](https://github.com/pinpoint-apm/pinpoint-c-agent/actions/workflows/main.yml) [![Gitter](https://badges.gitter.im/naver/pinpoint-c-agent.svg)](https://gitter.im/naver/pinpoint-c-agent?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![codecov](https://codecov.io/gh/pinpoint-apm/pinpoint-c-agent/branch/master/graph/badge.svg?token=KswbmFvWp3)](https://codecov.io/gh/pinpoint-apm/pinpoint-c-agent) [![License](https://img.shields.io/github/license/pinpoint-apm/pinpoint-c-agent)](LICENSE) \
4+
`pinpoint_php_ext:` [![pinpoint_php](https://img.shields.io/badge/php-7.1~8.3-8892BF)](https://pecl.php.net/package/pinpoint_php)\
5+
`pinpoint-php-aop:` ![Packagist License](https://img.shields.io/packagist/l/pinpoint-apm/pinpoint-php-aop)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/pinpoint-apm/pinpoint-php-aop.svg?style=flat-square)](https://packagist.org/packages/pinpoint-apm/pinpoint-php-aop)\
7+
`pinpointpy:` ![PyPI - License](https://img.shields.io/pypi/l/pinpointpy)
8+
[![pypi](https://badge.fury.io/py/pinpointpy.svg)](https://pypi.org/project/pinpointpy/)
9+
![PyPI - Downloads](https://img.shields.io/pypi/dm/pinpointpy)
510

611

712
**Visit [our official website](http://pinpoint-apm.github.io/pinpoint/) for more information and [the Latest updates on Pinpoint](https://pinpoint-apm.github.io/pinpoint/news.html)**
813

914

10-
The current stable version is [the Latest](https://github.com/pinpoint-apm/pinpoint-c-agent/releases).
15+
# Pinpoint `C` Agent
16+
17+
> What's `C`
18+
19+
1. Use `C/Cpp` common API
20+
2. `C`ross-platform: windows/*nux/macOS
21+
22+
Pinpoint C Agent helps your monitor your PHP/PYTHON applications into [pinpoint-apm](https://github.com/pinpoint-apm/pinpoint).\
23+
Our advantage:
24+
1. Continuous maintenance and optimization. (Since Jul 31,2018)
25+
2. Auto-injection, that means less aggression against your code.
26+
- python: leverage [PEP 318 Decorator](https://peps.python.org/pep-0318/)
27+
- php: leverage `CG(*_table)` in php kernel and AST parser([nikic/PHP-Parser](https://github.com/nikic/PHP-Parser))
28+
3. Cross-platform: windows/*nux/macOS. It helps address the problems even when you developing.
29+
30+
## Python Agent
31+
32+
> py 3.8+
33+
34+
`pip install pinpointPy`
35+
36+
[Full guide for python](DOC/PY/Readme.md)
1137

12-
# Pinpoint Agent
38+
## PHP Agent
1339

14-
It is an agent written by C++, PHP and Python languages. And we hope to support other languages by this agent. Until now, it supports **_PHP_**, **_C/CPP_** and **_PYTHON_**.
40+
> php 7.1+
1541
16-
## Overview Pinpoint Agent
42+
1. Install extension
1743

18-
### How does it work
44+
` pecl install pinpoint_php `
1945

20-
![How does it work](images/pinpoint_v0.5.x.png)
46+
2. Import pinpoint aspect plugin
2147

22-
### Pinpoint Agent
48+
`composer require pinpoint-apm/pinpoint-php-aop`
2349

24-
language| tutorial
25-
---|---
26-
php|[EN](DOC/PHP/Readme.md) [CN](DOC/PHP/Readme-CN.md) [KR](DOC/PHP/Readme-KR.md)
27-
python3|[EN](DOC/PY/Readme.md) [CN](DOC/PY/Readme-CN.md) [KR](DOC/PY/Readme-KR.md)
28-
c/cpp|[English](DOC/C-CPP/Readme.md)
50+
[Full guide for PHP](DOC/PHP/Readme.md)
2951

30-
> [Try playground](/testapps/readme.md)
52+
## C/CPP built in API
53+
54+
[Full guide for C](DOC/C-CPP/Readme.md)
55+
56+
57+
## Our agent playground
58+
59+
`cd testapps && docker compose build --build-arg PHP_VERSION=7.4 && docker compose up`
60+
61+
[Tested project](/testapps/readme.md)
3162

3263
### Blogs
3364

34-
- Intro pinpoint php aop : https://github.com/pinpoint-apm/pinpoint-php-aop/wiki/Intro-pinpoint-php-aop
35-
- pinpoint php aop 内部原理: https://github.com/pinpoint-apm/pinpoint-php-aop/wiki/pinpoint-php-aop-%E5%86%85%E9%83%A8%E5%8E%9F%E7%90%86
36-
- pinpoint php aop 내부 원리: https://github.com/pinpoint-apm/pinpoint-php-aop/wiki/pinpoint-php-aop-%EB%82%B4%EB%B6%80-%EC%9B%90%EB%A6%AC
65+
- [Intro pinpoint php aop](https://github.com/pinpoint-apm/pinpoint-php-aop/wiki/Intro-pinpoint-php-aop)
66+
- [pinpoint php aop 内部原理](https://github.com/pinpoint-apm/pinpoint-php-aop/wiki/pinpoint-php-aop-%E5%86%85%E9%83%A8%E5%8E%9F%E7%90%86)
67+
- [pinpoint php aop 내부 원리](https://github.com/pinpoint-apm/pinpoint-php-aop/wiki/pinpoint-php-aop-%EB%82%B4%EB%B6%80-%EC%9B%90%EB%A6%AC)
3768

3869

3970
## Contact Us
4071

41-
* Submit an [issue](https://github.com/pinpoint-apm/pinpoint-c-agent/issues)
72+
* Submit an [issue](https://github.com/pinpoint-apm/pinpoint-c-agent/issues) 👍👍
73+
* [Email Us](mailto:dl_cd_pinpoint@navercorp.com) 👍👍
4274
* [Gitter char room](https://gitter.im/naver/pinpoint-c-agent)
43-
* dl_cd_pinpoint@navercorp.com
44-
* Chinese Community (QQ Group: 882020485)
75+
* QQ us (QQ Group: 882020485)
4576
<details>
4677
<summary> show more
4778
</summary>
4879

4980
QQ Group1: 897594820 | QQ Group2: 812507584 | QQ Group3: 882020485| DING Group : 21981598
5081
:----------------: |:----------------: | :-----------: | :-----------:
5182
![QQ Group1](images/NAVERPinpoint.png) | ![QQ Group2](images/NAVERPinpoint2.png)| ![QQ Group3](images/NAVERPinpoint3.png)| ![DING Group](images/NaverPinpoint交流群-DING.jpg)
52-
5383
</details>
5484

5585
## Contributing
5686

87+
Thanks all [![GitHub contributors](https://img.shields.io/github/contributors/pinpoint-apm/pinpoint-c-agent)](https://github.com/pinpoint-apm/pinpoint-c-agent/graphs/contributors)
88+
5789
We are looking forward to your contributions via pull requests.
5890

5991
## License

collector-agent/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
## v0.6.4
2+
- fix: panic: send on closed channel #658
3+
14
## v0.5.3 2024.05.31
25
- support go install
6+
37
## [v0.5.0] start time in ms
48
- return current time in ms

collector-agent/agent/AgentRouter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ func (manager *AgentRouter) Clean() {
189189
manager.rwMutex.RUnlock()
190190
manager.rwMutex.Lock()
191191
delete(manager.AgentMap, id)
192-
agent.Stop()
193192
manager.rwMutex.Unlock()
194193
manager.rwMutex.RLock()
194+
//shrink rwMutex scope
195+
agent.Stop()
195196
}
196197
}
197198
manager.rwMutex.RUnlock()

collector-agent/agent/ErrorAnalysis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (e *ErrorAnalysisFilter) sendExpMetaData(meta *v1.PExceptionMetaData) {
3232
defer conn.Close()
3333
client := v1.NewMetadataClient(conn)
3434

35-
ctx, cancel := common.BuildPinpointCtx(config.MetaDataTimeWaitSec, e.md)
35+
ctx, cancel := common.BuildPinpointCtx(config.MetaDataTimeWait, e.md)
3636
defer cancel()
3737
result, err := client.RequestExceptionMetaData(ctx, meta)
3838
if err != nil {

collector-agent/agent/GrpcAgent.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type GrpcAgent struct {
3131
requestCounter RequestProfiler
3232
utReport *UrlTemplateReport
3333
tasksGroup sync.WaitGroup
34-
tSpanCh chan *TSpan
34+
tSpanBufCh chan *TSpan
3535
ExitCh chan bool
3636
log *log.Entry
3737
errorAnalysisFilter *ErrorAnalysisFilter
@@ -52,7 +52,7 @@ func (agent *GrpcAgent) SendSpan(span *TSpan) {
5252
log.Warnf("sendSpan met:%s", r)
5353
}
5454
}()
55-
agent.tSpanCh <- span
55+
agent.tSpanBufCh <- span
5656
}
5757

5858
func (agent *GrpcAgent) GetLastBusyTime() int64 {
@@ -61,7 +61,6 @@ func (agent *GrpcAgent) GetLastBusyTime() int64 {
6161

6262
func (agent *GrpcAgent) Stop() {
6363
agent.log.Warn("I'm exiting")
64-
close(agent.tSpanCh)
6564
close(agent.ExitCh)
6665
agent.tasksGroup.Wait()
6766
agent.log.Warn("I'm exit")
@@ -85,7 +84,7 @@ func (agent *GrpcAgent) String() string {
8584
return fmt.Sprintf("id:%s name:%s type:%d startTime:%s", agent.AgentId, agent.agentName, agent.agentType, agent.StartTime)
8685
}
8786

88-
func (agent *GrpcAgent) agentOnline() error {
87+
func (agent *GrpcAgent) handleRegisterAgent() error {
8988

9089
commandTask := sync.WaitGroup{}
9190
defer commandTask.Wait()
@@ -107,7 +106,7 @@ func (agent *GrpcAgent) agentOnline() error {
107106
}()
108107

109108
client := v1.NewAgentClient(conn)
110-
ctx, cancel := common.BuildPinpointCtx(config.GrpcConTextTimeOutSec, agent.BaseMD)
109+
ctx, cancel := common.BuildPinpointCtx(config.GrpcConTextTimeOut, agent.BaseMD)
111110
defer cancel()
112111
pbAgentInfo := common.GetPBAgentInfo(agent.agentType)
113112
agent.log.Debugf("RequestAgentInfo pbAgentInfo:%v", pbAgentInfo)
@@ -136,6 +135,7 @@ func (agent *GrpcAgent) agentOnline() error {
136135
// handle command
137136
go agent.handleCommand(conn, &commandTask)
138137

138+
agent.log.Info("agent online ")
139139
agent.AgentOnLine = true
140140

141141
defer func() { agent.AgentOnLine = false }()
@@ -161,20 +161,18 @@ func (agent *GrpcAgent) agentOnline() error {
161161
}
162162

163163
func (agent *GrpcAgent) keepAgentOnline() {
164-
agent.tasksGroup.Add(1)
165164
defer agent.tasksGroup.Done()
166165

167166
for {
168-
if err := agent.agentOnline(); err != nil {
167+
if err := agent.handleRegisterAgent(); err != nil {
169168
agent.log.Infof("agent online exit:%s ", err)
170169
}
171170

172171
config := common.GetConfig()
173-
if common.WaitChannelEvent(agent.ExitCh, config.PingInterval) == common.E_AGENT_STOPPING {
172+
if common.WaitChannelEvent(agent.ExitCh, config.AgentReTryTimeout) == common.E_AGENT_STOPPING {
174173
break
175174
}
176175
}
177-
agent.spanSender.Stop()
178176
}
179177

180178
func (agent *GrpcAgent) registerFilter() {
@@ -235,7 +233,7 @@ func (agent *GrpcAgent) sendStat() {
235233
for {
236234
msg := CollectPStateMessage(agent.requestCounter.GetMaxAvg, agent.requestCounter.GetReqTimeProfiler)
237235

238-
agent.log.Debugf("%v", msg)
236+
agent.log.Debugf("PStatMessage: %v", msg)
239237
if err := stream.Send(msg); err != nil {
240238
agent.log.Warn(err)
241239
break
@@ -270,7 +268,7 @@ func (agent *GrpcAgent) sendStat() {
270268
}
271269

272270
func (agent *GrpcAgent) uploadStatInfo() {
273-
agent.tasksGroup.Add(1)
271+
274272
defer agent.tasksGroup.Done()
275273

276274
for {
@@ -309,22 +307,25 @@ func (agent *GrpcAgent) Init(id, _name string, _type int32, StartTime string) {
309307

310308
config := common.GetConfig()
311309

312-
agent.tSpanCh = make(chan *TSpan, config.AgentChannelSize)
310+
agent.tSpanBufCh = make(chan *TSpan, config.AgentChannelSize)
313311
agent.ExitCh = make(chan bool)
314-
agent.spanSender = createSpanSender(agent.BaseMD, agent.ExitCh)
312+
agent.spanSender = createSpanSender(agent.BaseMD, agent.ExitCh, &agent.tasksGroup, agent.log)
315313
agent.requestCounter.CTime = time.Now().Unix()
316314

317315
agent.errorAnalysisFilter = createErrorAnalysisFilter(agent.BaseMD)
318316

319317
agent.registerFilter()
318+
agent.tasksGroup.Add(1)
320319
// start agentOnline
321320
go agent.keepAgentOnline()
322321
// send stat
322+
agent.tasksGroup.Add(1)
323323
go agent.uploadStatInfo()
324324

325325
}
326326

327327
func (agent *GrpcAgent) Start() {
328+
agent.tasksGroup.Add(1)
328329
go agent.consumeJsonSpan()
329330
}
330331

@@ -463,18 +464,17 @@ func (agent *GrpcAgent) handleCommand(conn *grpc.ClientConn, wg *sync.WaitGroup)
463464

464465
func (agent *GrpcAgent) consumeJsonSpan() {
465466
defer agent.tasksGroup.Done()
466-
agent.tasksGroup.Add(1)
467-
468-
for span := range agent.tSpanCh {
469-
if span == nil {
470-
agent.log.Infof("agent:%v get EOF", agent)
471-
return
472-
}
473-
474-
for _, filter := range agent.spanFilters {
475-
if !filter.Interceptor(span) {
476-
break
467+
for {
468+
select {
469+
case span := <-agent.tSpanBufCh:
470+
for _, filter := range agent.spanFilters {
471+
if !filter.Interceptor(span) {
472+
break
473+
}
477474
}
475+
case <-agent.spanSender.exitCh:
476+
agent.log.Warn("consumeJsonSpan task done, as agent exit")
477+
return
478478
}
479479
}
480480
}

0 commit comments

Comments
 (0)