diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 53522ef45..0ba0d3b5f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,7 +3,7 @@ USER root ## install developmental env ENV TZ=Asia/Shanghai ENV LC_CTYPE=en_US.UTF-8 -ENV LC_ALL=en_US.UTF-8 +# ENV LC_ALL=en_US.UTF-8 # referr from https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user ARG USERNAME=pinpoint ARG USER_UID=1000 @@ -28,10 +28,11 @@ RUN groupadd --gid $USER_GID $USERNAME \ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -RUN apt update && apt install -y gcc g++ gdb pkg-config libxml2-dev libsqlite3-dev libcurl4-openssl-dev zlib1g-dev make cmake wget autoconf git clangd python3-pip clang-format protobuf-compiler vim -## enable php-7.4 +RUN apt update && apt install -y apt-utils gcc g++ gdb pkg-config libxml2-dev libsqlite3-dev libcurl4-openssl-dev zlib1g-dev make cmake wget autoconf git clangd iputils-ping python3 python3.8-venv python3-pip clang-format protobuf-compiler vim +# enable php-7.4 ENV PHP_VESION=php-7.4.33 -RUN cd ~ && wget https://www.php.net/distributions/${PHP_VESION}.tar.gz && tar xvf ${PHP_VESION}.tar.gz && cd ${PHP_VESION} && ./configure --prefix=/opt/${PHP_VESION} --enable-fpm --enable-opcache --enable-debug && make -j && make install +COPY ${PHP_VESION}.tar.gz /repo/${PHP_VESION}.tar.gz +RUN cd /repo && tar xvf ${PHP_VESION}.tar.gz && cd ${PHP_VESION} && ./configure --prefix=/opt/${PHP_VESION} --enable-fpm --enable-opcache --enable-debug && make -j && make install ENV PATH="$PATH:/opt/php/bin/:/opt/php/sbin/" COPY php.ini /opt/$PHP_VESION/lib @@ -61,9 +62,9 @@ COPY php.ini /opt/$PHP_VESION/lib # install golang 1.18 - -RUN wget https://go.dev/dl/go1.18.10.linux-amd64.tar.gz && rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.10.linux-amd64.tar.gz +COPY go1.18.10.linux-amd64.tar.gz /repo/go1.18.10.linux-amd64.tar.gz +RUN rm -rf /usr/local/go && cd /repo/ && tar -C /usr/local -xzf go1.18.10.linux-amd64.tar.gz ENV PATH=$PATH:/usr/local/go/bin ENV GO_PATH=~/go ENV PATH=$PATH:/$GO_PATH/bin -RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest +RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ffbbe52db..932ba927a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,22 +1,10 @@ { "name": "PINPOINT php Dev", - "dockerFile": "Dockerfile", - "runArgs": [ - "--user=pinpoint", - "--cap-add=SYS_PTRACE", - "--cap-add=NET_RAW", - "--cap-add=NET_ADMIN", - "--security-opt=seccomp=unconfined", - "--volume=${env:HOME}:${env:HOME}", - "--volume=/var/run/docker.sock:/var/run/docker.sock", - // "--volume=envoy-build:/build", - "--network=host", - // Uncomment next line if you have devcontainer.env - // "--env-file=.devcontainer/devcontainer.env" + "service": "pinpoint", + "dockerComposeFile": [ + "docker-compose.yaml" ], - "containerEnv": { - "ENVOY_SRCDIR": "${containerWorkspaceFolder}", - }, + "workspaceFolder": "/workspace", "settings": { "terminal.integrated.shell.linux": "/bin/bash", "bazel.buildifierFixOnFormat": true, @@ -33,22 +21,24 @@ }, "remoteUser": "pinpoint", "containerUser": "pinpoint", - "postCreateCommand": ".devcontainer/setup.sh", + // "postCreateCommand": ".devcontainer/setup.sh", "extensions": [ - "zxh404.vscode-proto3", - "llvm-vs-code-extensions.vscode-clangd", - "vadimcn.vscode-lldb", - "webfreak.debug", - "ms-python.python", - "xaver.clang-format", - "zxh404.vscode-proto3", - "Gruntfuggly.todo-tree", - "msyrus.go-doc", - "golang.go", - "bierner.github-markdown-preview", - "bierner.markdown-emoji", - "ms-vscode.cmake-tools", - "matepek.vscode-catch2-test-adapter", - "adam-bender.commit-message-editor" - ] + "zxh404.vscode-proto3", + "llvm-vs-code-extensions.vscode-clangd", + "vadimcn.vscode-lldb", + "webfreak.debug", + "ms-python.python", + "xaver.clang-format", + "zxh404.vscode-proto3", + "Gruntfuggly.todo-tree", + "msyrus.go-doc", + "golang.go", + "bierner.github-markdown-preview", + "bierner.markdown-emoji", + "ms-vscode.cmake-tools", + "matepek.vscode-catch2-test-adapter", + "adam-bender.commit-message-editor", + "formulahendry.vscode-mysql", + "ms-python.autopep8" + ] } \ No newline at end of file diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml new file mode 100644 index 000000000..5f7511bc3 --- /dev/null +++ b/.devcontainer/docker-compose.yaml @@ -0,0 +1,49 @@ +version: '3.9' + +services: + dev-mysql: + image: mysql:5.7 + restart: always + container_name: dev-mysql + hostname: dev-mysql + environment: + MYSQL_ROOT_PASSWORD: 'password' + ports: + - '3306:3306' + expose: + - '3306' + volumes: + - ..:/workspace:cached + redis: + image: redis:alpine + command: redis-server --port 6379 + container_name: redis_boot + hostname: redis_boot + labels: + - "name=redis" + - "mode=standalone" + ports: + - 6379:6379 + + pinpoint: + container_name: pinpoint + command: sleep infinity + hostname: pinpoint + build: + context: ./ + dockerfile: Dockerfile + # args: + volumes: + - ..:/workspace:cached + - /var/run/docker.sock:/var/run/docker.sock + # - ${env:HOME}:/workspace + security_opt: + - seccomp=unconfined + cap_add: + - SYS_PTRACE + - NET_RAW + - NET_ADMIN + user: pinpoint + + + \ No newline at end of file diff --git a/.devcontainer/go1.18.10.linux-amd64.tar.gz b/.devcontainer/go1.18.10.linux-amd64.tar.gz new file mode 100644 index 000000000..c616ae9de --- /dev/null +++ b/.devcontainer/go1.18.10.linux-amd64.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e05400e4c79ef5394424c0eff5b9141cb782da25f64f79d54c98af0a37f8d49 +size 141977100 diff --git a/.devcontainer/php-7.4.33.tar.gz b/.devcontainer/php-7.4.33.tar.gz new file mode 100644 index 000000000..73c40efa6 --- /dev/null +++ b/.devcontainer/php-7.4.33.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a2337996f07c8a097e03d46263b5c98d2c8e355227756351421003bea8f463e +size 16869345 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..167ee0976 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +.devcontainer/*.gz filter=lfs diff=lfs merge=lfs -text +.devcontainer/go1.18.10.linux-amd64.tar.gz filter=lfs diff=lfs merge=lfs -text +.devcontainer/php-7.4.33.tar.gz filter=lfs diff=lfs merge=lfs -text diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml index d032cf6a5..7a1a2c077 100644 --- a/.github/workflows/build-wheels.yml +++ b/.github/workflows/build-wheels.yml @@ -3,13 +3,18 @@ name: build-wheels on: workflow_dispatch: inputs: + release-testpypi: + description: Do you want to release to test-pypi + required: true + default: "true" release: - description: Do you want to release to pipy + description: Do you want to release to pypi required: true default: "false" jobs: build_wheels_pypitest: + if: ${{ github.event.inputs.release-testpypi }} == "true" name: Build wheels on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: @@ -58,7 +63,6 @@ jobs: publish-pypitest: needs: build_wheels_pypitest runs-on: ubuntu-latest - if: ${{ github.event.inputs.release }} == "true" steps: - uses: actions/download-artifact@v3 with: @@ -78,6 +82,7 @@ jobs: repository_url: https://test.pypi.org/legacy/ build_wheels: + if: ${{ github.event.inputs.release }} == "true" name: Build wheels on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: @@ -121,7 +126,6 @@ jobs: publish: needs: build_wheels runs-on: ubuntu-latest - if: ${{ github.event.inputs.release }} == "true" steps: - uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bfe73f1fc..e14d8035b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -77,13 +77,6 @@ jobs: php-versions: ["7.0"] steps: - uses: actions/checkout@v2 - # - name: set mysql - # run: | - # sudo service mysql start - # sudo mysql --host='127.0.0.1' --user='root' --password='root' < '/home/runner/work/pinpoint-c-agent/pinpoint-c-agent/testapps/PHP/tests/script.sql' - # - name: set redis - # run: | - # sudo apt-get install redis-server - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} @@ -117,13 +110,13 @@ jobs: - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - run: | - pip install -r requirements.txt - python setup.py install || echo "failed, but ignore" - # nosetests does not support python3 anymore - # nosetests src/PY/test --ignore-files="TestCoroutines.*" - python -m unittest discover -s src/PY/test -p 'Test*.py' - + - name: run unittest + run: | + # ref https://github.com/pypa/setuptools/issues/3198 + pip install -e . + python -m unittest discover -s src/PY/test + pip install -r plugins/PY/requirements.txt + python -m unittest discover -s plugins/PY/pinpointPy Collector-agent: strategy: matrix: @@ -145,8 +138,4 @@ jobs: - run: | go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest - # cd collector-agent - # go mod download - # go build - # go test ./... -v cd collector-agent && make && go test ./... -v \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6917d67f1..3883c88ab 100644 --- a/.gitignore +++ b/.gitignore @@ -69,7 +69,6 @@ aclocal.m4 src/PHP/pinpoint_php.dep testapps/PHP/composer.phar collector-agent/collector-agent -common/include/common.h .cache compile_commands.json wheelhouse/ diff --git a/DOC/API/common.h b/DOC/API/common.h deleted file mode 100644 index 825f5f40e..000000000 --- a/DOC/API/common.h +++ /dev/null @@ -1,252 +0,0 @@ -/******************************************************************************* - * Copyright 2019 NAVER Corp - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy - * of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - ******************************************************************************/ -#ifndef COMMON_H_ -#define COMMON_H_ - -#include -#include -#include -#include - -#ifdef __linux__ -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) -#elif _WIN32 - -#else - -#endif - -#if defined(__GNUC__) || defined(__clang__) -#define DEPRECATED __attribute__((deprecated)) -#elif defined(_MSC_VER) -#define DEPRECATED __declspec(deprecated) -#else -#define DEPRECATED -#endif - - -#define MAX_VEC 512 -#define LOG_SIZE 4096 -#define IN_MSG_BUF_SIZE 4096 -#define NAMING_SIZE 128 -#define MAX_SPAN_SIZE 4096*100 - -typedef enum{ - RESPONSE_AGENT_INFO = 0, - REQ_UPDATE_SPAN = 1 -}MSG_TYPE; - - -typedef enum{ - E_LOGGING=0x1, - E_DISABLE_GIL=0x2, // disable gil checking in python - E_UTEST = 0x4 -}AGENT_FLAG; - -typedef int32_t NodeID; - -#pragma pack (1) -typedef struct { - uint32_t type; - uint32_t length; -}Header; -#pragma pack () - -typedef struct collector_agent_s{ - uint64_t start_time; - char* appid; - char* appname; -}CollectorAgentInfo; - -/// -typedef struct trace_store_layer{ - void(*set_cur_trace_cb)(void*); - void*(*get_cur_trace_cb)(void); -}TraceStoreLayer; - -#define LOG_SIZE 4096 -#define MAX_ADDRESS_SIZE 256 -typedef void (*VOID_FUNC)(void); -typedef struct pp_agent_s{ - char co_host[MAX_ADDRESS_SIZE]; // tcp:ip:port should support dns - long timeout_ms; // always be 0 - long trace_limit; // change to long as python need long - int agent_type; - uint8_t inter_flag; - VOID_FUNC get_read_lock; - VOID_FUNC get_write_lock; - VOID_FUNC release_lock; -}PPAgentT; - -typedef enum { - E_OFFLINE = 0x1, - E_TRACE_PASS =0x2, - E_TRACE_BLOCK =0x4, - E_READY = 0x8 -}E_AGENT_STATUS; - -/** - * @brief at present only root checking - */ -typedef enum { - E_CURRENT_LOC=0x0, - E_ROOT_LOC=0x1 -}E_NODE_LOC; -/** - *pinpoint_start_trace - *pinpoint_end_trace - *pinpoint_add_clue - *pinpoint_add_clues - *pinpoint_unique_id - *pinpoint_tracelimit $timestamp - *pinpoint_drop_trace - *pinpoint_app_name - *pinpoint_app_id - *pinpoint_start_time - */ -#ifdef __cplusplus -extern "C"{ -#endif - -extern PPAgentT global_agent_info; - -/** - * @brief - * - * @return NodeID - */ -NodeID pinpoint_get_per_thread_id(void); - -void pinpoint_update_per_thread_id(NodeID id); - -/** - * start a trace (span). if current span is empty, create a span or else create a spanevent - * @return - */ -NodeID pinpoint_start_trace(NodeID); -/** - * the same as pinpoint_start_trace. BUT, end a span or a spanevent - * @return - */ -NodeID pinpoint_end_trace(NodeID); - -/** - * check id->traceNode is root - * @param - * @return 1: is root; 0: not root node;-1: A wrong id - */ -int pinpoint_trace_is_root(NodeID); - -/** - * force end current trace, only called when callstack leaked - * @return int 0 : means oK - * -1: exception found, check the log - */ -int pinpoint_force_end_trace(NodeID,int32_t timeout); - -/** - * pinpoint_add_clues, append a value into span[key] - * @param key must be a string - * @param value key must be a string - */ -void pinpoint_add_clues(NodeID _id,const char* key,const char* value,E_NODE_LOC flag); -/** - * pinpoint_add_clues, add a key-value into span. span[key]=value - * @param key must be a string - * @param value key must be a string - */ -void pinpoint_add_clue(NodeID _id,const char* key,const char* value,E_NODE_LOC flag); -/** - * add a key value into current trace. IF the trace is end, all data(key-value) will be free - * @param key - * @param value - */ -void pinpoint_set_context_key(NodeID _id,const char* key,const char* value); -/** - * get the corresponding value with key(in current trace) - * @param key - * @return - */ -const char* pinpoint_get_context_key(NodeID _id,const char* key); - - -void pinpoint_set_context_long(NodeID _id,const char* key,long); - -/** - * @brief the value is a long type - * - * @param _id node id - * @param key string - * @return int 1: failed - * 0: success - */ -int pinpoint_get_context_long(NodeID _id,const char* key,long*); -/** - * if tracelimit enable, check current trace state, - * @param timestamp - * @return 0, sampled or else, not sampled - */ -int check_tracelimit(int64_t); - -/** - * @brief setting current trace status - typedef enum { - E_OFFLINE = 0x1, - E_TRACE_PASS =0x2, - E_TRACE_BLOCK =0x4, - E_READY = 0x8 - }E_AGENT_STATUS; - * @param _id - * @param status - * @return int - */ -int mark_current_trace_status(NodeID _id,int status); - -/** - * get an unique auto-increment id - * NOTE: implement by shared memory, only valid in current host. - * @return - */ -int64_t generate_unique_id(void); - -/** - * get the start time of collector-agent.Use to generate transactionID - * @return - */ -uint64_t pinpoint_start_time(void); - -/** - * mark current span with error - * @param msg - * @param error_filename - * @param error_lineno - */ -void catch_error(NodeID _id,const char* msg,const char* error_filename,uint32_t error_lineno); -typedef void(*log_msg_cb)(char*); -void register_error_cb(log_msg_cb error_cb); -void pp_trace(const char *format,...); -/** - * NOTE: only for testcase - */ -void reset_unique_id(void); - -DEPRECATED void pinpoint_reset_store_layer(TraceStoreLayer* storeLayer); - -#ifdef __cplusplus -} -#endif -#endif /* COMMON_H_ */ diff --git a/MANIFEST.in b/MANIFEST.in index 9d1b1c291..a39f9303f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include *.txt README.md NOTICE LICENSE MANIFEST.in -recursive-include common *.cmake *.h *.txt *.in *.cc *.c *.cpp *.h *.inl -recursive-include src/PY *.py *.c *.h *.txt -prune common/build \ No newline at end of file +#include *.txt README.md NOTICE LICENSE MANIFEST.in +#recursive-include common *.cmake *.h *.txt *.in *.cc *.c *.cpp *.h *.inl +#recursive-include src/PY *.c *.h +#recursive-include plugins/PY/ *.py \ No newline at end of file diff --git a/collector-agent/Dockerfile b/collector-agent/Dockerfile index 8116b9bdd..34962200e 100644 --- a/collector-agent/Dockerfile +++ b/collector-agent/Dockerfile @@ -1,8 +1,11 @@ FROM golang:1.18-alpine3.17 as builder WORKDIR /apps -COPY collector-agent /apps/collector-agent -RUN cd /apps/collector-agent && go mod tidy && go build -o CollectorAgent +USER root +RUN apk add --no-cache make protobuf-dev +RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest +COPY ./ /apps +RUN make FROM alpine:3.17 -COPY --from=builder /apps/collector-agent/CollectorAgent /usr/local/bin +COPY --from=builder /apps/collector-agent /usr/local/bin/CollectorAgent ENTRYPOINT [ "CollectorAgent" ] \ No newline at end of file diff --git a/collector-agent/agent/GrpcAgent.go b/collector-agent/agent/GrpcAgent.go index 7cdf85d46..6bdd9c721 100644 --- a/collector-agent/agent/GrpcAgent.go +++ b/collector-agent/agent/GrpcAgent.go @@ -321,7 +321,7 @@ func (agent *GrpcAgent) collectorActiveThreadCount(conn *grpc.ClientConn, respon if activeThreadCountClient, err := client.CommandStreamActiveThreadCount(ctx); err == nil { sequenceId := int32(1) for { - agent.log.Infof("ResponseId %d", responseId) + agent.log.Debugf("ResponseId %d", responseId) response := v1.PCmdStreamResponse{ ResponseId: responseId, SequenceId: sequenceId, diff --git a/collector-agent/makefile b/collector-agent/makefile index 2817359a0..a9acc344c 100644 --- a/collector-agent/makefile +++ b/collector-agent/makefile @@ -5,8 +5,6 @@ TAG=${tag} default: server ; protoc: - # fixme - # protoc --go_out=pinpoint-grpc-idl/proto/ --go-grpc_out=pinpoint-grpc-idl/proto --proto_path=pinpoint-grpc-idl/proto/ --go-grpc_opt=paths=source_relative pinpoint-grpc-idl/proto/v1/*.proto protoc --go_out=pinpoint-grpc-idl/proto/ --go-grpc_out=pinpoint-grpc-idl/proto --proto_path=pinpoint-grpc-idl/proto/ --go-grpc_opt=paths=source_relative v1/Annotation.proto v1/Cmd.proto v1/CustomMetric.proto v1/Service.proto v1/Span.proto v1/Stat.proto v1/ThreadDump.proto server: protoc @@ -15,7 +13,7 @@ server: protoc clean: rm -rf pinpoint-grpc-idl/proto/v1/*.go - rm collector-agent + rm -rf collector-agent docker: docker build -f Dockerfile -t ${TAG} . \ No newline at end of file diff --git a/collector-agent/todo.md b/collector-agent/todo.md index c2cfd0102..06b749695 100644 --- a/collector-agent/todo.md +++ b/collector-agent/todo.md @@ -1,5 +1,5 @@ ### Todo list -- [ ] support unique id -- [ ] support url template - - [ ] collector-agent - - [ ] support metric \ No newline at end of file +- [-] support unique id +- [-] support url template + - [-] collector-agent + - [-] support metric \ No newline at end of file diff --git a/common/include/common.h b/common/include/common.h new file mode 100644 index 000000000..747c8ed70 --- /dev/null +++ b/common/include/common.h @@ -0,0 +1,278 @@ +/******************************************************************************* + * Copyright 2019 NAVER Corp + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ +#ifndef COMMON_H_ +#define COMMON_H_ + +#include +#include +#include +#include + +#if defined(__GNUC__) || defined(__clang__) +#define DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) +#define DEPRECATED __declspec(deprecated) +#else +#define DEPRECATED +#endif + +#define MAX_VEC 512 +#define LOG_SIZE 4096 +#define IN_MSG_BUF_SIZE 4096 +#define NAMING_SIZE 128 +static const int RECONNECT_TIME_SEC = 5; +typedef enum { RESPONSE_AGENT_INFO = 0, REQ_UPDATE_SPAN = 1 } MSG_TYPE; + +typedef enum { + E_LOGGING = 0x1, + E_DISABLE_GIL = 0x2, // disable gil checking in python + E_UTEST = 0x4 +} AGENT_FLAG; + +#pragma pack(1) +typedef struct { + uint32_t type; + uint32_t length; +} Header; +#pragma pack() + +typedef struct collector_agent_s { + uint64_t start_time; + char* appid; + char* appname; +} CollectorAgentInfo; + +/// +typedef struct trace_store_layer { + void (*set_cur_trace_cb)(void*); + void* (*get_cur_trace_cb)(void); +} TraceStoreLayer; + +#define LOG_SIZE 4096 +#define MAX_ADDRESS_SIZE 256 +typedef void (*VOID_FUNC)(void); +typedef struct pp_agent_s { + char co_host[MAX_ADDRESS_SIZE]; // tcp:ip:port should support dns + long timeout_ms; // always be 0 + long trace_limit; // change to long as python need long + int agent_type; + uint8_t inter_flag; + VOID_FUNC get_read_lock; + VOID_FUNC get_write_lock; + VOID_FUNC release_lock; +} PPAgentT; + +typedef enum { + E_OFFLINE = 0x1, + E_TRACE_PASS = 0x2, + E_TRACE_BLOCK = 0x4, + E_READY = 0x8 +} E_AGENT_STATUS; + +/** + * @brief at present only root checking + */ + +typedef int NodeID; +typedef NodeID E_NODE_LOC; +static const NodeID E_INVALID_NODE = -1; +static const NodeID E_ROOT_NODE = 0; +static const E_NODE_LOC E_LOC_CURRENT = 0x0; +static const E_NODE_LOC E_LOC_ROOT = 0x1; + +#define PINPOINT_C_AGENT_API_VERSION "0.4.23" + +/** + * @brief change logs + * ## v0.4.13 + * pinpoint_get_context_key API changed + * ## v0.4.10 + * - new API: pinpoint_start_traceV1,pinpoint_add_exception + * ## v0.4.9 + * - not open + * ## v0.4.8 + * - add tls + */ +#ifdef __cplusplus +extern "C" { +#endif + +extern PPAgentT global_agent_info; + +/** + * @brief [tls] + * pinpoint_get_per_thread_id and pinpoint_update_per_thread_id are paired API + * pinpoint_get_per_thread_id get the current trace-id of current thread + * pinpoint_update_per_thread_id update(stores) the current trace-id for pinpoint_get_per_thread_id + * @return NodeID + */ +NodeID pinpoint_get_per_thread_id(void); +void pinpoint_update_per_thread_id(NodeID id); + +/** + * @brief [tls] start a trace (span) from parentId. if current span is empty, create a span or else + * create a spanevent + * + * @param parentId + * @return -1: failed new traceId related to parentId (caller [parentId] -> callee [NodeID] ) + */ +NodeID pinpoint_start_trace(NodeID parentId); + +/** + * @brief [tls] V1 support trace with optional config + * Not support on root traceNode + * @param parentId + * @param opt param ... count; if opt == nullptr, the same as pinpoint_start_trace; Note: must end + * with nullptr + * @param ... only support const char*; + * eg: + * "TraceMinTimeMs:23" // the minimum time of a trace should be 23ms + * "TraceOnlyException" // only trace exception( only report when call pinpoint_add_exception) + * @return NodeID + */ +NodeID pinpoint_start_traceV1(NodeID parentId, const char* opt, ...); + +void pinpoint_add_exception(NodeID, const char* exp); + +/**[tls] + * the same as pinpoint_start_trace. BUT, end a span or a spanevent + * Note: pinpoint_end_trace is thread safe, but you should avoid to call it in the multi-thread, it + * may send duplicate trace span + * @return NodeID is parent node id + */ +NodeID pinpoint_end_trace(NodeID); + +/** + * @brief wake a finished trace: this trace get a new startime, so it could be profile again. the + * end_trace will update the ["e"] by cumulative time (NOTE: root trace not supported) + * + * @param traceId + * @return int 0 if success, -1 if failed + */ +int pinpoint_wake_trace(NodeID traceId); + +/** + * check id->traceNode is root + * @param + * @return 1: is root; 0: not root node;-1: A wrong id + */ +int pinpoint_trace_is_root(NodeID); + +/** + * force end current trace, only called when callstack leaked + * @return int 0 : means oK + * -1: exception found, check the log + */ +int pinpoint_force_end_trace(NodeID, int32_t timeout); + +/** + * [tls] pinpoint_add_clues, append a value into span[key] + * @param key must be a string + * @param value key must be a string + */ +void pinpoint_add_clues(NodeID _id, const char* key, const char* value, E_NODE_LOC flag); +/** + * [tls] pinpoint_add_clues, add a key-value into span. span[key]=value + * @param key must be a string + * @param value key must be a string + */ +void pinpoint_add_clue(NodeID _id, const char* key, const char* value, E_NODE_LOC flag); +/** + * [tls] add a key value into current trace. IF the trace is end, all data(key-value) will be free + * @param key + * @param value + */ +void pinpoint_set_context_key(NodeID _id, const char* key, const char* value); +/** + * [tls] get the corresponding value with key(in current trace) + * @param size copy into pbuf, not include '\0' + * @return value size + */ +int pinpoint_get_context_key(NodeID _id, const char* key, char* pbuf, int buf_size); + +void pinpoint_set_context_long(NodeID _id, const char* key, long); + +/** + * @brief the value is a long type + * + * @param _id node id + * @param key string + * @return int 1: failed + * 0: success + */ +int pinpoint_get_context_long(NodeID _id, const char* key, long*); +/** + * [tls] if tracelimit enable, check current trace state, + * @param timestamp + * @return 0, sampled or else, not sampled + */ +int check_tracelimit(int64_t); + +/** +* @brief [tls] setting current trace status + typedef enum { + E_OFFLINE = 0x1, + E_TRACE_PASS =0x2, + E_TRACE_BLOCK =0x4, + E_READY = 0x8 + }E_AGENT_STATUS; +* @param _id +* @param status +* @return int last status +*/ +uint64_t mark_current_trace_status(NodeID _id, int status); + +/** + * [tls] get an unique auto-increment id + * NOTE: implement by shared memory, only valid in current host. + * @return + */ +int64_t generate_unique_id(void); + +/** + * [tls] get the start time of collector-agent.Use to generate transactionID + * @return + */ +uint64_t pinpoint_start_time(void); + +/** + * mark current span with error + * @param msg + * @param error_filename + * @param error_lineno + */ +void catch_error(NodeID _id, const char* msg, const char* error_filename, uint32_t error_lineno); +typedef void (*log_msg_cb)(char*); +void register_error_cb(log_msg_cb error_cb); + +/** + * @brief for test-case: not send span to collector-agent, pass to handler + * not tls + * @param handler + */ +void register_span_handler(void (*handler)(const char*)); + +void pp_trace(const char* format, ...); +/** + * NOTE: only for testcase + */ +void reset_unique_id(void); +const char* pinpoint_agent_version(); +void show_status(void); +#ifdef __cplusplus +} +#endif +#endif /* COMMON_H_ */ diff --git a/common/src/Cache/SharedObj.c b/common/src/Cache/SharedObj.cpp similarity index 100% rename from common/src/Cache/SharedObj.c rename to common/src/Cache/SharedObj.cpp diff --git a/common/src/Logging.c b/common/src/Logging.cpp similarity index 100% rename from common/src/Logging.c rename to common/src/Logging.cpp diff --git a/common/test/test_main.cpp b/common/test/test_main.cc similarity index 100% rename from common/test/test_main.cpp rename to common/test/test_main.cc diff --git a/plugins/PY/pinpointPy/Bottle/RequestPlugin.py b/plugins/PY/pinpointPy/Bottle/RequestPlugin.py index 6f69524af..aec4537f1 100644 --- a/plugins/PY/pinpointPy/Bottle/RequestPlugin.py +++ b/plugins/PY/pinpointPy/Bottle/RequestPlugin.py @@ -19,9 +19,9 @@ from bottle import response -from ..Defines import PP_HTTP_STATUS_CODE, PP_ADD_EXCEPTION -from ..WSGIPlugin import WSGIPlugin -from ..pinpoint import add_trace_header_v2, add_trace_header +from pinpointPy.Defines import PP_HTTP_STATUS_CODE, PP_ADD_EXCEPTION +from pinpointPy.WSGIPlugin import WSGIPlugin +from pinpointPy.pinpoint import add_trace_header_v2, add_trace_header class RequestPlugin(WSGIPlugin): diff --git a/plugins/PY/pinpointPy/Bottle/__init__.py b/plugins/PY/pinpointPy/Bottle/__init__.py index 5b21e0e5e..02f41bef1 100644 --- a/plugins/PY/pinpointPy/Bottle/__init__.py +++ b/plugins/PY/pinpointPy/Bottle/__init__.py @@ -19,7 +19,7 @@ # Created by eeliu at 11/9/20 -from .RequestPlugin import RequestPlugin +from pinpointPy.Bottle.RequestPlugin import RequestPlugin def PinPointMiddleWare(application): def handler(environ,start_response): @@ -28,4 +28,8 @@ def handler(environ,start_response): response = application(environ,start_response) plugin.onEnd(response) return response - return handler \ No newline at end of file + return handler + +__all__=['PinPointMiddleWare'] +__version__ ='0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/Common.py b/plugins/PY/pinpointPy/Common.py index c85def725..d927eb77b 100644 --- a/plugins/PY/pinpointPy/Common.py +++ b/plugins/PY/pinpointPy/Common.py @@ -19,8 +19,8 @@ # Created by eeliu at 3/5/20 -from . import Defines -from . import pinpoint +from pinpointPy import Defines +from pinpointPy import pinpoint from abc import ABCMeta, abstractmethod class PinTrace(object): diff --git a/plugins/PY/pinpointPy/CommonPlugin.py b/plugins/PY/pinpointPy/CommonPlugin.py index 0e0596c7f..18f44a5b9 100644 --- a/plugins/PY/pinpointPy/CommonPlugin.py +++ b/plugins/PY/pinpointPy/CommonPlugin.py @@ -15,9 +15,9 @@ # ------------------------------------------------------------------------------ -from . import Common -from . import Defines -from . import pinpoint +from pinpointPy import Common +from pinpointPy import Defines +from pinpointPy import pinpoint class PinpointCommonPlugin(Common.PinTrace): diff --git a/plugins/PY/pinpointPy/Defines.py b/plugins/PY/pinpointPy/Defines.py index 116a99e82..538a364e4 100644 --- a/plugins/PY/pinpointPy/Defines.py +++ b/plugins/PY/pinpointPy/Defines.py @@ -32,7 +32,7 @@ PP_HEADER_PINPOINT_PAPPNAME = 'Pinpoint-Pappname' PP_HEADER_PINPOINT_PAPPTYPE = 'Pinpoint-Papptype' PP_HEADER_PINPOINT_HOST = 'Pinpoint-Host' -PP_HEADER_PINPOINT_CLIENT='Pinpoint-Client' # add for Celery Caller client-ip +PP_HEADER_PINPOINT_CLIENT = 'Pinpoint-Client' # add for Celery Caller client-ip PP_HEADER_NGINX_PROXY = 'Pinpoint-ProxyNginx' PP_HTTP_NGINX_PROXY = 'HTTP_Pinpoint-ProxyNginx' @@ -42,61 +42,62 @@ PP_HEADER_PINPOINT_SAMPLED = "Pinpoint-Sampled" PP_HTTP_PINPOINT_SAMPLED = 'HTTP_PINPOINT_SAMPLED' -PP_DESTINATION='dst' -PP_INTERCEPTOR_NAME='name' -PP_APP_NAME='appname' -PP_APP_ID='appid' -PP_REQ_URI='uri' -PP_REQ_CLIENT='client' -PP_REQ_SERVER='server' -PP_SERVER_TYPE='stp' -PP_AGENT_TYPE='FT' +PP_DESTINATION = 'dst' +PP_INTERCEPTOR_NAME = 'name' +PP_APP_NAME = 'appname' +PP_APP_ID = 'appid' +PP_REQ_URI = 'uri' +PP_REQ_CLIENT = 'client' +PP_REQ_SERVER = 'server' +PP_SERVER_TYPE = 'stp' +PP_AGENT_TYPE = 'FT' +PP_URL_TEMPLATED = 'UT' -PP_PARENT_SPAN_ID='psid' -PP_PARENT_NAME='pname' -PP_PARENT_TYPE='ptype' -PP_PARENT_HOST='Ah' +PP_PARENT_SPAN_ID = 'psid' +PP_PARENT_NAME = 'pname' +PP_PARENT_TYPE = 'ptype' +PP_PARENT_HOST = 'Ah' -PP_NGINX_PROXY='NP' -PP_APACHE_PROXY='AP' -PP_TRANSCATION_ID='tid' -PP_SPAN_ID='sid' -PP_NOT_SAMPLED='s0' -PP_SAMPLED='s1' -PP_NEXT_SPAN_ID='nsid' -PP_ADD_EXCEPTION='EXP' +PP_NGINX_PROXY = 'NP' +PP_APACHE_PROXY = 'AP' +PP_TRANSCATION_ID = 'tid' +PP_SPAN_ID = 'sid' +PP_NOT_SAMPLED = 's0' +PP_SAMPLED = 's1' +PP_NEXT_SPAN_ID = 'nsid' +PP_ADD_EXCEPTION = 'EXP' -PP_SQL_FORMAT='SQL' -PP_ARGS='-1' -PP_RETURN='14' +PP_SQL_FORMAT = 'SQL' +PP_ARGS = '-1' +PP_RETURN = '14' PYTHON = '1700' -PP_METHOD_CALL= '1701' -PP_CELERY='1702' +PP_METHOD_CALL = '1701' +PP_CELERY = '1702' PP_REMOTE_METHOD = '9900' -PP_HTTP_URL= '40' -PP_HTTP_PARAM= '41' -PP_HTTP_PARAM_ENTITY= '42' -PP_HTTP_COOKIE= '45' -PP_HTTP_STATUS_CODE= '46' +PP_HTTP_URL = '40' +PP_HTTP_PARAM = '41' +PP_HTTP_PARAM_ENTITY = '42' +PP_HTTP_COOKIE = '45' +PP_HTTP_STATUS_CODE = '46' PP_HTTP_METHOD = '206' -PP_HTTP_INTERNAL_DISPLAY=48 -PP_HTTP_IO=49 -PP_MESSAGE_QUEUE_URI=100 +PP_HTTP_INTERNAL_DISPLAY = 48 +PP_HTTP_IO = 49 +PP_MESSAGE_QUEUE_URI = 100 -PP_MYSQL= '2101' -PP_REDIS= '8200' -PP_REDIS_REDISSON= '8203' -PP_REDIS_REDISSON_INTERNAL= '8204' -PP_POSTGRESQL='2501' -PP_MEMCACHED= '8050' -PP_MEMCACHED_FUTURE_GET='8051' -PP_MONGDB_EXE_QUERY= '2651' -PP_KAFKA='8660' -PP_KAFKA_TOPIC='140' -PP_RABBITMQ_CLIENT='8300' -PP_RABBITMQ_EXCHANGEKEY='130' -PP_RABBITMQ_ROUTINGKEY='131' \ No newline at end of file +PP_MYSQL = '2101' +PP_REDIS = '8200' +PP_REDIS_REDISSON = '8203' +PP_REDIS_REDISSON_INTERNAL = '8204' +PP_POSTGRESQL = '2501' +PP_MEMCACHED = '8050' +PP_MEMCACHED_FUTURE_GET = '8051' +PP_MONGDB_EXE_QUERY = '2651' +PP_KAFKA = '8660' +PP_KAFKA_TOPIC = '140' +PP_RABBITMQ_CLIENT = '8300' +PP_RABBITMQ_EXCHANGEKEY = '130' +PP_RABBITMQ_ROUTINGKEY = '131' diff --git a/plugins/PY/pinpointPy/Django/BaseDjangoRequestPlugins.py b/plugins/PY/pinpointPy/Django/BaseDjangoRequestPlugins.py index 5cf9c54f8..c08357a74 100644 --- a/plugins/PY/pinpointPy/Django/BaseDjangoRequestPlugins.py +++ b/plugins/PY/pinpointPy/Django/BaseDjangoRequestPlugins.py @@ -19,9 +19,9 @@ # Created by eeliu at 3/5/20 -from .. import Common -from .. import Defines -from .. import pinpoint +from pinpointPy import Common +from pinpointPy import Defines +from pinpointPy import pinpoint class BaseDjangoRequestPlugins(Common.PinTrace): diff --git a/plugins/PY/pinpointPy/Django/DjangoMiddleWare.py b/plugins/PY/pinpointPy/Django/DjangoMiddleWare.py index f9cef0e8e..07eb745f7 100644 --- a/plugins/PY/pinpointPy/Django/DjangoMiddleWare.py +++ b/plugins/PY/pinpointPy/Django/DjangoMiddleWare.py @@ -17,7 +17,7 @@ from django.utils.deprecation import MiddlewareMixin -from .BaseDjangoRequestPlugins import BaseDjangoRequestPlugins +from pinpointPy.Django.BaseDjangoRequestPlugins import BaseDjangoRequestPlugins class DjangoMiddleWare(MiddlewareMixin): diff --git a/plugins/PY/pinpointPy/Django/__init__.py b/plugins/PY/pinpointPy/Django/__init__.py index d759fcc34..ea261079b 100644 --- a/plugins/PY/pinpointPy/Django/__init__.py +++ b/plugins/PY/pinpointPy/Django/__init__.py @@ -18,5 +18,7 @@ # limitations under the License. # ****************************************************************************** -from .DjangoMiddleWare import DjangoMiddleWare -__all__=['DjangoMiddleWare'] \ No newline at end of file +from pinpointPy.Django.DjangoMiddleWare import DjangoMiddleWare +__all__=['DjangoMiddleWare'] +__version__ ='0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/Fastapi/AsyCommon.py b/plugins/PY/pinpointPy/Fastapi/AsyCommon.py index 506a67f32..b279db1a2 100644 --- a/plugins/PY/pinpointPy/Fastapi/AsyCommon.py +++ b/plugins/PY/pinpointPy/Fastapi/AsyCommon.py @@ -24,7 +24,7 @@ from starlette_context import context -from .. import pinpoint +from pinpointPy import pinpoint class AsynPinTrace(object): diff --git a/plugins/PY/pinpointPy/Fastapi/AsyCommonPlugin.py b/plugins/PY/pinpointPy/Fastapi/AsyCommonPlugin.py index 03a78768a..7ade8f38f 100644 --- a/plugins/PY/pinpointPy/Fastapi/AsyCommonPlugin.py +++ b/plugins/PY/pinpointPy/Fastapi/AsyCommonPlugin.py @@ -15,9 +15,9 @@ # ------------------------------------------------------------------------------ -from .AsyCommon import AsynPinTrace -from .. import Defines -from .. import pinpoint +from pinpointPy.Fastapi.AsyCommon import AsynPinTrace +from pinpointPy import Defines +from pinpointPy import pinpoint class CommonPlugin(AsynPinTrace): diff --git a/plugins/PY/pinpointPy/Fastapi/AsyRequestPlugin.py b/plugins/PY/pinpointPy/Fastapi/AsyRequestPlugin.py index ea6691783..475fc9e41 100644 --- a/plugins/PY/pinpointPy/Fastapi/AsyRequestPlugin.py +++ b/plugins/PY/pinpointPy/Fastapi/AsyRequestPlugin.py @@ -18,9 +18,9 @@ # ------------------------------------------------------------------------------ -from .AsyCommon import AsynPinTrace -from .. import pinpoint -from .. import Defines +from pinpointPy.Fastapi.AsyCommon import AsynPinTrace +from pinpointPy import pinpoint +from pinpointPy import Defines class AsyRequestPlugin(AsynPinTrace): diff --git a/plugins/PY/pinpointPy/Fastapi/FastAPIRequestPlugin.py b/plugins/PY/pinpointPy/Fastapi/FastAPIRequestPlugin.py index 2b594adb5..fb474a2f9 100644 --- a/plugins/PY/pinpointPy/Fastapi/FastAPIRequestPlugin.py +++ b/plugins/PY/pinpointPy/Fastapi/FastAPIRequestPlugin.py @@ -18,9 +18,9 @@ # ------------------------------------------------------------------------------ -from .AsyRequestPlugin import * -from .. import Defines -from .. import pinpoint +from pinpointPy.Fastapi.AsyRequestPlugin import * +from pinpointPy import Defines +from pinpointPy import pinpoint class FastAPIRequestPlugin(AsyRequestPlugin): diff --git a/plugins/PY/pinpointPy/Fastapi/MotorMongo/__init__.py b/plugins/PY/pinpointPy/Fastapi/MotorMongo/__init__.py index 7d044fba4..998bf2ffa 100644 --- a/plugins/PY/pinpointPy/Fastapi/MotorMongo/__init__.py +++ b/plugins/PY/pinpointPy/Fastapi/MotorMongo/__init__.py @@ -19,7 +19,8 @@ # create by eelu -from ...Interceptor import Interceptor,intercept_once +from pinpointPy.Interceptor import intercept_once + @intercept_once def monkey_patch(): @@ -31,4 +32,5 @@ def monkey_patch(): # do nothing print(e) -__all__=['monkey_patch'] \ No newline at end of file + +__all__ = ['monkey_patch'] diff --git a/plugins/PY/pinpointPy/Fastapi/MotorMongo/motorComandPlugins.py b/plugins/PY/pinpointPy/Fastapi/MotorMongo/motorComandPlugins.py index df113a7f5..b04060d0a 100644 --- a/plugins/PY/pinpointPy/Fastapi/MotorMongo/motorComandPlugins.py +++ b/plugins/PY/pinpointPy/Fastapi/MotorMongo/motorComandPlugins.py @@ -21,10 +21,8 @@ from pymongo import monitoring -from .. import AsyCommon -from ... import pinpoint -from ... import Defines - +from pinpointPy.Fastapi import AsyCommon +from pinpointPy import pinpoint,Defines class MotorComandPlugins(AsyCommon.AsynPinTrace): diff --git a/plugins/PY/pinpointPy/Fastapi/PinTranscation.py b/plugins/PY/pinpointPy/Fastapi/PinTranscation.py index f3e69f00e..8c168c6d6 100644 --- a/plugins/PY/pinpointPy/Fastapi/PinTranscation.py +++ b/plugins/PY/pinpointPy/Fastapi/PinTranscation.py @@ -17,10 +17,9 @@ # limitations under the License. - # ------------------------------------------------------------------------------ -from .AsyCommon import AsynPinTrace -from .. import Defines -from .. import pinpoint -from ..Common import GenPinHeader +from pinpointPy.Fastapi.AsyCommon import AsynPinTrace +from pinpointPy import Defines,pinpoint +from pinpointPy.Common import GenPinHeader from starlette_context import request_cycle_context diff --git a/plugins/PY/pinpointPy/Fastapi/__init__.py b/plugins/PY/pinpointPy/Fastapi/__init__.py index fa8be8f35..bf95ba136 100644 --- a/plugins/PY/pinpointPy/Fastapi/__init__.py +++ b/plugins/PY/pinpointPy/Fastapi/__init__.py @@ -18,10 +18,10 @@ # ------------------------------------------------------------------------------ import importlib -from .PinTranscation import PinTransaction, PinStarlettePlugin -from .AsyCommonPlugin import CommonPlugin -from .middleware import PinPointMiddleWare -from ..Common import PinHeader,GenPinHeader +from pinpointPy.Fastapi.PinTranscation import PinTransaction, PinStarlettePlugin +from pinpointPy.Fastapi.AsyCommonPlugin import CommonPlugin +from pinpointPy.Fastapi.middleware import PinPointMiddleWare +from pinpointPy.Common import PinHeader, GenPinHeader def __monkey_patch(*args, **kwargs): @@ -38,5 +38,7 @@ def asyn_monkey_patch_for_pinpoint(AioRedis=True, MotorMongo=True, httpx=True): __monkey_patch(aioredis=AioRedis, MotorMongo=MotorMongo, httpx=httpx) +__version__ = '0.0.1' +__author__ = 'liu.mingyi@navercorp.com' __all__ = ['asyn_monkey_patch_for_pinpoint', 'PinPointMiddleWare', 'CommonPlugin', 'PinTransaction', 'PinHeader', 'GenPinHeader', 'PinStarlettePlugin'] diff --git a/plugins/PY/pinpointPy/Fastapi/aioredis/AioRedisPlugins.py b/plugins/PY/pinpointPy/Fastapi/aioredis/AioRedisPlugins.py index 7a13bb7df..3e0d9d1a0 100644 --- a/plugins/PY/pinpointPy/Fastapi/aioredis/AioRedisPlugins.py +++ b/plugins/PY/pinpointPy/Fastapi/aioredis/AioRedisPlugins.py @@ -19,9 +19,8 @@ # ****************************************************************************** -from .. import AsyCommon -from ... import pinpoint -from ... import Defines +from pinpointPy.Fastapi import AsyCommon +from pinpointPy import pinpoint, Defines class AioRedisPlugins(AsyCommon.AsynPinTrace): diff --git a/plugins/PY/pinpointPy/Fastapi/aioredis/__init__.py b/plugins/PY/pinpointPy/Fastapi/aioredis/__init__.py index e2a94a0d4..ef480a0da 100644 --- a/plugins/PY/pinpointPy/Fastapi/aioredis/__init__.py +++ b/plugins/PY/pinpointPy/Fastapi/aioredis/__init__.py @@ -19,7 +19,7 @@ # Created by suwei at 8/20/20 -from ...Interceptor import Interceptor,intercept_once +from pinpointPy.Interceptor import Interceptor,intercept_once @intercept_once def monkey_patch(): diff --git a/plugins/PY/pinpointPy/Fastapi/httpx/__init__.py b/plugins/PY/pinpointPy/Fastapi/httpx/__init__.py index 740da45e5..382b94c35 100644 --- a/plugins/PY/pinpointPy/Fastapi/httpx/__init__.py +++ b/plugins/PY/pinpointPy/Fastapi/httpx/__init__.py @@ -19,7 +19,7 @@ # create by eelu -from ...Interceptor import Interceptor,intercept_once +from pinpointPy.Interceptor import Interceptor,intercept_once @intercept_once def monkey_patch(): diff --git a/plugins/PY/pinpointPy/Fastapi/middleware.py b/plugins/PY/pinpointPy/Fastapi/middleware.py index e63b8c175..f1fd6a493 100644 --- a/plugins/PY/pinpointPy/Fastapi/middleware.py +++ b/plugins/PY/pinpointPy/Fastapi/middleware.py @@ -20,7 +20,7 @@ from fastapi import Request from starlette.middleware.base import BaseHTTPMiddleware -from .FastAPIRequestPlugin import FastAPIRequestPlugin +from pinpointPy.Fastapi.FastAPIRequestPlugin import FastAPIRequestPlugin class PinPointMiddleWare(BaseHTTPMiddleware): async def dispatch(self, request: Request, call_next): diff --git a/plugins/PY/pinpointPy/Flask/FlaskPlugins.py b/plugins/PY/pinpointPy/Flask/FlaskPlugins.py index 43e318f6b..de02ffa53 100644 --- a/plugins/PY/pinpointPy/Flask/FlaskPlugins.py +++ b/plugins/PY/pinpointPy/Flask/FlaskPlugins.py @@ -19,21 +19,22 @@ # Created by eeliu at 3/5/20 -from flask import Flask,Request +from flask import Request + +from pinpointPy import Common +from pinpointPy import pinpoint +from pinpointPy import Defines -from .. import Common -from .. import pinpoint -from .. import Defines class BaseFlaskPlugins(Common.PinTrace): def __init__(self, name): super().__init__(name) self.isLimit = False - def isSample(self,args): + def isSample(self, args): return True - def onBefore(self,*args, **kwargs): + def onBefore(self, *args, **kwargs): super().onBefore(*args, **kwargs) request = Request(args[1]) pinpoint.add_trace_header(Defines.PP_APP_NAME, pinpoint.app_name()) @@ -41,16 +42,17 @@ def onBefore(self,*args, **kwargs): pinpoint.add_context(Defines.PP_APP_NAME, pinpoint.app_name()) ############################################################### # print("------------------- call before -----------------------") - pinpoint.add_trace_header(Defines.PP_INTERCEPTOR_NAME, 'BaseFlaskrequest') + pinpoint.add_trace_header( + Defines.PP_INTERCEPTOR_NAME, 'BaseFlaskrequest') pinpoint.add_trace_header(Defines.PP_REQ_URI, request.path) pinpoint.add_trace_header(Defines.PP_REQ_CLIENT, request.remote_addr) pinpoint.add_trace_header(Defines.PP_REQ_SERVER, request.host) pinpoint.add_trace_header(Defines.PP_SERVER_TYPE, Defines.PYTHON) pinpoint.add_context(Defines.PP_SERVER_TYPE, Defines.PYTHON) - # nginx add http if Defines.PP_HTTP_PINPOINT_PSPANID in request.headers: - pinpoint.add_trace_header(Defines.PP_PARENT_SPAN_ID, request.headers[Defines.PP_HTTP_PINPOINT_PSPANID]) + pinpoint.add_trace_header( + Defines.PP_PARENT_SPAN_ID, request.headers[Defines.PP_HTTP_PINPOINT_PSPANID]) if Defines.PP_HTTP_PINPOINT_SPANID in request.headers: self.sid = request.headers[Defines.PP_HTTP_PINPOINT_SPANID] @@ -60,7 +62,6 @@ def onBefore(self,*args, **kwargs): self.sid = pinpoint.gen_sid() pinpoint.add_context(Defines.PP_SPAN_ID, self.sid) - if Defines.PP_HTTP_PINPOINT_TRACEID in request.headers: self.tid = request.headers[Defines.PP_HTTP_PINPOINT_TRACEID] elif Defines.PP_HEADER_PINPOINT_TRACEID in request.headers: @@ -86,7 +87,8 @@ def onBefore(self,*args, **kwargs): # Not nginx, no http if Defines.PP_HEADER_PINPOINT_PSPANID in request.headers: - pinpoint.add_trace_header(Defines.PP_PARENT_SPAN_ID, request.headers[Defines.PP_HEADER_PINPOINT_PSPANID]) + pinpoint.add_trace_header( + Defines.PP_PARENT_SPAN_ID, request.headers[Defines.PP_HEADER_PINPOINT_PSPANID]) # print("PINPOINT_PSPANID:", request.headers[PP_HEADER_PINPOINT_PSPANID]) if Defines.PP_HEADER_PINPOINT_PAPPNAME in request.headers: @@ -103,19 +105,20 @@ def onBefore(self,*args, **kwargs): self.Ah = request.headers[Defines.PP_HEADER_PINPOINT_HOST] pinpoint.add_context(Defines.PP_PARENT_HOST, self.Ah) pinpoint.add_trace_header(Defines.PP_PARENT_HOST, self.Ah) - + if Defines.PP_NGINX_PROXY in request.headers: - pinpoint.add_trace_header(Defines.PP_NGINX_PROXY, request.headers[Defines.PP_NGINX_PROXY]) - + pinpoint.add_trace_header( + Defines.PP_NGINX_PROXY, request.headers[Defines.PP_NGINX_PROXY]) + if Defines.PP_APACHE_PROXY in request.headers: - pinpoint.add_trace_header(Defines.PP_APACHE_PROXY, request.headers[Defines.PP_APACHE_PROXY]) + pinpoint.add_trace_header( + Defines.PP_APACHE_PROXY, request.headers[Defines.PP_APACHE_PROXY]) pinpoint.add_context(Defines.PP_HEADER_PINPOINT_SAMPLED, "s1") if (Defines.PP_HTTP_PINPOINT_SAMPLED in request.headers and request.headers[Defines.PP_HTTP_PINPOINT_SAMPLED] == Defines.PP_NOT_SAMPLED) or (Defines.PP_HEADER_PINPOINT_SAMPLED in request.headers and request.headers[Defines.PP_HEADER_PINPOINT_SAMPLED] == Defines.PP_NOT_SAMPLED) or pinpoint.check_trace_limit(): pinpoint.drop_trace() pinpoint.add_context(Defines.PP_HEADER_PINPOINT_SAMPLED, "s0") - pinpoint.add_trace_header(Defines.PP_TRANSCATION_ID, self.tid) pinpoint.add_trace_header(Defines.PP_SPAN_ID, self.sid) pinpoint.add_context(Defines.PP_TRANSCATION_ID, self.tid) @@ -124,7 +127,7 @@ def onBefore(self,*args, **kwargs): ############################################################### return args, kwargs - def onEnd(self,ret): + def onEnd(self, ret): ############################################################### ############################################################### @@ -133,5 +136,5 @@ def onEnd(self,ret): return ret def onException(self, e): - pinpoint.mark_as_error(str(e),"",0) + pinpoint.mark_as_error(str(e), "", 0) raise e diff --git a/plugins/PY/pinpointPy/Flask/PinPointMiddleWare.py b/plugins/PY/pinpointPy/Flask/PinPointMiddleWare.py index 5b27c5038..4f69be85a 100644 --- a/plugins/PY/pinpointPy/Flask/PinPointMiddleWare.py +++ b/plugins/PY/pinpointPy/Flask/PinPointMiddleWare.py @@ -17,19 +17,24 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- -from ..Defines import PP_HTTP_STATUS_CODE -from ..pinpoint import add_trace_header_v2 -from .FlaskPlugins import BaseFlaskPlugins - +from pinpointPy.Defines import PP_HTTP_STATUS_CODE, PP_URL_TEMPLATED +from pinpointPy.pinpoint import add_trace_header_v2, add_trace_header +from pinpointPy.Flask.FlaskPlugins import BaseFlaskPlugins +from flask import request +import sys class PinPointMiddleWare(): - def __init__(self, app,wsgi_app): + def __init__(self, app, wsgi_app): self.app = app self.wsgi_app = wsgi_app @app.after_request def mark_status_code(response): + if request.url_rule: + add_trace_header(PP_URL_TEMPLATED, str(request.url_rule)) + if 'unittest' in sys.modules.keys(): + response.headers["UT"] = str(request.url_rule) if response: add_trace_header_v2(PP_HTTP_STATUS_CODE, str(response.status)) return response @@ -37,4 +42,3 @@ def mark_status_code(response): @BaseFlaskPlugins("Flask Web App") def __call__(self, environ, start_response): return self.wsgi_app(environ, start_response) - diff --git a/plugins/PY/pinpointPy/Flask/__init__.py b/plugins/PY/pinpointPy/Flask/__init__.py index fe92992bf..f5573bdfe 100644 --- a/plugins/PY/pinpointPy/Flask/__init__.py +++ b/plugins/PY/pinpointPy/Flask/__init__.py @@ -19,4 +19,10 @@ # ------------------------------------------------------------------------------ from .PinPointMiddleWare import PinPointMiddleWare from .FlaskPlugins import BaseFlaskPlugins -__all__=['PinPointMiddleWare','BaseFlaskPlugins'] \ No newline at end of file +__all__=['PinPointMiddleWare','BaseFlaskPlugins'] + +__version__="0.0.1" +__author__ = 'liu.mingyi@navercorp.com' +# Changes +# ## 0.0.1 +# start support UT https://github.com/pinpoint-apm/pinpoint-c-agent/issues/534 \ No newline at end of file diff --git a/plugins/PY/pinpointPy/Flask/test_flask.py b/plugins/PY/pinpointPy/Flask/test_flask.py new file mode 100644 index 000000000..af214e4b4 --- /dev/null +++ b/plugins/PY/pinpointPy/Flask/test_flask.py @@ -0,0 +1,31 @@ +import unittest +from flask import Flask, request +from pinpointPy.Flask.PinPointMiddleWare import PinPointMiddleWare +from pinpointPy import set_agent, monkey_patch_for_pinpoint + + +class Test_Flask(unittest.TestCase): + def setUp(self) -> None: + app = Flask("abc") + app.wsgi_app = PinPointMiddleWare(app, app.wsgi_app) + app.config.update({ + "TESTING": True, + }) + + set_agent("cd.dev.test.py", "cd.dev.test.py", + 'tcp:dev-collector:9999', -1) + + @app.route('/abc', methods=['GET']) + def builtin_hello(): + return '''hello''' + + self.app = app + self.client = app.test_client() + return super().setUp() + + def test_request_example(self): + response = self.client.get("/abc") + assert "ut" in response.headers + +if __name__ == '__main__': + unittest.main() diff --git a/plugins/PY/pinpointPy/Helper.py b/plugins/PY/pinpointPy/Helper.py index 5b26fd92b..510e87efc 100644 --- a/plugins/PY/pinpointPy/Helper.py +++ b/plugins/PY/pinpointPy/Helper.py @@ -18,22 +18,28 @@ # ------------------------------------------------------------------------------ # Created by eeliu at 11/10/20 -from . import Defines -from . import pinpoint +from pinpointPy import Defines +from pinpointPy import pinpoint + def generateNextSid(): - return pinpoint.gen_sid() + return pinpoint.gen_sid() + -def generatePinpointHeader(host, headers,traceId=-1): +def generatePinpointHeader(host, headers, traceId=-1): headers[Defines.PP_HEADER_PINPOINT_SAMPLED] = Defines.PP_SAMPLED - headers[Defines.PP_HEADER_PINPOINT_PAPPTYPE] = pinpoint.get_context(Defines.PP_SERVER_TYPE,traceId) - headers[Defines.PP_HEADER_PINPOINT_PAPPNAME] = pinpoint.get_context(Defines.PP_APP_NAME,traceId) + headers[Defines.PP_HEADER_PINPOINT_PAPPTYPE] = pinpoint.get_context( + Defines.PP_SERVER_TYPE, traceId) + headers[Defines.PP_HEADER_PINPOINT_PAPPNAME] = pinpoint.get_context( + Defines.PP_APP_NAME, traceId) headers['Pinpoint-Flags'] = "0" headers[Defines.PP_HEADER_PINPOINT_HOST] = host - headers[Defines.PP_HEADER_PINPOINT_TRACEID] = pinpoint.get_context(Defines.PP_TRANSCATION_ID,traceId) - headers[Defines.PP_HEADER_PINPOINT_PSPANID] = pinpoint.get_context(Defines.PP_SPAN_ID,traceId) + headers[Defines.PP_HEADER_PINPOINT_TRACEID] = pinpoint.get_context( + Defines.PP_TRANSCATION_ID, traceId) + headers[Defines.PP_HEADER_PINPOINT_PSPANID] = pinpoint.get_context( + Defines.PP_SPAN_ID, traceId) nsid = pinpoint.gen_sid() - pinpoint.add_context(Defines.PP_NEXT_SPAN_ID, nsid,traceId) + pinpoint.add_context(Defines.PP_NEXT_SPAN_ID, nsid, traceId) headers[Defines.PP_HEADER_PINPOINT_SPANID] = nsid @@ -71,7 +77,8 @@ def startPinpointByEnviron(environ): pinpoint.add_context(Defines.PP_SERVER_TYPE, Defines.PYTHON) # nginx add http if Defines.PP_HTTP_PINPOINT_PSPANID in environ: - pinpoint.add_trace_header(Defines.PP_PARENT_SPAN_ID, environ[Defines.PP_HTTP_PINPOINT_PSPANID]) + pinpoint.add_trace_header( + Defines.PP_PARENT_SPAN_ID, environ[Defines.PP_HTTP_PINPOINT_PSPANID]) if Defines.PP_HTTP_PINPOINT_SPANID in environ: sid = environ[Defines.PP_HTTP_PINPOINT_SPANID] @@ -104,7 +111,8 @@ def startPinpointByEnviron(environ): # Not nginx, no http if Defines.PP_HEADER_PINPOINT_PSPANID in environ: - pinpoint.add_trace_header(Defines.PP_PARENT_SPAN_ID, environ[Defines.PP_HEADER_PINPOINT_PSPANID]) + pinpoint.add_trace_header( + Defines.PP_PARENT_SPAN_ID, environ[Defines.PP_HEADER_PINPOINT_PSPANID]) # print("PINPOINT_PSPANID:", environ[PP_HEADER_PINPOINT_PSPANID]) if Defines.PP_HEADER_PINPOINT_PAPPNAME in environ: @@ -123,14 +131,16 @@ def startPinpointByEnviron(environ): pinpoint.add_trace_header(Defines.PP_PARENT_HOST, Ah) if Defines.PP_NGINX_PROXY in environ: - pinpoint.add_trace_header(Defines.PP_NGINX_PROXY, environ[Defines.PP_NGINX_PROXY]) + pinpoint.add_trace_header( + Defines.PP_NGINX_PROXY, environ[Defines.PP_NGINX_PROXY]) if Defines.PP_APACHE_PROXY in environ: - pinpoint.add_trace_header(Defines.PP_APACHE_PROXY, environ[Defines.PP_APACHE_PROXY]) + pinpoint.add_trace_header( + Defines.PP_APACHE_PROXY, environ[Defines.PP_APACHE_PROXY]) pinpoint.add_context(Defines.PP_HEADER_PINPOINT_SAMPLED, "s1") if (Defines.PP_HTTP_PINPOINT_SAMPLED in environ and environ[ - Defines.PP_HTTP_PINPOINT_SAMPLED] == Defines.PP_NOT_SAMPLED) or pinpoint.check_trace_limit(): + Defines.PP_HTTP_PINPOINT_SAMPLED] == Defines.PP_NOT_SAMPLED) or pinpoint.check_trace_limit(): pinpoint.drop_trace() pinpoint.add_context(Defines.PP_HEADER_PINPOINT_SAMPLED, "s0") diff --git a/plugins/PY/pinpointPy/RequestPlugins.py b/plugins/PY/pinpointPy/RequestPlugins.py index 3fd376a48..36cec968a 100644 --- a/plugins/PY/pinpointPy/RequestPlugins.py +++ b/plugins/PY/pinpointPy/RequestPlugins.py @@ -19,23 +19,25 @@ # Created by eeliu at 3/5/20 -from . import Common -from . import Defines -from . import pinpoint +from pinpointPy import Common +from pinpointPy import Defines +from pinpointPy import pinpoint + class RequestPlugin(Common.PinTrace): - def __init__(self,name): + def __init__(self, name): super().__init__(name) - def onBefore(self,*args, **kwargs): + def onBefore(self, *args, **kwargs): super().onBefore(*args, **kwargs) pinpoint.add_trace_header(Defines.PP_APP_NAME, pinpoint.app_name()) pinpoint.add_trace_header(Defines.PP_APP_ID, pinpoint.app_id()) pinpoint.add_context(Defines.PP_APP_NAME, pinpoint.app_name()) - request =args[0] + request = args[0] ############################################################### # print("------------------- call before -----------------------") - pinpoint.add_trace_header(Defines.PP_INTERCEPTOR_NAME, 'BaseFlaskrequest') + pinpoint.add_trace_header( + Defines.PP_INTERCEPTOR_NAME, 'BaseFlaskrequest') pinpoint.add_trace_header(Defines.PP_REQ_URI, request.path) pinpoint.add_trace_header(Defines.PP_REQ_CLIENT, request.remote_addr) pinpoint.add_trace_header(Defines.PP_REQ_SERVER, request.host) @@ -44,8 +46,10 @@ def onBefore(self,*args, **kwargs): # nginx add http if Defines.PP_HTTP_PINPOINT_PSPANID in request.headers: - pinpoint.add_trace_header(Defines.PP_PARENT_SPAN_ID, request.headers[Defines.PP_HTTP_PINPOINT_PSPANID]) - print("PINPOINT_PSPANID:", request.headers[Defines.PP_HTTP_PINPOINT_PSPANID]) + pinpoint.add_trace_header( + Defines.PP_PARENT_SPAN_ID, request.headers[Defines.PP_HTTP_PINPOINT_PSPANID]) + print("PINPOINT_PSPANID:", + request.headers[Defines.PP_HTTP_PINPOINT_PSPANID]) if Defines.PP_HTTP_PINPOINT_SPANID in request.headers: self.sid = request.headers[Defines.PP_HTTP_PINPOINT_SPANID] @@ -80,7 +84,8 @@ def onBefore(self,*args, **kwargs): # Not nginx, no http if Defines.PP_HEADER_PINPOINT_PSPANID in request.headers: - pinpoint.add_trace_header(Defines.PP_PARENT_SPAN_ID, request.headers[Defines.PP_HEADER_PINPOINT_PSPANID]) + pinpoint.add_trace_header( + Defines.PP_PARENT_SPAN_ID, request.headers[Defines.PP_HEADER_PINPOINT_PSPANID]) # print("PINPOINT_PSPANID:", request.headers[PP_HEADER_PINPOINT_PSPANID]) if Defines.PP_HEADER_PINPOINT_PAPPNAME in request.headers: @@ -99,10 +104,12 @@ def onBefore(self,*args, **kwargs): pinpoint.add_trace_header(Defines.PP_PARENT_HOST, self.Ah) if Defines.PP_NGINX_PROXY in request.headers: - pinpoint.add_trace_header(Defines.PP_NGINX_PROXY, request.headers[Defines.PP_NGINX_PROXY]) + pinpoint.add_trace_header( + Defines.PP_NGINX_PROXY, request.headers[Defines.PP_NGINX_PROXY]) if Defines.PP_APACHE_PROXY in request.headers: - pinpoint.add_trace_header(Defines.PP_APACHE_PROXY, request.headers[Defines.PP_APACHE_PROXY]) + pinpoint.add_trace_header( + Defines.PP_APACHE_PROXY, request.headers[Defines.PP_APACHE_PROXY]) pinpoint.add_context(Defines.PP_HEADER_PINPOINT_SAMPLED, "s1") if (Defines.PP_HTTP_PINPOINT_SAMPLED in request.headers and request.headers[Defines.PP_HTTP_PINPOINT_SAMPLED] == Defines.PP_NOT_SAMPLED) or pinpoint.check_trace_limit(): @@ -115,13 +122,10 @@ def onBefore(self,*args, **kwargs): pinpoint.add_context(Defines.PP_SPAN_ID, self.sid) return args, kwargs - def onEnd(self,ret): + def onEnd(self, ret): super().onEnd(ret) return ret def onException(self, e): pinpoint.mark_as_error(str(e), "", 0) raise e - - - diff --git a/plugins/PY/pinpointPy/WSGIPlugin.py b/plugins/PY/pinpointPy/WSGIPlugin.py index 7b24e62e3..9e30f8efd 100644 --- a/plugins/PY/pinpointPy/WSGIPlugin.py +++ b/plugins/PY/pinpointPy/WSGIPlugin.py @@ -19,9 +19,9 @@ # Created by eeliu at 11/9/20 -from .Common import PinTrace -from . import Helper -from . import pinpoint +from pinpointPy.Common import PinTrace +from pinpointPy import Helper +from pinpointPy import pinpoint class WSGIPlugin(PinTrace): @@ -41,4 +41,4 @@ def onEnd(self, ret): return ret def onException(self, e): - pinpoint.mark_as_error(str(e), "", 0) \ No newline at end of file + pinpoint.mark_as_error(str(e), "", 0) diff --git a/plugins/PY/pinpointPy/__init__.py b/plugins/PY/pinpointPy/__init__.py index 067812dc7..00d312e72 100644 --- a/plugins/PY/pinpointPy/__init__.py +++ b/plugins/PY/pinpointPy/__init__.py @@ -17,11 +17,12 @@ # !/usr/bin/env python # -*- coding: UTF-8 -*- # Created by eeliu at 2/4/21 -__version__ = "1.0.15" -from .libs import monkey_patch_for_pinpoint -from .pinpoint import set_agent, app_id, app_name, gen_tid +from pinpointPy.libs import monkey_patch_for_pinpoint +from pinpointPy.pinpoint import set_agent, app_id, app_name, gen_tid, logger # from .PinTranscation import PinHeader,GenPinHeader,PinTranscation __all__ = ['monkey_patch_for_pinpoint', - 'set_agent', 'app_id', 'app_name','gen_tid'] + 'set_agent', 'app_id', 'app_name', 'gen_tid', 'logger'] +__version__ = "1.0.15" +__author__ = 'liu.mingyi@navercorp.com' diff --git a/plugins/PY/pinpointPy/libs/DjangoRest/ViewsPlugin.py b/plugins/PY/pinpointPy/libs/DjangoRest/ViewsPlugin.py index a5ba0b183..882461bea 100644 --- a/plugins/PY/pinpointPy/libs/DjangoRest/ViewsPlugin.py +++ b/plugins/PY/pinpointPy/libs/DjangoRest/ViewsPlugin.py @@ -15,9 +15,9 @@ # ------------------------------------------------------------------------------ -from ... import Common -from ... import Defines -from ... import pinpoint +from pinpointPy import Common +from pinpointPy import Defines +from pinpointPy import pinpoint class ViewsPlugin(Common.PinTrace): diff --git a/plugins/PY/pinpointPy/libs/DjangoRest/__init__.py b/plugins/PY/pinpointPy/libs/DjangoRest/__init__.py index 79b1f919b..5a8df3b38 100644 --- a/plugins/PY/pinpointPy/libs/DjangoRest/__init__.py +++ b/plugins/PY/pinpointPy/libs/DjangoRest/__init__.py @@ -14,24 +14,21 @@ # limitations under the License. - # ------------------------------------------------------------------------------ -from ...Interceptor import Interceptor,intercept_once +from pinpointPy.Interceptor import Interceptor, intercept_once + @intercept_once def monkey_patch(): - try: - from rest_framework.views import APIView - from .ViewsPlugin import ViewsPlugin - - - Interceptors = [ - Interceptor(APIView, 'dispatch', ViewsPlugin), - ] - for interceptor in Interceptors: - interceptor.enable() + from rest_framework.views import APIView + from .ViewsPlugin import ViewsPlugin + Interceptors = [ + Interceptor(APIView, 'dispatch', ViewsPlugin), + ] + for interceptor in Interceptors: + interceptor.enable() - except ImportError as e: - # do nothing - print(e) -__all__=['monkey_patch'] \ No newline at end of file +__all__ = ['monkey_patch'] +__version__ = '0.0.1' +__author__ = 'liu.mingyi@navercorp.com' diff --git a/plugins/PY/pinpointPy/libs/MySQLdb/MysqldbPlugin.py b/plugins/PY/pinpointPy/libs/MySQLdb/MysqldbPlugin.py index cba720227..4f1651b40 100644 --- a/plugins/PY/pinpointPy/libs/MySQLdb/MysqldbPlugin.py +++ b/plugins/PY/pinpointPy/libs/MySQLdb/MysqldbPlugin.py @@ -19,9 +19,9 @@ # ------------------------------------------------------------------------------ -from ... import Common -from ... import pinpoint -from ... import Defines +from pinpointPy import Common +from pinpointPy import pinpoint +from pinpointPy import Defines class MysqldbPlugin(Common.PinTrace): diff --git a/plugins/PY/pinpointPy/libs/MySQLdb/__init__.py b/plugins/PY/pinpointPy/libs/MySQLdb/__init__.py index 5b5cbd103..710214c39 100644 --- a/plugins/PY/pinpointPy/libs/MySQLdb/__init__.py +++ b/plugins/PY/pinpointPy/libs/MySQLdb/__init__.py @@ -16,7 +16,8 @@ # See the License for the specific language governing permissions and - # limitations under the License. - # ------------------------------------------------------------------------------ -from ...Interceptor import Interceptor,intercept_once +from pinpointPy.Interceptor import Interceptor, intercept_once + @intercept_once def monkey_patch(): @@ -33,4 +34,7 @@ def monkey_patch(): except ImportError as e: print(e) -__all__=['monkey_patch'] \ No newline at end of file + +__all__ = ['monkey_patch'] +__version__ = '0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/libs/MysqlConnector/CMysqlPlugin.py b/plugins/PY/pinpointPy/libs/MysqlConnector/CMysqlPlugin.py index f19339108..3fa40e10f 100644 --- a/plugins/PY/pinpointPy/libs/MysqlConnector/CMysqlPlugin.py +++ b/plugins/PY/pinpointPy/libs/MysqlConnector/CMysqlPlugin.py @@ -15,9 +15,9 @@ # ------------------------------------------------------------------------------ -from ... import Common -from ... import Defines -from ... import pinpoint +from pinpointPy import Common +from pinpointPy import Defines +from pinpointPy import pinpoint class CMysqlPlugin(Common.PinTrace): diff --git a/plugins/PY/pinpointPy/libs/MysqlConnector/MysqlPlugin.py b/plugins/PY/pinpointPy/libs/MysqlConnector/MysqlPlugin.py index 21c64db00..24ee21c3c 100644 --- a/plugins/PY/pinpointPy/libs/MysqlConnector/MysqlPlugin.py +++ b/plugins/PY/pinpointPy/libs/MysqlConnector/MysqlPlugin.py @@ -15,9 +15,9 @@ # ------------------------------------------------------------------------------ -from ... import Common -from ... import Defines -from ... import pinpoint +from pinpointPy import Common +from pinpointPy import Defines +from pinpointPy import pinpoint class MysqlPlugin(Common.PinTrace): diff --git a/plugins/PY/pinpointPy/libs/MysqlConnector/__init__.py b/plugins/PY/pinpointPy/libs/MysqlConnector/__init__.py index 2a050e189..ab9b2a0b9 100644 --- a/plugins/PY/pinpointPy/libs/MysqlConnector/__init__.py +++ b/plugins/PY/pinpointPy/libs/MysqlConnector/__init__.py @@ -14,7 +14,7 @@ # limitations under the License. - # ------------------------------------------------------------------------------ -from ...Interceptor import Interceptor,intercept_once +from pinpointPy.Interceptor import Interceptor,intercept_once @intercept_once def monkey_patch(): @@ -39,4 +39,6 @@ def monkey_patch(): # do nothing print(e) -__all__=['monkey_patch'] \ No newline at end of file +__all__=['monkey_patch'] +__version__ = '0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/libs/PyMysql/PyMysqlPlugin.py b/plugins/PY/pinpointPy/libs/PyMysql/PyMysqlPlugin.py index e01dcd85c..3a5b226d2 100644 --- a/plugins/PY/pinpointPy/libs/PyMysql/PyMysqlPlugin.py +++ b/plugins/PY/pinpointPy/libs/PyMysql/PyMysqlPlugin.py @@ -15,9 +15,9 @@ # ------------------------------------------------------------------------------ -from ... import Common -from ... import pinpoint -from ... import Defines +from pinpointPy import Common +from pinpointPy import pinpoint +from pinpointPy import Defines class PyMysqlPlugin(Common.PinTrace): diff --git a/plugins/PY/pinpointPy/libs/PyMysql/__init__.py b/plugins/PY/pinpointPy/libs/PyMysql/__init__.py index 01f36f292..b41e0c043 100644 --- a/plugins/PY/pinpointPy/libs/PyMysql/__init__.py +++ b/plugins/PY/pinpointPy/libs/PyMysql/__init__.py @@ -14,7 +14,7 @@ # limitations under the License. - # ------------------------------------------------------------------------------ -from ...Interceptor import Interceptor,intercept_once +from pinpointPy.Interceptor import Interceptor,intercept_once @intercept_once def monkey_patch(): @@ -35,4 +35,7 @@ def monkey_patch(): # do nothing print(e) -__all__=['monkey_patch'] \ No newline at end of file +__all__=['monkey_patch'] + +__version__ = '0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/libs/__init__.py b/plugins/PY/pinpointPy/libs/__init__.py index b8a31c1e4..5da21a092 100644 --- a/plugins/PY/pinpointPy/libs/__init__.py +++ b/plugins/PY/pinpointPy/libs/__init__.py @@ -14,14 +14,20 @@ # limitations under the License. - # ------------------------------------------------------------------------------ import importlib +from pinpointPy.pinpoint import logger + + def __monkey_patch(*args, **kwargs): for key in kwargs: if kwargs[key]: module = importlib.import_module('pinpointPy.libs.' + key) monkey_patch = getattr(module, 'monkey_patch') if callable(monkey_patch): - monkey_patch() - print("try to install pinpointPy.lib.%s module" % (key)) + try: + monkey_patch() + except Exception as e: + logger.info("exception at {}", e) + def monkey_patch_for_pinpoint(pymongo=True, PyMysql=True, @@ -33,7 +39,9 @@ def monkey_patch_for_pinpoint(pymongo=True, DjangoRest=True, MysqlConnector=True): __monkey_patch(pymongo=pymongo, PyMysql=PyMysql, pyRedis=pyRedis, requests=requests, urllib=urllib, - sqlalchemy=sqlalchemy, MySQLdb=MySQLdb, DjangoRest=DjangoRest,MysqlConnector=MysqlConnector) + sqlalchemy=sqlalchemy, MySQLdb=MySQLdb, DjangoRest=DjangoRest, MysqlConnector=MysqlConnector) __all__ = ['monkey_patch_for_pinpoint'] +__version__ = '0.0.1' +__author__ = 'liu.mingyi@navercorp.com' diff --git a/plugins/PY/pinpointPy/libs/pyRedis/PyRedisPlugins.py b/plugins/PY/pinpointPy/libs/pyRedis/PyRedisPlugins.py index 4f4bc8657..e99b93dbf 100644 --- a/plugins/PY/pinpointPy/libs/pyRedis/PyRedisPlugins.py +++ b/plugins/PY/pinpointPy/libs/pyRedis/PyRedisPlugins.py @@ -21,9 +21,9 @@ # ****************************************************************************** -from ... import Common -from ... import pinpoint -from ... import Defines +from pinpointPy import Common +from pinpointPy import pinpoint +from pinpointPy import Defines class PyRedisPlugins(Common.PinTrace): diff --git a/plugins/PY/pinpointPy/libs/pyRedis/__init__.py b/plugins/PY/pinpointPy/libs/pyRedis/__init__.py index 37b8bb2b2..618cb54b5 100644 --- a/plugins/PY/pinpointPy/libs/pyRedis/__init__.py +++ b/plugins/PY/pinpointPy/libs/pyRedis/__init__.py @@ -19,7 +19,7 @@ # Created by eeliu at 8/20/20 -from ...Interceptor import Interceptor,intercept_once +from pinpointPy.Interceptor import Interceptor,intercept_once @intercept_once def monkey_patch(): @@ -37,4 +37,6 @@ def monkey_patch(): # do nothing print(e) -__all__=['monkey_patch'] \ No newline at end of file +__all__=['monkey_patch'] +__version__ = '0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/libs/pymongo/MongoClientPlugin.py b/plugins/PY/pinpointPy/libs/pymongo/MongoClientPlugin.py index 879dc74b2..d6da19383 100644 --- a/plugins/PY/pinpointPy/libs/pymongo/MongoClientPlugin.py +++ b/plugins/PY/pinpointPy/libs/pymongo/MongoClientPlugin.py @@ -19,9 +19,9 @@ # Created by eeliu at 8/20/20 -from ... import Common -from ... import pinpoint -from ... import Defines +from pinpointPy import Common +from pinpointPy import pinpoint +from pinpointPy import Defines class MongoClientPlugin(Common.PinTrace): diff --git a/plugins/PY/pinpointPy/libs/pymongo/__init__.py b/plugins/PY/pinpointPy/libs/pymongo/__init__.py index defc59e18..bf290cc63 100644 --- a/plugins/PY/pinpointPy/libs/pymongo/__init__.py +++ b/plugins/PY/pinpointPy/libs/pymongo/__init__.py @@ -18,7 +18,7 @@ # ------------------------------------------------------------------------------ # Created by eeliu at 8/20/20 -from ...Interceptor import Interceptor,intercept_once +from pinpointPy.Interceptor import Interceptor,intercept_once @intercept_once def monkey_patch(): @@ -46,3 +46,5 @@ def monkey_patch(): __all__=['monkey_patch'] +__version__ = '0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/libs/requests/NextSpanPlugin.py b/plugins/PY/pinpointPy/libs/requests/NextSpanPlugin.py index b71ae059f..15e34d3d9 100644 --- a/plugins/PY/pinpointPy/libs/requests/NextSpanPlugin.py +++ b/plugins/PY/pinpointPy/libs/requests/NextSpanPlugin.py @@ -15,10 +15,10 @@ # ------------------------------------------------------------------------------ -from ... import Common -from ... import Helper -from ... import Defines -from ... import pinpoint +from pinpointPy import Common +from pinpointPy import Helper +from pinpointPy import Defines +from pinpointPy import pinpoint from urllib.parse import urlparse diff --git a/plugins/PY/pinpointPy/libs/requests/__init__.py b/plugins/PY/pinpointPy/libs/requests/__init__.py index c8ce8bb1e..917121fa0 100644 --- a/plugins/PY/pinpointPy/libs/requests/__init__.py +++ b/plugins/PY/pinpointPy/libs/requests/__init__.py @@ -15,7 +15,7 @@ # ------------------------------------------------------------------------------ -from ...Interceptor import Interceptor,intercept_once +from pinpointPy.Interceptor import Interceptor,intercept_once @intercept_once def monkey_patch(): @@ -37,4 +37,7 @@ def monkey_patch(): except ImportError: pass -__all__=['monkey_patch'] \ No newline at end of file +__all__=['monkey_patch'] + +__version__ = '0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/libs/sqlalchemy/__init__.py b/plugins/PY/pinpointPy/libs/sqlalchemy/__init__.py index e344b499b..89af062d7 100644 --- a/plugins/PY/pinpointPy/libs/sqlalchemy/__init__.py +++ b/plugins/PY/pinpointPy/libs/sqlalchemy/__init__.py @@ -19,7 +19,7 @@ # Created by eeliu at 7/31/20 -from ...Interceptor import intercept_once +from pinpointPy.Interceptor import intercept_once @intercept_once def monkey_patch(): @@ -27,4 +27,7 @@ def monkey_patch(): from .sqlalchemyPlugin import before_cursor_execute,after_cursor_execute except ImportError: pass -__all__=['monkey_patch'] \ No newline at end of file +__all__=['monkey_patch'] + +__version__ = '0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/libs/sqlalchemy/sqlalchemyPlugin.py b/plugins/PY/pinpointPy/libs/sqlalchemy/sqlalchemyPlugin.py index 2ee217b6a..e8a99511e 100644 --- a/plugins/PY/pinpointPy/libs/sqlalchemy/sqlalchemyPlugin.py +++ b/plugins/PY/pinpointPy/libs/sqlalchemy/sqlalchemyPlugin.py @@ -20,8 +20,8 @@ # Created by eeliu at 7/31/20 -from ... import pinpoint -from ... import Defines +from pinpointPy import pinpoint +from pinpointPy import Defines from sqlalchemy import event from sqlalchemy.engine import Engine from urllib.parse import urlparse diff --git a/plugins/PY/pinpointPy/libs/urllib/UrlOpenPlugin.py b/plugins/PY/pinpointPy/libs/urllib/UrlOpenPlugin.py index 1c24cbb15..92d1a7814 100644 --- a/plugins/PY/pinpointPy/libs/urllib/UrlOpenPlugin.py +++ b/plugins/PY/pinpointPy/libs/urllib/UrlOpenPlugin.py @@ -20,10 +20,10 @@ # Created by eeliu at 8/20/20 from urllib.parse import urlparse -from ... import Common -from ... import Defines -from ... import pinpoint -from ... import Helper +from pinpointPy import Common +from pinpointPy import Defines +from pinpointPy import pinpoint +from pinpointPy import Helper class UrlOpenPlugin(Common.PinTrace): diff --git a/plugins/PY/pinpointPy/libs/urllib/__init__.py b/plugins/PY/pinpointPy/libs/urllib/__init__.py index 160d62843..ead7236be 100644 --- a/plugins/PY/pinpointPy/libs/urllib/__init__.py +++ b/plugins/PY/pinpointPy/libs/urllib/__init__.py @@ -19,7 +19,7 @@ # Created by eeliu at 8/20/20 -from ...Interceptor import Interceptor,intercept_once +from pinpointPy.Interceptor import Interceptor,intercept_once @intercept_once def monkey_patch(): @@ -39,3 +39,5 @@ def monkey_patch(): __all__=['monkey_patch'] +__version__ = '0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/pinpoint.py b/plugins/PY/pinpointPy/pinpoint.py index cf62f24ad..86be8d486 100644 --- a/plugins/PY/pinpointPy/pinpoint.py +++ b/plugins/PY/pinpointPy/pinpoint.py @@ -18,12 +18,14 @@ # Created by eeliu at 4/19/22 import random +import logging import _pinpointPy -from collections.abc import Callable __app_id = 'app_id_str' __app_name = 'app_name_str' +logger = logging.Logger('pinpointPy') + def app_id(): global __app_id @@ -56,7 +58,7 @@ def add_context(key: str, value: str, trace_id: int = -1): def get_context(key: str, trace_id: int = -1): - return _pinpointPy.get_context_key(key,trace_id) + return _pinpointPy.get_context_key(key, trace_id) def gen_tid(): @@ -80,7 +82,7 @@ def drop_trace(trace_id: int = -1): _pinpointPy.drop_trace(trace_id) -def check_trace_limit(time: int=-1) -> bool: +def check_trace_limit(time: int = -1) -> bool: return _pinpointPy.check_tracelimit(time) diff --git a/plugins/PY/pinpointPy/pyramid/PyRequestPlugin.py b/plugins/PY/pinpointPy/pyramid/PyRequestPlugin.py index 4db24fae6..2808d4067 100644 --- a/plugins/PY/pinpointPy/pyramid/PyRequestPlugin.py +++ b/plugins/PY/pinpointPy/pyramid/PyRequestPlugin.py @@ -20,8 +20,8 @@ # Created by eeliu at 11/12/20 -from .. import pinpoint -from .. import Defines +from pinpointPy import pinpoint +from pinpointPy import Defines from pinpointPy.RequestPlugins import RequestPlugin class PyRequestPlugin(RequestPlugin): def onBefore(self,*args, **kwargs): diff --git a/plugins/PY/pinpointPy/pyramid/__init__.py b/plugins/PY/pinpointPy/pyramid/__init__.py index 4639f5fab..65e1edb79 100644 --- a/plugins/PY/pinpointPy/pyramid/__init__.py +++ b/plugins/PY/pinpointPy/pyramid/__init__.py @@ -17,8 +17,11 @@ # limitations under the License. - # ------------------------------------------------------------------------------ -from .PyRequestPlugin import PyRequestPlugin +from pinpointPy.pyramid.PyRequestPlugin import PyRequestPlugin # Created by suwei at 4/15/22 -from .tween import * +from pinpointPy.pyramid.tween import * -__all__=['pinpoint_tween','PyRequestPlugin'] \ No newline at end of file +__all__=['pinpoint_tween','PyRequestPlugin'] + +__version__ ='0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/pyramid/tween.py b/plugins/PY/pinpointPy/pyramid/tween.py index e34e37a9f..e0223591a 100644 --- a/plugins/PY/pinpointPy/pyramid/tween.py +++ b/plugins/PY/pinpointPy/pyramid/tween.py @@ -19,7 +19,7 @@ # Created by eeliu at 11/12/20 -from .PyRequestPlugin import PyRequestPlugin +from pinpointPy.pyramid.PyRequestPlugin import PyRequestPlugin def pinpoint_tween(handler,registry): diff --git a/plugins/PY/pinpointPy/pyweb/RequestPlugin.py b/plugins/PY/pinpointPy/pyweb/RequestPlugin.py index fa4180110..d82a2298b 100644 --- a/plugins/PY/pinpointPy/pyweb/RequestPlugin.py +++ b/plugins/PY/pinpointPy/pyweb/RequestPlugin.py @@ -18,7 +18,8 @@ # ------------------------------------------------------------------------------ # Created by eeliu at 11/12/20 -from ..WSGIPlugin import WSGIPlugin +from pinpointPy.WSGIPlugin import WSGIPlugin + class RequestPlugin(WSGIPlugin): - pass \ No newline at end of file + pass diff --git a/plugins/PY/pinpointPy/pyweb/__init__.py b/plugins/PY/pinpointPy/pyweb/__init__.py index b4d85d998..62800eae3 100644 --- a/plugins/PY/pinpointPy/pyweb/__init__.py +++ b/plugins/PY/pinpointPy/pyweb/__init__.py @@ -17,6 +17,8 @@ # See the License for the specific language governing permissions and - # limitations under the License. - # ------------------------------------------------------------------------------ -from .middleware import PinPointMiddleWare -from .RequestPlugin import RequestPlugin -__all__=['PinPointMiddleWare','RequestPlugin'] \ No newline at end of file +from pinpointPy.pyweb.middleware import PinPointMiddleWare +from pinpointPy.pyweb.RequestPlugin import RequestPlugin +__all__ = ['PinPointMiddleWare', 'RequestPlugin'] +__version__ ='0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/pyweb/middleware.py b/plugins/PY/pinpointPy/pyweb/middleware.py index 5471a6907..22704617d 100644 --- a/plugins/PY/pinpointPy/pyweb/middleware.py +++ b/plugins/PY/pinpointPy/pyweb/middleware.py @@ -19,13 +19,14 @@ # Created by eeliu at 11/12/20 -from .RequestPlugin import RequestPlugin +from pinpointPy.pyweb.RequestPlugin import RequestPlugin + def PinPointMiddleWare(application): - def handler(environ,start_response): + def handler(environ, start_response): plugin = RequestPlugin("pyweb-request") - plugin.onBefore(environ,start_response) - response = application(environ,start_response) + plugin.onBefore(environ, start_response) + response = application(environ, start_response) plugin.onEnd(response) return response return handler diff --git a/plugins/PY/pinpointPy/pyweb2/RequestPlugin.py b/plugins/PY/pinpointPy/pyweb2/RequestPlugin.py index fa4180110..14faeae76 100644 --- a/plugins/PY/pinpointPy/pyweb2/RequestPlugin.py +++ b/plugins/PY/pinpointPy/pyweb2/RequestPlugin.py @@ -18,7 +18,7 @@ # ------------------------------------------------------------------------------ # Created by eeliu at 11/12/20 -from ..WSGIPlugin import WSGIPlugin +from pinpointPy.WSGIPlugin import WSGIPlugin class RequestPlugin(WSGIPlugin): pass \ No newline at end of file diff --git a/plugins/PY/pinpointPy/pyweb2/__init__.py b/plugins/PY/pinpointPy/pyweb2/__init__.py index fc0af2f19..d60bfa20a 100644 --- a/plugins/PY/pinpointPy/pyweb2/__init__.py +++ b/plugins/PY/pinpointPy/pyweb2/__init__.py @@ -17,7 +17,10 @@ # See the License for the specific language governing permissions and - # limitations under the License. - # ------------------------------------------------------------------------------ -from .RequestPlugin import RequestPlugin -from .middleware import PinPointMiddleWare +from pinpointPy.pyweb2.RequestPlugin import RequestPlugin +from pinpointPy.pyweb2.middleware import PinPointMiddleWare -__all__=['PinPointMiddleWare','RequestPlugin'] \ No newline at end of file +__all__ = ['PinPointMiddleWare', 'RequestPlugin'] + +__version__ ='0.0.1' +__author__ = 'liu.mingyi@navercorp.com' \ No newline at end of file diff --git a/plugins/PY/pinpointPy/pyweb2/middleware.py b/plugins/PY/pinpointPy/pyweb2/middleware.py index 5471a6907..b9d828b83 100644 --- a/plugins/PY/pinpointPy/pyweb2/middleware.py +++ b/plugins/PY/pinpointPy/pyweb2/middleware.py @@ -19,7 +19,7 @@ # Created by eeliu at 11/12/20 -from .RequestPlugin import RequestPlugin +from pinpointPy.pyweb2.RequestPlugin import RequestPlugin def PinPointMiddleWare(application): def handler(environ,start_response): diff --git a/plugins/PY/pinpointPy/readme.md b/plugins/PY/pinpointPy/readme.md new file mode 100644 index 000000000..77f828cd8 --- /dev/null +++ b/plugins/PY/pinpointPy/readme.md @@ -0,0 +1,7 @@ +## Generate requirements.txt + +```sh +pip install pipreqs +pipreqs . --encoding=utf-8-sig + +``` \ No newline at end of file diff --git a/plugins/PY/requirements.txt b/plugins/PY/requirements.txt new file mode 100644 index 000000000..76f25481f --- /dev/null +++ b/plugins/PY/requirements.txt @@ -0,0 +1,10 @@ +bottle==0.12.25 +Django==4.2.6 +djangorestframework==3.14.0 +fastapi==0.104.0 +Flask==3.0.0 +mysql_connector_repackaged==0.3.1 +pymysql==1.1.0 +redis==5.0.1 +starlette==0.27.0 +starlette_context==0.3.6 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index b88872b75..000000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -astor -coverage diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 7c2b2874c..000000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[bdist_wheel] -universal = 1 \ No newline at end of file diff --git a/setup_pypi.py b/setup_pypi.py index 00000fd93..25d925fa7 100644 --- a/setup_pypi.py +++ b/setup_pypi.py @@ -1,88 +1,53 @@ -from setuptools import setup, Extension,find_packages -from distutils.command.build_ext import build_ext -import os,subprocess,sys +from setuptools import setup, Extension, find_namespace_packages, find_packages +from distutils.command.build_ext import build_ext import platform +from pathlib import Path with open("README", "r") as fh: long_description = fh.read() -if sys.version_info[0] == 3: - class CommonBuild(build_ext): - build_temp = 'build' - def build_common(self): - if not os.path.exists(CommonBuild.build_temp): - os.makedirs(CommonBuild.build_temp) - - comm_path = os.path.abspath('common') - subprocess.check_call(['cmake','-DCMAKE_BUILD_TYPE=Debug',comm_path],cwd=CommonBuild.build_temp) - subprocess.check_call(['cmake', '--build', '.'], cwd=CommonBuild.build_temp) - - def run(self): - try: - out = subprocess.check_output(['cmake', '--version']) - except OSError: - raise RuntimeError("CMake must be installed to build the following extensions: " + - ", ".join(e.name for e in self.extensions)) - self.build_common() - super().run() - - pinpointBuild = CommonBuild - -else: - class CommonBuild(build_ext,object): - build_temp = 'build' - def build_common(self): - if not os.path.exists(CommonBuild.build_temp): - os.makedirs(CommonBuild.build_temp) - - comm_path = os.path.abspath('common') - subprocess.check_call(['cmake','-DCMAKE_BUILD_TYPE=Debug',comm_path],cwd=CommonBuild.build_temp) - subprocess.check_call(['cmake', '--build', '.'], cwd=CommonBuild.build_temp) - - def run(self): - try: - out = subprocess.check_output(['cmake', '--version']) - except OSError: - raise RuntimeError("CMake must be installed to build the following extensions: " + - ", ".join(e.name for e in self.extensions)) - self.build_common() - super(CommonBuild,self).run() - - pinpointBuild = CommonBuild - -############################################### -# check os type - name = platform.system().lower() -agent_libraries = [] -if name=='windows': +agent_libraries = [] +if name == 'windows': raise RuntimeError('pinpoint-c-agent currently not support MS') -elif name == 'darwin': - agent_libraries = ['pinpoint_common', 'stdc++'] -elif name == 'linux': - agent_libraries = ['pinpoint_common','rt','stdc++'] +elif name == 'darwin': + agent_libraries = ['stdc++'] +elif name == 'linux': + agent_libraries = ['rt', 'stdc++'] else: raise RuntimeError('Unknow platform to me: '+name) ############################################### +extFiles = [ + 'src/PY/_pinpoint_py.cpp', +] + +# add pinpoint-common + +for a_file in Path("common").glob('**/*.cpp'): + extFiles.append(str(a_file)) + +for a_file in Path("common").glob('**/*.c'): + extFiles.append(str(a_file)) setup(name='pinpointPy', - version="1.0.15",# don't forget update __version__ in pinpointPy/__init__.py - author="cd_pinpoint members", + version="1.0.15", # don't forget update __version__ in pinpointPy/__init__.py + author="cd_pinpoint members", author_email='dl_cd_pinpoint@navercorp.com', license='Apache License 2.0', url="https://github.com/pinpoint-apm/pinpoint-c-agent", long_description=long_description, long_description_content_type='text/markdown', ext_modules=[ - Extension('_pinpointPy', - ['src/PY/_pinpoint_py.c'], - include_dirs = ['common/include'], - library_dirs = [pinpointBuild.build_temp+"/lib"], - libraries = agent_libraries - ) - ], - package_dir={'':'plugins/PY'}, - packages=find_packages(where='plugins/PY'), - cmdclass={'build_ext': pinpointBuild} -) \ No newline at end of file + Extension('_pinpointPy', + extFiles, + include_dirs=['common/include', + 'common/jsoncpp/include', 'common/src'], + libraries=agent_libraries, + extra_compile_args=['-std=c++11'] + ) + ], + package_dir={'': 'plugins/PY'}, + packages=find_namespace_packages( + 'plugins/PY', include=['pinpointPy.*', 'pinpointPy']), + ) diff --git a/setup_pypi_test.py b/setup_pypi_test.py index 7f034f1c6..80733c07a 100644 --- a/setup_pypi_test.py +++ b/setup_pypi_test.py @@ -1,88 +1,53 @@ -from setuptools import setup, Extension,find_packages -from distutils.command.build_ext import build_ext -import os,subprocess,sys +from setuptools import setup, Extension, find_namespace_packages, find_packages +from distutils.command.build_ext import build_ext import platform +from pathlib import Path with open("README", "r") as fh: long_description = fh.read() -if sys.version_info[0] == 3: - class CommonBuild(build_ext): - build_temp = 'build' - def build_common(self): - if not os.path.exists(CommonBuild.build_temp): - os.makedirs(CommonBuild.build_temp) - - comm_path = os.path.abspath('common') - subprocess.check_call(['cmake','-DCMAKE_BUILD_TYPE=Debug',comm_path],cwd=CommonBuild.build_temp) - subprocess.check_call(['cmake', '--build', '.'], cwd=CommonBuild.build_temp) - - def run(self): - try: - out = subprocess.check_output(['cmake', '--version']) - except OSError: - raise RuntimeError("CMake must be installed to build the following extensions: " + - ", ".join(e.name for e in self.extensions)) - self.build_common() - super().run() - - pinpointBuild = CommonBuild - -else: - class CommonBuild(build_ext,object): - build_temp = 'build' - def build_common(self): - if not os.path.exists(CommonBuild.build_temp): - os.makedirs(CommonBuild.build_temp) - - comm_path = os.path.abspath('common') - subprocess.check_call(['cmake','-DCMAKE_BUILD_TYPE=Debug',comm_path],cwd=CommonBuild.build_temp) - subprocess.check_call(['cmake', '--build', '.'], cwd=CommonBuild.build_temp) - - def run(self): - try: - out = subprocess.check_output(['cmake', '--version']) - except OSError: - raise RuntimeError("CMake must be installed to build the following extensions: " + - ", ".join(e.name for e in self.extensions)) - self.build_common() - super(CommonBuild,self).run() - - pinpointBuild = CommonBuild - -############################################### -# check os type - name = platform.system().lower() -agent_libraries = [] -if name=='windows': +agent_libraries = [] +if name == 'windows': raise RuntimeError('pinpoint-c-agent currently not support MS') -elif name == 'darwin': - agent_libraries = ['pinpoint_common', 'stdc++'] -elif name == 'linux': - agent_libraries = ['pinpoint_common','rt','stdc++'] +elif name == 'darwin': + agent_libraries = ['stdc++'] +elif name == 'linux': + agent_libraries = ['rt', 'stdc++'] else: raise RuntimeError('Unknow platform to me: '+name) ############################################### +extFiles = [ + 'src/PY/_pinpoint_py.c', +] + +# add pinpoint-common + +for a_file in Path("common").glob('**/*.cpp'): + extFiles.append(str(a_file)) + +for a_file in Path("common").glob('**/*.c'): + extFiles.append(str(a_file)) setup(name='pinpointPy', - version="1.0.37", - author="cd_pinpoint members", + version="1.0.38", # don't forget update __version__ in pinpointPy/__init__.py + author="cd_pinpoint members", author_email='dl_cd_pinpoint@navercorp.com', license='Apache License 2.0', url="https://github.com/pinpoint-apm/pinpoint-c-agent", long_description=long_description, long_description_content_type='text/markdown', ext_modules=[ - Extension('_pinpointPy', - ['src/PY/_pinpoint_py.c'], - include_dirs = ['common/include'], - library_dirs = [pinpointBuild.build_temp+"/lib"], - libraries = agent_libraries - ) - ], - package_dir={'':'plugins/PY'}, - packages=find_packages(where='plugins/PY'), - cmdclass={'build_ext': pinpointBuild} -) + Extension('_pinpointPy', + extFiles, + include_dirs=['common/include', + 'common/jsoncpp/include', 'common/src'], + libraries=agent_libraries + ) + ], + package_dir={'': 'plugins/PY'}, + # packages=find_packages('plugins/PY'), + packages=find_namespace_packages( + 'plugins/PY', include=['pinpointPy.*', 'pinpointPy']), + ) diff --git a/src/PY/_pinpoint_py.c b/src/PY/_pinpoint_py.c deleted file mode 100644 index d914f5fab..000000000 --- a/src/PY/_pinpoint_py.c +++ /dev/null @@ -1,561 +0,0 @@ -/******************************************************************************* - * Copyright 2019 NAVER Corp - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy - * of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - ******************************************************************************/ -#include -#include -#include "_pinpoint_py.h" - -static PyObject *py_obj_msg_callback; -// global g_collector_host is suck -// static char* g_collector_host; - -#if defined(__linux__) || defined(_UNIX) || defined(__APPLE__) -#include -#include -#include -static void _init_common_shared(void) __attribute__((constructor)); -static void _free_common_shared(void) __attribute__((destructor)); -static pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER; - -static void _get_read_lock(void) -{ - pthread_rwlock_rdlock(&rwlock); -} - -static void _release_lock(void) -{ - pthread_rwlock_unlock(&rwlock); -} - -static void _get_write_lock(void) -{ - pthread_rwlock_wrlock(&rwlock); -} - -void _init_common_shared(void) -{ - pthread_rwlock_init(&rwlock, NULL); - global_agent_info.get_read_lock = _get_read_lock; - global_agent_info.get_write_lock = _get_write_lock; - global_agent_info.release_lock = _release_lock; -} - -void _free_common_shared(void) -{ - pthread_rwlock_destroy(&rwlock); -} -#else - -#error "your platform not support" - -#endif - -#define MODNAME "_pinpointPy" - -#ifndef CYTHON_UNUSED -#if defined(__GNUC__) -#if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -#define CYTHON_UNUSED __attribute__((__unused__)) -#else -#define CYTHON_UNUSED -#endif -#elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) -#define CYTHON_UNUSED __attribute__((__unused__)) -#else -#define CYTHON_UNUSED -#endif -#endif - -/** - * void pinpoint_add_clues(const char* key,const char* value); - * */ -static PyObject *py_pinpoint_add_clues(PyObject *self, PyObject *args) -{ - char *key = NULL; - char *value = NULL; - int id = -1; - int loc = 0; - if (PyArg_ParseTuple(args, "ss|ii", &key, &value, &id, &loc)) - { - // python is special, use thread-id - if (id == -1) - id = pinpoint_get_per_thread_id(); - - pinpoint_add_clues(id, key, value, loc); - } - return Py_BuildValue("O", Py_True); -} - -/** - * void pinpoint_add_clue(const char* key,const char* value); - */ -static PyObject *py_pinpoint_add_clue(PyObject *self, PyObject *args) -{ - char *key = NULL; - char *value = NULL; - int id = -1; - int loc = 0; - if (PyArg_ParseTuple(args, "ss|ii", &key, &value, &id, &loc)) - { - if (id == -1) - id = pinpoint_get_per_thread_id(); - - pinpoint_add_clue(id, key, value, loc); - } - return Py_BuildValue("O", Py_True); -} - -/** - * void pinpoint_set_special_key(const char* key,const char* value); - */ -static PyObject *py_pinpoint_context_key(PyObject *self, PyObject *args) -{ - char *key = NULL; - char *value = NULL; - int id = -1; - if (PyArg_ParseTuple(args, "ss|i", &key, &value, &id)) - { - if (id == -1) - id = pinpoint_get_per_thread_id(); - - pinpoint_set_context_key(id, key, value); - } - return Py_BuildValue("O", Py_True); -} - -/** - * const char* pinpoint_get_special_key(const char* key); - */ -static PyObject *py_pinpoint_get_key(PyObject *self, PyObject *args) -{ - char *key = NULL; - int id = -1; - if (PyArg_ParseTuple(args, "s|i", &key, &id)) - { - if (id == -1) - id = pinpoint_get_per_thread_id(); - char buf[1024] = {0}; - if (pinpoint_get_context_key(id, key, buf, sizeof(buf)) > 0) - { - return Py_BuildValue("s", buf); - } - else - { - return Py_BuildValue("O", Py_False); - } - } - else - { - return Py_BuildValue("O", Py_False); - } -} - -/** - * bool check_tracelimit(int64_t timestamp); - */ -static PyObject *py_check_tracelimit(PyObject *self, PyObject *args) -{ - int64_t timestamp = -1; - bool ret; - if (!PyArg_ParseTuple(args, "|l", ×tamp)) - { - return NULL; - } - ret = check_tracelimit(timestamp); - if (ret == true) - { - return Py_BuildValue("O", Py_True); - } - else - { - return Py_BuildValue("O", Py_False); - } -} - -static PyObject *py_force_flush_span(PyObject *self, PyObject *args) -{ - int32_t timeout = 3; - int id = -1; - if (!PyArg_ParseTuple(args, "|ii", &timeout, &id)) - { - return NULL; - } - - if (id == -1) - id = pinpoint_get_per_thread_id(); - - if (global_agent_info.inter_flag & E_DISABLE_GIL) - { - pinpoint_force_end_trace(id, timeout); - } - else - { - Py_BEGIN_ALLOW_THREADS - pinpoint_force_end_trace(id, timeout); - Py_END_ALLOW_THREADS - } - - return Py_BuildValue("O", Py_True); -} - -static inline uint32_t startTraceWithPerThreadId(void) -{ - uint32_t id = pinpoint_start_trace(pinpoint_get_per_thread_id()); - pinpoint_update_per_thread_id(id); - return id; -} - -static PyObject *py_pinpoint_start_trace(PyObject *self, PyObject *args) -{ - int ret = 0; - int32_t id = -1; - - if (!PyArg_ParseTuple(args, "|i", &id)) - { - return NULL; - } - - if (global_agent_info.inter_flag & E_DISABLE_GIL) - { - if (id == -1) - { - ret = startTraceWithPerThreadId(); - } - else - { - ret = pinpoint_start_trace(id); - } - } - else - { - Py_BEGIN_ALLOW_THREADS if (id == -1) - { - ret = startTraceWithPerThreadId(); - } - else - { - ret = pinpoint_start_trace(id); - } - Py_END_ALLOW_THREADS - } - - return Py_BuildValue("i", ret); -} - -static inline int endTraceWithPerThreadId(void) -{ - int cid = pinpoint_get_per_thread_id(); - int id = pinpoint_end_trace(cid); - pinpoint_update_per_thread_id(id); - return id; -} - -static PyObject *py_pinpoint_end_trace(PyObject *self, PyObject *args) -{ - int ret = 0; - int32_t id = -1; - if (!PyArg_ParseTuple(args, "|i", &id)) - { - return NULL; - } - - if (global_agent_info.inter_flag & E_DISABLE_GIL) - { - if (id == -1) - { - ret = endTraceWithPerThreadId(); - } - else - { - ret = pinpoint_end_trace(id); - } - } - else - { - Py_BEGIN_ALLOW_THREADS - - if (id == -1) - { - ret = endTraceWithPerThreadId(); - } - else - { - ret = pinpoint_end_trace(id); - } - - Py_END_ALLOW_THREADS - } - - return Py_BuildValue("i", ret); -} - -static PyObject *py_generate_unique_id(PyObject *self, CYTHON_UNUSED PyObject *unused) -{ - uint64_t ret = generate_unique_id(); - return Py_BuildValue("l", ret); -} - -static PyObject *py_trace_has_root(PyObject *self, PyObject *args) -{ - int id = -1; - if (!PyArg_ParseTuple(args, "|i", &id)) - { - return NULL; - } - if (id == -1) - { - id = pinpoint_get_per_thread_id(); - } - - if (id == 0) - { - return Py_BuildValue("O", Py_False); - } - else - { - // check the input id - int ret = pinpoint_trace_is_root(id); - if (ret == -1) - { - PyErr_SetString(PyExc_Exception, "input traceId is not exist"); - return Py_BuildValue("O", Py_False); - ; - } - return Py_BuildValue("O", Py_True); - } -} - -static PyObject *py_pinpoint_drop_trace(PyObject *self, PyObject *args) -{ - int id = -1; - - if (!PyArg_ParseTuple(args, "|i", &id)) - { - return NULL; - } - - if (id == -1) - id = pinpoint_get_per_thread_id(); - - mark_current_trace_status(id, E_TRACE_BLOCK); - - return Py_BuildValue("O", Py_True); -} - -static PyObject *py_pinpoint_start_time(PyObject *self, CYTHON_UNUSED PyObject *unused) -{ - uint64_t start_time = pinpoint_start_time(); - return Py_BuildValue("l", start_time); -} - -// origin from https://docs.python.org/3/extending/extending.html#calling-python-functions-from-c - -static void msg_log_error_cb(char *msg) -{ - if (py_obj_msg_callback && msg) - { - PyObject *arglist; - PyObject *result; - arglist = Py_BuildValue("(s)", msg); - result = PyObject_CallObject(py_obj_msg_callback, arglist); - if (result == NULL) - { - fprintf(stderr, "%s", msg); - PyErr_SetString(PyExc_TypeError, msg); - return; - } - Py_XDECREF(result); // I don't care return - Py_DECREF(arglist); - } -} - -static PyObject *py_pinpoint_enable_utest(PyObject *self, PyObject *args) -{ - global_agent_info.inter_flag |= E_LOGGING; - global_agent_info.inter_flag |= E_DISABLE_GIL; - - PyObject *temp; - if (PyArg_ParseTuple(args, "O:callback", &temp)) - { - if (PyCallable_Check(temp)) - { - Py_XINCREF(temp); - Py_XDECREF(py_obj_msg_callback); - py_obj_msg_callback = temp; - register_error_cb(msg_log_error_cb); - } - } - // disable logging callback - global_agent_info.inter_flag |= E_UTEST; - - return Py_BuildValue("O", Py_True); -} - -bool set_collector_host(char *host) -{ - if (strcasestr(host, "unix") || strcasestr(host, "tcp")) - { - strncpy(global_agent_info.co_host, host, MAX_ADDRESS_SIZE); - return true; - } - PyErr_SetString(PyExc_TypeError, "collector_host must start with unix/tcp"); - return false; -} - -/** - * def set_agent(collector_host=, trace_limit=,enable_coroutines=) - */ -static PyObject *py_set_agent(PyObject *self, PyObject *args, PyObject *keywds) -{ - // PyObject* setting; - bool ret = false; - static char *kwlist[] = {"collector_host", "trace_limit", NULL}; - char *collector_host = "unix:/tmp/collector-agent.sock"; - long trace_limit = -1; - if (PyArg_ParseTupleAndKeywords(args, keywds, "s|l", kwlist, &collector_host, &trace_limit)) - { - global_agent_info.get_write_lock(); - ret = set_collector_host(collector_host); - if (!ret) - { - goto END_OF_PARSE; - } - - global_agent_info.trace_limit = trace_limit; - - pp_trace("collector_host:%s", collector_host); - pp_trace("trace_limit:%ld", trace_limit); - - END_OF_PARSE: - global_agent_info.release_lock(); - - if (ret == true) - { - return Py_BuildValue("O", Py_True); - } - return NULL; - } - else - { - return NULL; - } -} - -static PyObject *py_pinpoint_mark_an_error(PyObject *self, PyObject *args) -{ - char *msg = NULL; - char *file_name = NULL; - uint32_t line_no = 0; - int id = -1; - if (PyArg_ParseTuple(args, "ssi|i", &msg, &file_name, &line_no, &id)) - { - if (id == -1) - id = pinpoint_get_per_thread_id(); - - catch_error(id, msg, file_name, line_no); - } - - return Py_BuildValue("O", Py_True); -} - -/* Module method table */ -static PyMethodDef PinpointMethods[] = { - {"start_trace", py_pinpoint_start_trace, METH_VARARGS, "def start_trace(int id=-1):# create a new trace and insert into trace chain"}, - {"end_trace", py_pinpoint_end_trace, METH_VARARGS, "def end_trace(int id=-1):# end currently matched trace"}, - {"unique_id", py_generate_unique_id, METH_NOARGS, "def unique_id()-> long"}, - {"trace_has_root", py_trace_has_root, METH_VARARGS, "def trace_has_root(int id=-1)-> long # check current whether have a root. \n True: \nFalse: \n Note: If the id is invalid, return false"}, - {"drop_trace", py_pinpoint_drop_trace, METH_VARARGS, "def drop_trace(int id=-1):# drop this trace"}, - {"start_time", py_pinpoint_start_time, METH_NOARGS, "def start_time()->long"}, - {"add_clues", py_pinpoint_add_clues, METH_VARARGS, "def add_clues(string key,string value,int id=-1,int loc=0)"}, - {"add_clue", py_pinpoint_add_clue, METH_VARARGS, "def add_clue(string key,string value,int id=-1,int loc=0)"}, - {"set_context_key", py_pinpoint_context_key, METH_VARARGS, "def set_context_key(string key,string value,int id=-1): # create a key-value pair that bases on current trace chain"}, - {"get_context_key", py_pinpoint_get_key, METH_VARARGS, "def get_context_key(string key,int id=-1)->string "}, - {"check_tracelimit", py_check_tracelimit, METH_VARARGS, "def check_tracelimit(long timestamp=-1): #check trace whether is limit"}, - {"enable_debug", py_pinpoint_enable_utest, METH_VARARGS, "def enable_debug(callback):#enable logging output(callback )"}, - {"force_flush_trace", py_force_flush_span, METH_VARARGS, "def force_flush_trace(timeout=3,int id=-1): #force flush span during timeout"}, - {"mark_as_error", py_pinpoint_mark_an_error, METH_VARARGS, "def mark_as_error(string msg,string file_name,uint line_no,int id=-1): #Found an error in this trace"}, - {"set_agent", (PyCFunction)py_set_agent, METH_VARARGS | METH_KEYWORDS, "def set_agent(collector_host=\"unix:/tmp/collector-agent.sock or tcp:host:port\",trace_limit=-1): # set pinpint collector information"}, - {NULL, NULL, 0, NULL}}; - -#if PY_MAJOR_VERSION > 2 - -static void free_pinpoint_module(void *module) -{ - Py_XDECREF(py_obj_msg_callback); - - if (py_obj_msg_callback) - { - Py_DECREF(py_obj_msg_callback); - } -} - -/* Module structure */ -static struct PyModuleDef _pinpointPymodule = { - - PyModuleDef_HEAD_INIT, - - MODNAME, /* name of module */ - "python agent for pinpoint platform", /* Doc string (may be NULL) */ - -1, /* Size of per-interpreter state or -1 */ - PinpointMethods, /* Method table */ - NULL, - NULL, - NULL, - free_pinpoint_module /* free global variables*/ -}; - -/* Module initialization function */ -PyMODINIT_FUNC -PyInit__pinpointPy(void) -{ - - global_agent_info.agent_type = 1700; - strncpy(global_agent_info.co_host, "unix:/tmp/collector.sock", MAX_ADDRESS_SIZE); - global_agent_info.inter_flag = 0; - global_agent_info.timeout_ms = 0; - global_agent_info.trace_limit = -1; - register_error_cb(NULL); - - PyObject *m = PyModule_Create(&_pinpointPymodule); - if (m == NULL) - return NULL; - - return m; -} -#else - -PyDoc_STRVAR(pinpointPy__doc__, "python agent for pinpoint platform"); - -PyMODINIT_FUNC -init_pinpointPy(void) -{ - PyObject *m; - - m = Py_InitModule3(MODNAME, - PinpointMethods, - pinpointPy__doc__); - if (m == NULL) - return; - - global_agent_info.agent_type = 1700; - strncpy(global_agent_info.co_host, "unix:/tmp/collector.sock", MAX_ADDRESS_SIZE); - global_agent_info.inter_flag = 0; - global_agent_info.timeout_ms = 0; - global_agent_info.trace_limit = -1; - - register_error_cb(NULL); -} - -#endif diff --git a/src/PY/_pinpoint_py.cpp b/src/PY/_pinpoint_py.cpp new file mode 100644 index 000000000..a19142f2c --- /dev/null +++ b/src/PY/_pinpoint_py.cpp @@ -0,0 +1,484 @@ +/******************************************************************************* + * Copyright 2019 NAVER Corp + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ +#include +#include +#include "_pinpoint_py.h" + +static PyObject* py_obj_msg_callback; +// global g_collector_host is suck +// static char* g_collector_host; + +#if defined(__linux__) || defined(_UNIX) || defined(__APPLE__) +#include +#include +#include +static void _init_common_shared(void) __attribute__((constructor)); +static void _free_common_shared(void) __attribute__((destructor)); +static pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER; + +static void _get_read_lock(void) { pthread_rwlock_rdlock(&rwlock); } + +static void _release_lock(void) { pthread_rwlock_unlock(&rwlock); } + +static void _get_write_lock(void) { pthread_rwlock_wrlock(&rwlock); } + +void _init_common_shared(void) { + pthread_rwlock_init(&rwlock, NULL); + global_agent_info.get_read_lock = _get_read_lock; + global_agent_info.get_write_lock = _get_write_lock; + global_agent_info.release_lock = _release_lock; +} + +void _free_common_shared(void) { pthread_rwlock_destroy(&rwlock); } +#else + +#error "your platform not support" + +#endif + +#define MODNAME "_pinpointPy" + +#ifndef CYTHON_UNUSED +#if defined(__GNUC__) +#if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +#define CYTHON_UNUSED __attribute__((__unused__)) +#else +#define CYTHON_UNUSED +#endif +#elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +#define CYTHON_UNUSED __attribute__((__unused__)) +#else +#define CYTHON_UNUSED +#endif +#endif + +/** + * void pinpoint_add_clues(const char* key,const char* value); + * */ +static PyObject* py_pinpoint_add_clues(PyObject* self, PyObject* args) { + char* key = NULL; + char* value = NULL; + NodeID id = E_INVALID_NODE; + int loc = 0; + if (PyArg_ParseTuple(args, "ss|ii", &key, &value, &id, &loc)) { + // python is special, use thread-id + if (id == -1) + id = pinpoint_get_per_thread_id(); + + pinpoint_add_clues(id, key, value, loc); + } + return Py_BuildValue("O", Py_True); +} + +/** + * void pinpoint_add_clue(const char* key,const char* value); + */ +static PyObject* py_pinpoint_add_clue(PyObject* self, PyObject* args) { + char* key = NULL; + char* value = NULL; + int id = -1; + int loc = 0; + if (PyArg_ParseTuple(args, "ss|ii", &key, &value, &id, &loc)) { + if (id == -1) + id = pinpoint_get_per_thread_id(); + + pinpoint_add_clue(id, key, value, loc); + } + return Py_BuildValue("O", Py_True); +} + +/** + * void pinpoint_set_special_key(const char* key,const char* value); + */ +static PyObject* py_pinpoint_context_key(PyObject* self, PyObject* args) { + char* key = NULL; + char* value = NULL; + int id = -1; + if (PyArg_ParseTuple(args, "ss|i", &key, &value, &id)) { + if (id == -1) + id = pinpoint_get_per_thread_id(); + + pinpoint_set_context_key(id, key, value); + } + return Py_BuildValue("O", Py_True); +} + +/** + * const char* pinpoint_get_special_key(const char* key); + */ +static PyObject* py_pinpoint_get_key(PyObject* self, PyObject* args) { + char* key = NULL; + int id = -1; + if (PyArg_ParseTuple(args, "s|i", &key, &id)) { + if (id == -1) + id = pinpoint_get_per_thread_id(); + char buf[1024] = {0}; + if (pinpoint_get_context_key(id, key, buf, sizeof(buf)) > 0) { + return Py_BuildValue("s", buf); + } else { + return Py_BuildValue("O", Py_False); + } + } else { + return Py_BuildValue("O", Py_False); + } +} + +/** + * bool check_tracelimit(int64_t timestamp); + */ +static PyObject* py_check_tracelimit(PyObject* self, PyObject* args) { + int64_t timestamp = -1; + bool ret; + if (!PyArg_ParseTuple(args, "|l", ×tamp)) { + return NULL; + } + ret = check_tracelimit(timestamp); + if (ret == true) { + return Py_BuildValue("O", Py_True); + } else { + return Py_BuildValue("O", Py_False); + } +} + +static PyObject* py_force_flush_span(PyObject* self, PyObject* args) { + int32_t timeout = 3; + int id = -1; + if (!PyArg_ParseTuple(args, "|ii", &timeout, &id)) { + return NULL; + } + + if (id == -1) + id = pinpoint_get_per_thread_id(); + + if (global_agent_info.inter_flag & E_DISABLE_GIL) { + pinpoint_force_end_trace(id, timeout); + } else { + Py_BEGIN_ALLOW_THREADS pinpoint_force_end_trace(id, timeout); + Py_END_ALLOW_THREADS + } + + return Py_BuildValue("O", Py_True); +} + +static inline uint32_t startTraceWithPerThreadId(void) { + uint32_t id = pinpoint_start_trace(pinpoint_get_per_thread_id()); + pinpoint_update_per_thread_id(id); + return id; +} + +static PyObject* py_pinpoint_start_trace(PyObject* self, PyObject* args) { + int ret = 0; + int32_t id = -1; + + if (!PyArg_ParseTuple(args, "|i", &id)) { + return NULL; + } + + if (global_agent_info.inter_flag & E_DISABLE_GIL) { + if (id == -1) { + ret = startTraceWithPerThreadId(); + } else { + ret = pinpoint_start_trace(id); + } + } else { + Py_BEGIN_ALLOW_THREADS if (id == -1) { ret = startTraceWithPerThreadId(); } + else { + ret = pinpoint_start_trace(id); + } + Py_END_ALLOW_THREADS + } + + return Py_BuildValue("i", ret); +} + +static inline int endTraceWithPerThreadId(void) { + NodeID cid = pinpoint_get_per_thread_id(); + NodeID id = pinpoint_end_trace(cid); + pinpoint_update_per_thread_id(id); + return id; +} + +static PyObject* py_pinpoint_end_trace(PyObject* self, PyObject* args) { + NodeID ret = 0; + int32_t id = -1; + if (!PyArg_ParseTuple(args, "|i", &id)) { + return NULL; + } + + if (global_agent_info.inter_flag & E_DISABLE_GIL) { + if (id == -1) { + ret = endTraceWithPerThreadId(); + } else { + ret = pinpoint_end_trace(id); + } + } else { + Py_BEGIN_ALLOW_THREADS + + if (id == -1) { + ret = endTraceWithPerThreadId(); + } + else { + ret = pinpoint_end_trace(id); + } + + Py_END_ALLOW_THREADS + } + + return Py_BuildValue("i", ret); +} + +static PyObject* py_generate_unique_id(PyObject* self, CYTHON_UNUSED PyObject* unused) { + uint64_t ret = generate_unique_id(); + return Py_BuildValue("l", ret); +} + +static PyObject* py_trace_has_root(PyObject* self, PyObject* args) { + int id = -1; + if (!PyArg_ParseTuple(args, "|i", &id)) { + return NULL; + } + if (id == -1) { + id = pinpoint_get_per_thread_id(); + } + + if (id == 0) { + return Py_BuildValue("O", Py_False); + } else { + // check the input id + int ret = pinpoint_trace_is_root(id); + if (ret == -1) { + PyErr_SetString(PyExc_Exception, "input traceId is not exist"); + return Py_BuildValue("O", Py_False); + ; + } + return Py_BuildValue("O", Py_True); + } +} + +static PyObject* py_pinpoint_drop_trace(PyObject* self, PyObject* args) { + int id = -1; + + if (!PyArg_ParseTuple(args, "|i", &id)) { + return NULL; + } + + if (id == -1) + id = pinpoint_get_per_thread_id(); + + mark_current_trace_status(id, E_TRACE_BLOCK); + + return Py_BuildValue("O", Py_True); +} + +static PyObject* py_pinpoint_start_time(PyObject* self, CYTHON_UNUSED PyObject* unused) { + uint64_t start_time = pinpoint_start_time(); + return Py_BuildValue("l", start_time); +} + +// origin from https://docs.python.org/3/extending/extending.html#calling-python-functions-from-c + +static void msg_log_error_cb(char* msg) { + if (py_obj_msg_callback && msg) { + PyObject* arglist; + PyObject* result; + arglist = Py_BuildValue("(s)", msg); + result = PyObject_CallObject(py_obj_msg_callback, arglist); + if (result == NULL) { + fprintf(stderr, "%s", msg); + PyErr_SetString(PyExc_TypeError, msg); + return; + } + Py_XDECREF(result); // I don't care return + Py_DECREF(arglist); + } +} + +static PyObject* py_pinpoint_enable_utest(PyObject* self, PyObject* args) { + global_agent_info.inter_flag |= E_LOGGING; + global_agent_info.inter_flag |= E_DISABLE_GIL; + + PyObject* temp; + if (PyArg_ParseTuple(args, "O:callback", &temp)) { + if (PyCallable_Check(temp)) { + Py_XINCREF(temp); + Py_XDECREF(py_obj_msg_callback); + py_obj_msg_callback = temp; + register_error_cb(msg_log_error_cb); + } + } + // disable logging callback + global_agent_info.inter_flag |= E_UTEST; + + return Py_BuildValue("O", Py_True); +} + +bool set_collector_host(const char* host) { + if (strcasestr(host, "unix") || strcasestr(host, "tcp")) { + strncpy(global_agent_info.co_host, host, MAX_ADDRESS_SIZE); + return true; + } + PyErr_SetString(PyExc_TypeError, "collector_host must start with unix/tcp"); + return false; +} + +/** + * def set_agent(collector_host=, trace_limit=,enable_coroutines=) + */ +static PyObject* py_set_agent(PyObject* self, PyObject* args, PyObject* keywds) { + // PyObject* setting; + bool ret = false; + char default_host[] = "collector_host"; + char default_tracelimit[] = "trace_limit"; + char* kwlist[] = {default_host, default_tracelimit, NULL}; + char* collector_host = nullptr; // = "unix:/tmp/collector-agent.sock"; + long trace_limit = -1; + if (PyArg_ParseTupleAndKeywords(args, keywds, "s|l", kwlist, &collector_host, &trace_limit)) { + global_agent_info.get_write_lock(); + ret = set_collector_host(collector_host); + if (!ret) { + goto END_OF_PARSE; + } + + global_agent_info.trace_limit = trace_limit; + + pp_trace("collector_host:%s", collector_host); + pp_trace("trace_limit:%ld", trace_limit); + + END_OF_PARSE: + global_agent_info.release_lock(); + + if (ret == true) { + return Py_BuildValue("O", Py_True); + } + return NULL; + } else { + return NULL; + } +} + +static PyObject* py_pinpoint_mark_an_error(PyObject* self, PyObject* args) { + char* msg = NULL; + char* file_name = NULL; + uint32_t line_no = 0; + NodeID id = -1; + if (PyArg_ParseTuple(args, "ssi|i", &msg, &file_name, &line_no, &id)) { + if (id == -1) + id = pinpoint_get_per_thread_id(); + + catch_error(id, msg, file_name, line_no); + } + + return Py_BuildValue("O", Py_True); +} + +/* Module method table */ +static PyMethodDef PinpointMethods[] = { + {"start_trace", py_pinpoint_start_trace, METH_VARARGS, + "def start_trace(int id=-1):# create a new trace and insert into trace chain"}, + {"end_trace", py_pinpoint_end_trace, METH_VARARGS, + "def end_trace(int id=-1):# end currently matched trace"}, + {"unique_id", py_generate_unique_id, METH_NOARGS, "def unique_id()-> long"}, + {"trace_has_root", py_trace_has_root, METH_VARARGS, + "def trace_has_root(int id=-1)-> long # check current whether have a root. \n True: \nFalse: " + "\n Note: If the id is invalid, return false"}, + {"drop_trace", py_pinpoint_drop_trace, METH_VARARGS, + "def drop_trace(int id=-1):# drop this trace"}, + {"start_time", py_pinpoint_start_time, METH_NOARGS, "def start_time()->long"}, + {"add_clues", py_pinpoint_add_clues, METH_VARARGS, + "def add_clues(string key,string value,int id=-1,int loc=0)"}, + {"add_clue", py_pinpoint_add_clue, METH_VARARGS, + "def add_clue(string key,string value,int id=-1,int loc=0)"}, + {"set_context_key", py_pinpoint_context_key, METH_VARARGS, + "def set_context_key(string key,string value,int id=-1): # create a key-value pair that bases " + "on current trace chain"}, + {"get_context_key", py_pinpoint_get_key, METH_VARARGS, + "def get_context_key(string key,int id=-1)->string "}, + {"check_tracelimit", py_check_tracelimit, METH_VARARGS, + "def check_tracelimit(long timestamp=-1): #check trace whether is limit"}, + {"enable_debug", py_pinpoint_enable_utest, METH_VARARGS, + "def enable_debug(callback):#enable logging output(callback )"}, + {"force_flush_trace", py_force_flush_span, METH_VARARGS, + "def force_flush_trace(timeout=3,int id=-1): #force flush span during timeout"}, + {"mark_as_error", py_pinpoint_mark_an_error, METH_VARARGS, + "def mark_as_error(string msg,string file_name,uint line_no,int id=-1): #Found an error in " + "this trace"}, + {"set_agent", (PyCFunction)py_set_agent, METH_VARARGS | METH_KEYWORDS, + "def set_agent(collector_host=\"unix:/tmp/collector-agent.sock or " + "tcp:host:port\",trace_limit=-1): # set pinpint collector information"}, + {NULL, NULL, 0, NULL}}; + +#if PY_MAJOR_VERSION > 2 + +static void free_pinpoint_module(void* module) { + Py_XDECREF(py_obj_msg_callback); + + if (py_obj_msg_callback) { + Py_DECREF(py_obj_msg_callback); + } +} + +/* Module structure */ +static struct PyModuleDef _pinpointPymodule = { + + PyModuleDef_HEAD_INIT, + + MODNAME, /* name of module */ + "python agent for pinpoint platform", /* Doc string (may be NULL) */ + -1, /* Size of per-interpreter state or -1 */ + PinpointMethods, /* Method table */ + NULL, + NULL, + NULL, + free_pinpoint_module /* free global variables*/ +}; + +/* Module initialization function */ +PyMODINIT_FUNC PyInit__pinpointPy(void) { + + global_agent_info.agent_type = 1700; + strncpy(global_agent_info.co_host, "unix:/tmp/collector.sock", MAX_ADDRESS_SIZE); + global_agent_info.inter_flag = 0; + global_agent_info.timeout_ms = 0; + global_agent_info.trace_limit = -1; + register_error_cb(NULL); + + PyObject* m = PyModule_Create(&_pinpointPymodule); + if (m == NULL) + return NULL; + + return m; +} +#else + +PyDoc_STRVAR(pinpointPy__doc__, "python agent for pinpoint platform"); + +PyMODINIT_FUNC init_pinpointPy(void) { + PyObject* m; + + m = Py_InitModule3(MODNAME, PinpointMethods, pinpointPy__doc__); + if (m == NULL) + return; + + global_agent_info.agent_type = 1700; + strncpy(global_agent_info.co_host, "unix:/tmp/collector.sock", MAX_ADDRESS_SIZE); + global_agent_info.inter_flag = 0; + global_agent_info.timeout_ms = 0; + global_agent_info.trace_limit = -1; + + register_error_cb(NULL); +} + +#endif diff --git a/src/PY/test/TestCoroutines.py b/src/PY/test/testCoroutines.py similarity index 100% rename from src/PY/test/TestCoroutines.py rename to src/PY/test/testCoroutines.py diff --git a/src/PY/test/TestPinpoint.py b/src/PY/test/testPinpoint.py similarity index 100% rename from src/PY/test/TestPinpoint.py rename to src/PY/test/testPinpoint.py diff --git a/src/PY/test/TestUnderProcessMode.py b/src/PY/test/testUnderProcessMode.py similarity index 100% rename from src/PY/test/TestUnderProcessMode.py rename to src/PY/test/testUnderProcessMode.py diff --git a/src/PY/test/TestUnderThreadMode.py b/src/PY/test/testUnderThreadMode.py similarity index 100% rename from src/PY/test/TestUnderThreadMode.py rename to src/PY/test/testUnderThreadMode.py diff --git a/testapps/PY/app.py b/testapps/PY/app.py index cc00d5ad6..9e8497566 100644 --- a/testapps/PY/app.py +++ b/testapps/PY/app.py @@ -16,8 +16,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # ------------------------------------------------------------------------------ -import json -from flask import Flask,request,Response +from RedisControl import RedisControl +from DBControl import DBControl +import test_returns +import test_args +from test_exception import UserDefineException +import test_exception +from test_static_class_method import Method +import test_abstract +import test_private +import test_special +import test_mixin +from test_band import BandClass +from flask import Flask, request, Response from flask import render_template from datetime import datetime @@ -26,7 +37,10 @@ import test_function from app1 import user_function -import person, student, teacher, doctor +import person +import student +import teacher +import doctor import test_recursion import test_generatior import test_higher_order @@ -36,34 +50,22 @@ import test_partial import test_band from pinpointPy.Flask.PinPointMiddleWare import PinPointMiddleWare -from pinpointPy import set_agent,monkey_patch_for_pinpoint +from pinpointPy import set_agent, monkey_patch_for_pinpoint monkey_patch_for_pinpoint() -from test_band import BandClass -import test_mixin -import test_special -import test_private -import test_abstract -from test_static_class_method import Method -import test_exception -from test_exception import UserDefineException -import test_args -import test_returns -from DBControl import DBControl -from RedisControl import RedisControl app = Flask(__name__) -set_agent("flask-agent","FLASK-AGENT",'tcp:dev-collector:9999',-1) +set_agent("cd.dev.test.py", "cd.dev.test.py", 'tcp:dev-collector:9999', -1) + +app.wsgi_app = PinPointMiddleWare(app, app.wsgi_app) -app.wsgi_app = PinPointMiddleWare(app,app.wsgi_app) @app.route('/', methods=['GET', 'POST']) def home(): return render_template("index.html") - GREETING = "Hello World!" @@ -85,6 +87,12 @@ def test_func1_form(): return '''

