Skip to content

Commit

Permalink
fix backend crash
Browse files Browse the repository at this point in the history
  • Loading branch information
eeliu committed Nov 24, 2023
1 parent 0e1d206 commit b15df70
Show file tree
Hide file tree
Showing 45 changed files with 1,235 additions and 341 deletions.
32 changes: 3 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![pinpoint](images/logo.png)

[![Build](https://github.com/pinpoint-apm/pinpoint-c-agent/workflows/Build/badge.svg?branch=master)](https://github.com/pinpoint-apm/pinpoint-c-agent/actions) [![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)



Expand All @@ -9,42 +9,18 @@

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

# Pinpoint Common Agent
# Pinpoint 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_**.

## Overview Pinpoint Common Agent
## Overview Pinpoint Agent

### How does it work

![How does it work](images/pinpoint_v0.5.x.png)

### Distributed Tracking system

![php_agent_example](images/php_agent_example.png)

### Call Stack

![php_agent_example_detail](images/php_agent_example_detail.png) | ![php_agent_example_memcached](images/callstack-memcached.png)
--- | ---
![php_agent_example_pdo](images/callstack-pdo.png) | ![php_agent_example_redis](images/callstack-redis.png)

### Real-time Tracking Chart

CPU | Response Time
--- | ---
![php_agent_example_pdo](images/cpu.png) | ![php_agent_example_redis](images/responsetime.png)


## Installation guide

**Components:**
* Collector-Agent (**Required**)
* PHP-Agent
* Python-Agent
* c/cpp Agent
* Golang-Agent

### Install Collector-Agent

[How to install Collector-Agent](DOC/collector-agent/readme.md)
Expand Down Expand Up @@ -80,8 +56,6 @@ golang|[go-aop-agent](https://github.com/pinpoint-apm/go-aop-agent)

We are looking forward to your contributions via pull requests.

https://github.com/pinpoint-apm/pinpoint-c-agent/graphs/contributors

## License
This project is licensed under the Apache License, Version 2.0.
See [LICENSE](LICENSE) for full license text.
Expand Down
8 changes: 4 additions & 4 deletions plugins/PY/pinpointPy/CommonPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
class PinpointCommonPlugin(Common.PinTrace):

def onBefore(self, parentId, *args, **kwargs):
parentId, args, kwargs = super().onBefore(*args, **kwargs)
trace_id, args, kwargs = super().onBefore(parentId, *args, **kwargs)
pinpoint.add_trace_header(
Defines.PP_INTERCEPTOR_NAME, self.getUniqueName(), parentId)
Defines.PP_INTERCEPTOR_NAME, self.getUniqueName(), trace_id)
pinpoint.add_trace_header(
Defines.PP_SERVER_TYPE, Defines.PP_METHOD_CALL, parentId)
return args, kwargs
Defines.PP_SERVER_TYPE, Defines.PP_METHOD_CALL, trace_id)
return trace_id, args, kwargs

def onEnd(self, traceId, ret):
# pinpoint.add_trace_header_v2(Defines.PP_RETURN, str(ret), traceId)
Expand Down
2 changes: 1 addition & 1 deletion testapps/PY/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def test_mysql_form():

@app.route('/test_redis', methods=['GET'])
def test_redis_form():
r = RedisControl("localhost", "6379")
r = RedisControl("redis", "6379")
r.connection()
h1 = r.set("name", "Evy")
r.delete("name")
Expand Down
2 changes: 1 addition & 1 deletion testapps/PY/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ <h3>Error and exception</h3>

<h3>Call Remote</h3>
<form method="get" action="/call_remote">
remote url: <input type="text" name="remote" value="http://10.34.130.137:7009"/>
remote url: <input type="text" name="remote" value="http://backend"/>
<button type="submit">Call Remote</button>
</form>

Expand Down
9 changes: 5 additions & 4 deletions testapps/backend.dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
FROM python:3.8
FROM python:3.11
WORKDIR /app/

COPY testapps/backend/ /app/
RUN pip install -r requirements.txt

COPY setup.py /pinpoint-c-agent/setup.py
COPY common/ /pinpoint-c-agent/common
COPY README /pinpoint-c-agent/README
COPY plugins/PY /pinpoint-c-agent/plugins/PY
COPY src/PY /pinpoint-c-agent/src/PY

RUN pip install -r requirements.txt
RUN cd /pinpoint-c-agent && pip install -e .

# EXPOSE 8000
CMD [ "uvicorn", "main:app","--host=0.0.0.0","--port=8000","--reload" ]
EXPOSE 80
CMD [ "python", "app.py" ]
9 changes: 9 additions & 0 deletions testapps/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
composer.phar
vendor
.idea/
Cache
__class_index_table
*.ast
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock
39 changes: 39 additions & 0 deletions testapps/backend/DBControl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-


import pymysql


class DBControl(object):

def __init__(self, ip, user, pw, db=None):
self.ip = ip
self.user = user
self.pw = pw
self.db = db
self.conn = None
self.cursor = None

def con_db(self):
if self.db is None:
self.conn = pymysql.connect(host=self.ip, user=self.user, passwd=self.pw)
else:
self.conn = pymysql.connect(host=self.ip,user=self.user,passwd=self.pw, db=self.db)
if self.conn is None:
print("Connect to Database failed!")
else:
self.cursor = self.conn.cursor()

def db_select(self, sql):
self.cursor.execute(sql)
result = self.cursor.fetchall()
r = []
for res in result:
r.append(res)
return r

def db_close(self):
self.cursor.close()
self.conn.commit()
self.conn.close()
32 changes: 32 additions & 0 deletions testapps/backend/Readme-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 将pinpoint集成到Flask中


## 集成Pinpoint

> 确保安装了pinpointPy模块。([如何安装pinpointPy模块](../../../DOC/PY/Readme-CN.md))
1.```pinpoint``` 目录复制到您项目的根目录, 将 PinPointMiddleWare 添加到您的应用程序中。

```
app = Flask(__name__)
from PinPointMiddleWare import PinPointMiddleWare
app.wsgi_app = PinPointMiddleWare(app,app.wsgi_app)
......
```
2. 将[插件](../plugins)复制到```pinpoint``` 目录。 ```plugin``` 里的插件是一些示例,您也可以根据这些例子编写您自己的插件。
3. Hook 您所关心的函数。
> Example: flask/test_recursion.py
Hook the function ```fact``` by add ```@PinpointCommonPlugin( __name__)``` just before it.
```
from pinpointPy.CommonPlugin import PinpointCommonPlugin
@PinpointCommonPlugin( __name__)
def fact(n):
......
```
32 changes: 32 additions & 0 deletions testapps/backend/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Integrating Pinpoint Into Flask


## Integrating pinpoint

> Make sure pinpointPy module has been installed. ([How to Install pinpointPy module](../../../DOC/PY/Readme.md))
1. Copy ```pinpoint``` directory to your project root. Add PinPointMiddleWare to your application.

```
app = Flask(__name__)
from PinPointMiddleWare import PinPointMiddleWare
app.wsgi_app = PinPointMiddleWare(app,app.wsgi_app)
......
```
2. Copy [plugins](../plugins) to the ```pinpoint``` directory . Plugins in ```plugin``` are some examples, you can also write your own plugin according to these examples.
3. Hook the function you cared.
> Example: flask/test_recursion.py
Hook the function ```fact``` by add ```@PinpointCommonPlugin('', __name__)``` just before it.
```
from pinpointPy.CommonPlugin import PinpointCommonPlugin
@PinpointCommonPlugin(__name__)
def fact(n):
......
```
26 changes: 26 additions & 0 deletions testapps/backend/RedisControl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import redis


class RedisControl(object):

def __init__(self, host, port):
self.host = host
self.port = port
self.conn = None

def connection(self):
self.conn = redis.Redis(host=self.host, port=self.port)

def set(self, key, value):
self.conn.set(key, value)
return self.conn.get(key)

def get(self, key):
return "%s:%s" % (key, self.conn.get(key))

def delete(self, key):
self.conn.delete(key)
return "Delete %s success!"
Empty file removed testapps/backend/__init__.py
Empty file.
Loading

0 comments on commit b15df70

Please sign in to comment.