Skip to content

Commit

Permalink
Fix 658 panic (#660)
Browse files Browse the repository at this point in the history
* update read me

* fix(collector-agent): panic: send on closed channel

> #658
* remove close(ch)
* spread agent log
* limit redis version 6.0.2
  • Loading branch information
eeliu authored Aug 6, 2024
1 parent b2c6d2e commit 436949c
Show file tree
Hide file tree
Showing 21 changed files with 202 additions and 164 deletions.
31 changes: 0 additions & 31 deletions Changes-CN.md

This file was deleted.

2 changes: 2 additions & 0 deletions DOC/PHP/Readme-CN.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)

## 安装参照

### 依赖组件
Expand Down
2 changes: 2 additions & 0 deletions DOC/PHP/Readme-KR.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)

## 시작 가이드

### 요구
Expand Down
2 changes: 2 additions & 0 deletions DOC/PHP/Readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)

## Supported

[pinpoint-apm/pinpoint-php-aop#supported-librariesframework ](https://github.com/pinpoint-apm/pinpoint-php-aop?tab=readme-ov-file#supported-librariesframework)
Expand Down
2 changes: 2 additions & 0 deletions DOC/PY/Readme-CN.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)

# pinpoint-py agent 使用说明

## 入门指南
Expand Down
2 changes: 2 additions & 0 deletions DOC/PY/Readme-KR.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)

# pinpoint-py agent 가이드

## 시작 가이드
Expand Down
5 changes: 3 additions & 2 deletions DOC/PY/Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Tutorial for pinpoint-py agent
[English](Readme.md) | [中文](Readme-CN.md) | [한국어](Readme-KR.md)


## Getting Started