%s

''' % func1 +@app.route('/test_ut/', methods=['GET']) +def test_ut(username): + + return f'{username}->{request.url_rule}\'s profile' + + @app.route('/test_user_func2', methods=['GET']) def test_func2_form(): instance = test_function.TestUserFunc1("Evy", "99") @@ -121,6 +129,7 @@ def test_inherit_form(): @app.route('/test_recursion', methods=['GET']) def test_recursion_form(): + print(request.url_rule) r = test_recursion.fact(3) return '''

%s

''' % r @@ -147,6 +156,7 @@ def test_generator_form(): @app.route('/test_higher_order', methods=['GET']) def test_higher_order_form(): from pinpointPy.CommonPlugin import PinpointCommonPlugin + @PinpointCommonPlugin(__name__) def f(x): return x * x @@ -171,7 +181,7 @@ def test_return_form(): @app.route('/test_lambda', methods=['GET']) def test_lambda_form(): - lambda_f = lambda x: x * x + def lambda_f(x): return x * x h1 = lambda_f(3) l = test_lambda.return_lambda(3) h2 = l() @@ -210,7 +220,6 @@ def test_band_form():

%s

''' % (h1, h2, h3) - @app.route('/test_mixin', methods=['GET']) def test_mixin_form(): i1 = test_mixin.Human() @@ -261,9 +270,6 @@ def test_classmethod_form(): @app.route('/test_exception', methods=['GET']) def test_exception_form(): - # h1 = test_exception.test_syntaxerror("Hello") - # h1 = test_exception.test_nameerror("Hello") - # h1 = test_exception.test_ZeroDivisionError(0) h1 = test_exception.test_userexception("Evy") return '''

%s

''' % h1 @@ -295,13 +301,15 @@ def test_exception_in_recursion_form(): def test_arguments_form(): i1 = Method() f = open("app.py", 'r') - l1 = [None, 123, 3.1415, True, "abc", (123, "abc"), [456, "def"], {"a":1, "b":2}, set("abc"), i1, str(UserDefineException("Evy")), f, GREETING, lambda x:x*x] + l1 = [None, 123, 3.1415, True, "abc", (123, "abc"), [456, "def"], {"a": 1, "b": 2}, set( + "abc"), i1, str(UserDefineException("Evy")), f, GREETING, lambda x: x*x] l2 = [] for i in l1: l2.append(test_args.test_args1(i)) f.close() - h1 = "
".join('%s' %str(id) for id in l2) - h2 = test_args.test_args2("Hello", "Evy", "a", "b", "c", a="A", b="B", c="C") + h1 = "
".join('%s' % str(id) for id in l2) + h2 = test_args.test_args2("Hello", "Evy", "a", "b", + "c", a="A", b="B", c="C") return '''

%s

%s

''' % (h1, h2) @@ -310,32 +318,34 @@ def test_arguments_form(): def test_returns_form(): i1 = Method() f = open("app.py", 'r') - l1 = [None, 123, 3.1415, True, "abc", (123, "abc"), [456, "def"], {"a":1, "b":2}, set("abc"), i1, str(UserDefineException("Evy")), f, GREETING, lambda x:x*x] + l1 = [None, 123, 3.1415, True, "abc", (123, "abc"), [456, "def"], {"a": 1, "b": 2}, set( + "abc"), i1, str(UserDefineException("Evy")), f, GREETING, lambda x: x*x] # l1 = [[456, "def"]] l2 = [] for i in l1: l2.append(str(type(test_returns.test_returns1(i)))[8:-2]) f.close() - h1 = "
".join('%s' %str(id) for id in l2) - h2 = test_returns.test_returns2("Hello", "Evy", "a", "b", "c", a="A", b="B", c="C") + h1 = "
".join('%s' % str(id) for id in l2) + h2 = test_returns.test_returns2( + "Hello", "Evy", "a", "b", "c", a="A", b="B", c="C") return '''