Expand All @@ -15,7 +16,7 @@
$ pip install pinpointPy
```

### How to Use
### Choose your framework


#### 1.1 Flask
Expand Down
76 changes: 54 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,91 @@
![pinpoint](images/logo.png)

[![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)

[![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) \
`pinpoint_php_ext:` [![pinpoint_php](https://img.shields.io/badge/php-7.1~8.3-8892BF)](https://pecl.php.net/package/pinpoint_php)\
`pinpoint-php-aop:` ![Packagist License](https://img.shields.io/packagist/l/pinpoint-apm/pinpoint-php-aop)
[![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)\
`pinpointpy:` ![PyPI - License](https://img.shields.io/pypi/l/pinpointpy)
[![pypi](https://badge.fury.io/py/pinpointpy.svg)](https://pypi.org/project/pinpointpy/)
![PyPI - Downloads](https://img.shields.io/pypi/dm/pinpointpy)


**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)**


The current stable version is [the Latest](https://github.com/pinpoint-apm/pinpoint-c-agent/releases).
# Pinpoint `C` Agent

> What's `C`
1. Use `C/Cpp` common API
2. `C`ross-platform: windows/*nux/macOS

Pinpoint C Agent helps your monitor your PHP/PYTHON applications into [pinpoint-apm](https://github.com/pinpoint-apm/pinpoint).\
Our advantage:
1. Continuous maintenance and optimization. (Since Jul 31,2018)
2. Auto-injection, that means less aggression against your code.
- python: leverage [PEP 318 Decorator](https://peps.python.org/pep-0318/)
- php: leverage `CG(*_table)` in php kernel and AST parser([nikic/PHP-Parser](https://github.com/nikic/PHP-Parser))
3. Cross-platform: windows/*nux/macOS. It helps address the problems even when you developing.

## Python Agent

> py 3.8+
`pip install pinpointPy`

[Full guide for python](DOC/PY/Readme.md)

# Pinpoint Agent
## PHP Agent

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_**.
> php 7.1+
## Overview Pinpoint Agent
1. Install extension

### How does it work
` pecl install pinpoint_php `

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

### Pinpoint Agent
`composer require pinpoint-apm/pinpoint-php-aop`

language| tutorial
---|---
php|[EN](DOC/PHP/Readme.md) [CN](DOC/PHP/Readme-CN.md) [KR](DOC/PHP/Readme-KR.md)
python3|[EN](DOC/PY/Readme.md) [CN](DOC/PY/Readme-CN.md) [KR](DOC/PY/Readme-KR.md)
c/cpp|[English](DOC/C-CPP/Readme.md)
[Full guide for PHP](DOC/PHP/Readme.md)

> [Try playground](/testapps/readme.md)
## C/CPP built in API

[Full guide for C](DOC/C-CPP/Readme.md)


## Our agent playground

`cd testapps && docker compose build --build-arg PHP_VERSION=7.4 && docker compose up`

[Tested project](/testapps/readme.md)

### Blogs

- Intro pinpoint php aop : https://github.com/pinpoint-apm/pinpoint-php-aop/wiki/Intro-pinpoint-php-aop
- 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
- 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
- [Intro pinpoint php aop](https://github.com/pinpoint-apm/pinpoint-php-aop/wiki/Intro-pinpoint-php-aop)
- [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)
- [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)


## Contact Us

* Submit an [issue](https://github.com/pinpoint-apm/pinpoint-c-agent/issues)
* Submit an [issue](https://github.com/pinpoint-apm/pinpoint-c-agent/issues) 👍👍
* [Email Us](mailto:[email protected]) 👍👍
* [Gitter char room](https://gitter.im/naver/pinpoint-c-agent)
* [email protected]
* Chinese Community (QQ Group: 882020485)
* QQ us (QQ Group: 882020485)
<details>
<summary> show more
</summary>

QQ Group1: 897594820 | QQ Group2: 812507584 | QQ Group3: 882020485| DING Group : 21981598
:----------------: |:----------------: | :-----------: | :-----------:
![QQ Group1](images/NAVERPinpoint.png) | ![QQ Group2](images/NAVERPinpoint2.png)| ![QQ Group3](images/NAVERPinpoint3.png)| ![DING Group](images/NaverPinpoint交流群-DING.jpg)

</details>

## Contributing

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)

We are looking forward to your contributions via pull requests.

## License
Expand Down
4 changes: 4 additions & 0 deletions collector-agent/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## v0.6.4
- fix: panic: send on closed channel #658

## v0.5.3 2024.05.31
- support go install

## [v0.5.0] start time in ms
- return current time in ms
3 changes: 2 additions & 1 deletion collector-agent/agent/AgentRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ func (manager *AgentRouter) Clean() {
manager.rwMutex.RUnlock()
manager.rwMutex.Lock()
delete(manager.AgentMap, id)
agent.Stop()
manager.rwMutex.Unlock()
manager.rwMutex.RLock()
//shrink rwMutex scope
agent.Stop()
}
}
manager.rwMutex.RUnlock()
Expand Down
2 changes: 1 addition & 1 deletion collector-agent/agent/ErrorAnalysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (e *ErrorAnalysisFilter) sendExpMetaData(meta *v1.PExceptionMetaData) {
defer conn.Close()
client := v1.NewMetadataClient(conn)

ctx, cancel := common.BuildPinpointCtx(config.MetaDataTimeWaitSec, e.md)
ctx, cancel := common.BuildPinpointCtx(config.MetaDataTimeWait, e.md)
defer cancel()
result, err := client.RequestExceptionMetaData(ctx, meta)
if err != nil {
Expand Down
48 changes: 24 additions & 24 deletions collector-agent/agent/GrpcAgent.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type GrpcAgent struct {
requestCounter RequestProfiler
utReport *UrlTemplateReport
tasksGroup sync.WaitGroup
tSpanCh chan *TSpan
tSpanBufCh chan *TSpan
ExitCh chan bool
log *log.Entry
errorAnalysisFilter *ErrorAnalysisFilter
Expand All @@ -52,7 +52,7 @@ func (agent *GrpcAgent) SendSpan(span *TSpan) {
log.Warnf("sendSpan met:%s", r)
}
}()
agent.tSpanCh <- span
agent.tSpanBufCh <- span
}

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

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

func (agent *GrpcAgent) agentOnline() error {
func (agent *GrpcAgent) handleRegisterAgent() error {

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

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

agent.log.Info("agent online ")
agent.AgentOnLine = true

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

func (agent *GrpcAgent) keepAgentOnline() {
agent.tasksGroup.Add(1)
defer agent.tasksGroup.Done()

for {
if err := agent.agentOnline(); err != nil {
if err := agent.handleRegisterAgent(); err != nil {
agent.log.Infof("agent online exit:%s ", err)
}

config := common.GetConfig()
if common.WaitChannelEvent(agent.ExitCh, config.PingInterval) == common.E_AGENT_STOPPING {
if common.WaitChannelEvent(agent.ExitCh, config.AgentReTryTimeout) == common.E_AGENT_STOPPING {
break
}
}
agent.spanSender.Stop()
}

func (agent *GrpcAgent) registerFilter() {
Expand Down Expand Up @@ -235,7 +233,7 @@ func (agent *GrpcAgent) sendStat() {
for {
msg := CollectPStateMessage(agent.requestCounter.GetMaxAvg, agent.requestCounter.GetReqTimeProfiler)

agent.log.Debugf("%v", msg)
agent.log.Debugf("PStatMessage: %v", msg)
if err := stream.Send(msg); err != nil {
agent.log.Warn(err)
break
Expand Down Expand Up @@ -270,7 +268,7 @@ func (agent *GrpcAgent) sendStat() {
}

func (agent *GrpcAgent) uploadStatInfo() {
agent.tasksGroup.Add(1)

defer agent.tasksGroup.Done()

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

config := common.GetConfig()

agent.tSpanCh = make(chan *TSpan, config.AgentChannelSize)
agent.tSpanBufCh = make(chan *TSpan, config.AgentChannelSize)
agent.ExitCh = make(chan bool)
agent.spanSender = createSpanSender(agent.BaseMD, agent.ExitCh)
agent.spanSender = createSpanSender(agent.BaseMD, agent.ExitCh, &agent.tasksGroup, agent.log)
agent.requestCounter.CTime = time.Now().Unix()

agent.errorAnalysisFilter = createErrorAnalysisFilter(agent.BaseMD)

agent.registerFilter()
agent.tasksGroup.Add(1)
// start agentOnline
go agent.keepAgentOnline()
// send stat
agent.tasksGroup.Add(1)
go agent.uploadStatInfo()

}

func (agent *GrpcAgent) Start() {
agent.tasksGroup.Add(1)
go agent.consumeJsonSpan()
}

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

func (agent *GrpcAgent) consumeJsonSpan() {
defer agent.tasksGroup.Done()
agent.tasksGroup.Add(1)

for span := range agent.tSpanCh {
if span == nil {
agent.log.Infof("agent:%v get EOF", agent)
return
}

for _, filter := range agent.spanFilters {
if !filter.Interceptor(span) {
break
for {
select {
case span := <-agent.tSpanBufCh:
for _, filter := range agent.spanFilters {
if !filter.Interceptor(span) {
break
}
}
case <-agent.spanSender.exitCh:
agent.log.Warn("consumeJsonSpan task done, as agent exit")
return
}
}
}
Expand Down
Loading

0 comments on commit 436949c

Please sign in to comment.