%s

%s

''' % (h1, h2) @app.route('/test_mysql', methods=['GET']) def test_mysql_form(): - mysql = DBControl("localhost", "root", "root", "DBTest") + mysql = DBControl("dev-mysql", "root", "password", "employees") mysql.con_db() - h1 = mysql.db_select("select * from user;") + h1 = mysql.db_select("select * from employees limit 128") mysql.db_close() - return "
".join('%s' %str(id) for id in h1) + return "
".join('%s' % str(id) for id in h1) @app.route('/test_redis', methods=['GET']) def test_redis_form(): r = RedisControl("localhost", "6379") r.connection() - h1 = r.set("name","Evy") + h1 = r.set("name", "Evy") r.delete("name") return '''

%s

''' % h1 @@ -358,44 +368,10 @@ def signin_form(): @app.route('/signin', methods=['POST']) def signin(): - if request.form['username']=='admin' and request.form['password']=='password': + if request.form['username'] == 'admin' and request.form['password'] == 'password': return '

Hello, admin!

' return '

Bad username or password.

' -@app.route('/shopping/orders/',methods=['GET']) -def getOrder(orderId): - #h1 = requests.get('http://order.demo.pinpoint.com:8182/orders/'+orderId) - #print(h1.content) - return Response('{"orderId":"3a8b5c33-575e-42d0-bd2c-335d1917297d","orderStatus":"OPEN","paymentAmount":2300}',mimetype='application/json') - -@app.route('/shopping/orders/',methods=['PATCH']) -def processOrder(orderId): - h1 = requests.get('http://py.backend.com:8184/shopping/products') - print(h1.status_code) - return h1.content - -@app.route('/shopping/products',methods=['GET']) -def getProducts(): - #h1 = requests.get('http://product.demo.pinpoint.com:8181/products') - h1 = requests.get('http://shopping.demo.pinpoint.com:8180/shopping/products') - products = json.loads(s=h1.content) - print(h1.content) - valid_products(products) - return Response('[{"productId":1,"productName":"ITEM_1","productPrice":500}]', mimetype='application/json') - -@app.route('/shopping/orders',methods=['POST']) -def createOrders(): - content = request.json - requests.post('http://php.backend.com:8185/shopping/orders',json=content) - - return Response('{"orderId":"3a8b5c33-575e-42d0-bd2c-335d1917297d","orderStatus":"OPEN","paymentAmount":2300}',mimetype='application/json') -def valid_products(products): - db = DBControl('localhost', 'pinpoint', 'pinpoint', 'product') - db.con_db() - product_list = db.db_select('select product_name, product_price from t_product') - - - if __name__ == '__main__': - app.run(host='0.0.0.0',port=8184,processes=4,threaded=False) + app.run(host='0.0.0.0', port=8184, processes=4, threaded=False) diff --git a/testapps/PY/requirements.txt b/testapps/PY/requirements.txt index 277d2dd32..dbe6c7a53 100644 --- a/testapps/PY/requirements.txt +++ b/testapps/PY/requirements.txt @@ -1,20 +1,5 @@ -pinpointPy -astor -certifi -chardet -click -flask -contextvars -idna -itsdangerous -Jinja2 -MarkupSafe -nose -nose-exclude -public -query-string -requests -urllib3 -Werkzeug -pymysql -redis \ No newline at end of file +Flask==3.0.0 +pinpointPy==1.0.15 +PyMySQL==1.1.0 +redis==5.0.1 +Requests==2.31.0 diff --git a/testapps/PY/templates/index.html b/testapps/PY/templates/index.html index f29178c31..af9129a27 100644 --- a/testapps/PY/templates/index.html +++ b/testapps/PY/templates/index.html @@ -241,6 +241,15 @@

Simple server

+ + + Test Uri Templated + + + click me + + + diff --git a/testapps/PY/test.py b/testapps/PY/test.py new file mode 100644 index 000000000..12ccce43e --- /dev/null +++ b/testapps/PY/test.py @@ -0,0 +1,9 @@ +class Doctor: + def out(self): + print("out") + + +d = Doctor() +d.out() + + diff --git a/testapps/compose.yaml b/testapps/compose.yaml new file mode 100644 index 000000000..fe8d53821 --- /dev/null +++ b/testapps/compose.yaml @@ -0,0 +1,57 @@ +services: + dev-mysql: + image: mysql:5.7 + restart: always + environment: + MYSQL_ROOT_PASSWORD: 'password' + ports: + - '3306:3306' + expose: + - '3306' + dev-mysql-setup: + image: mysql:5.7 + depends_on: + dev-mysql: + condition: service_completed_successfully + # restart: "always" + entrypoint: [ "bash", "-c", "cd /app/ && mysql -uroot -ppassword -hdev-mysql