Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: simplify e2e test script #133

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Run clang-format
run: find ./ -iname "*.h" -o -iname "*.cc" | xargs ./run-clang-format/run-clang-format.py

test:
unit-test:
runs-on: ubuntu-20.04
steps:
- run: |
Expand Down Expand Up @@ -56,38 +56,18 @@ jobs:
- name: Run coverage test
run: |
./coverage.sh
- name: upload coverage data to codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
files: ./coverage_report/coverage.dat
name: codecov-cpp2sky
verbose: true

e2e-cpp:
e2e-test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Prepare service container
run: |
docker compose -f test/e2e/docker/docker-compose.e2e.yml up -d
docker compose -f test/e2e/docker/docker-compose.yml up -d
- name: Run e2e
run: |
sleep 10
pip3 install --upgrade pip
pip3 install setuptools
pip3 install -r test/e2e/requirements.txt
python3 test/e2e/main.py --expected_file=test/e2e/data/expected.yaml --max_retry_times=3 --target_path=/ping

e2e-python:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Prepare service container
run: |
docker compose -f test/e2e/docker/docker-compose.e2e-python.yml up -d
- name: Run e2e
run: |
pip3 install --upgrade pip
pip3 install setuptools
pip3 install -r test/e2e/requirements.txt
python3 test/e2e/main.py --expected_file=test/e2e/data/expected-python.yaml --max_retry_times=3 --target_path=/ping2
python3 test/e2e/main.py --expected_file=test/e2e/data/all_expected.yaml --max_retry_times=3
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# cpp2sky

![cpp2sky test](https://github.com/SkyAPM/cpp2sky/workflows/cpp2sky%20test/badge.svg)
![codecov test](https://codecov.io/gh/SkyAPM/cpp2sky/branch/main/graph/badge.svg)

Distributed tracing and monitor SDK in CPP for Apache SkyWalking APM. This SDK is compatible with C++ 17, C++ 14, and C++ 11.

Expand Down
7 changes: 2 additions & 5 deletions test/e2e/data/interm.py → test/e2e/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
from skywalking.decorators import runnable

if __name__ == '__main__':
config.init(collector='collector:19876', service='interm')
config.logging_level = 'DEBUG'

config.flask_collect_http_params = True
config.init()
agent.start()

from flask import Flask, Response
Expand All @@ -16,7 +13,7 @@

@app.route("/users", methods=["POST", "GET"])
def application():
res = requests.get("http://consumer:8080/pong")
res = requests.get("http://provider:8081/pong2")
return Response(status=res.status_code)

PORT = 8082
Expand Down
48 changes: 43 additions & 5 deletions test/e2e/consumer.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Copyright 2020 SkyAPM

// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -37,11 +36,50 @@ int main() {
httplib::Server svr;
auto tracer = createInsecureGrpcTracer(config);

svr.Get("/pong", [&](const httplib::Request& req, httplib::Response& res) {
auto parent = req.get_header_value(kPropagationHeader.data());
auto tracing_context = tracer->newContext(createSpanContext(parent));
// C++
svr.Get("/ping", [&](const httplib::Request& req, httplib::Response& res) {
auto tracing_context = tracer->newContext();

{
StartEntrySpan entry_span(tracing_context, "/ping");

{
std::string target_address = "provider:8081";

StartExitSpan exit_span(tracing_context, entry_span.get(), "/pong");
exit_span.get()->setPeer(target_address);

httplib::Client cli("provider", 8081);
httplib::Headers headers = {
{kPropagationHeader.data(),
*tracing_context->createSW8HeaderValue(target_address)}};
auto res = cli.Get("/pong", headers);
}
}

tracer->report(std::move(tracing_context));
});

// Python
svr.Get("/ping2", [&](const httplib::Request& req, httplib::Response& res) {
auto tracing_context = tracer->newContext();

{
StartEntrySpan entry_span(tracing_context, "/ping2");

{
std::string target_address = "bridge:8082";

StartExitSpan exit_span(tracing_context, entry_span.get(), "/users");
exit_span.get()->setPeer(target_address);

{ StartEntrySpan entry_span(tracing_context, "/pong"); }
httplib::Client cli("bridge", 8082);
httplib::Headers headers = {
{kPropagationHeader.data(),
*tracing_context->createSW8HeaderValue(target_address)}};
auto res = cli.Get("/users", headers);
}
}

tracer->report(std::move(tracing_context));
});
Expand Down
154 changes: 154 additions & 0 deletions test/e2e/data/all_expected.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
segmentItems:
- segmentSize: 2
segments:
# Segment from provider in [consumer -> provider] case.
- segmentId: not null
spans:
- componentId: 9000
endTime: gt 0
isError: false
operationName: /pong
parentSpanId: -1
peer: ''
refs:
- networkAddress: provider:8081
parentEndpoint: /ping
parentService: consumer
parentServiceInstance: node_0
parentSpanId: 1
parentTraceSegmentId: not null
refType: CrossProcess
traceId: not null
skipAnalysis: false
spanId: 0
spanLayer: Http
spanType: Entry
startTime: gt 0
# Segment from provider in [consumer -> bridge -> provider] case.
- segmentId: not null
spans:
- componentId: 9000
endTime: gt 0
isError: false
operationName: /pong2
parentSpanId: -1
peer: ''
refs:
- networkAddress: provider:8081
parentEndpoint: /pong2
parentService: bridge
parentServiceInstance: not null
parentSpanId: 1
parentTraceSegmentId: not null
refType: CrossProcess
traceId: not null
skipAnalysis: false
spanId: 0
spanLayer: Http
spanType: Entry
startTime: gt 0
serviceName: provider
- segmentSize: 1
segments:
# Segment from bridge in [consumer -> bridge -> provider] case.
- segmentId: not null
spans:
- componentId: 7002
endTime: gt 0
isError: false
operationName: /pong2
parentSpanId: 0
peer: provider:8081
skipAnalysis: false
spanId: 1
spanLayer: Http
spanType: Exit
startTime: gt 0
tags:
- key: http.method
value: GET
- key: http.url
value: http://provider:8081/pong2
- key: http.status_code
value: '200'
- componentId: 7001
endTime: gt 0
isError: false
operationName: /users
parentSpanId: -1
peer: not null
refs:
- networkAddress: bridge:8082
parentEndpoint: /ping2
parentService: consumer
parentServiceInstance: node_0
parentSpanId: 1
parentTraceSegmentId: not null
refType: CrossProcess
traceId: not null
skipAnalysis: false
spanId: 0
spanLayer: Http
spanType: Entry
startTime: gt 0
tags:
- key: http.method
value: GET
- key: http.url
value: http://bridge:8082/users
- key: http.status_code
value: '200'
serviceName: bridge
- segmentSize: 2
segments:
# Segment from consumer [consumer -> provider] case.
- segmentId: not null
spans:
- componentId: 9000
endTime: gt 0
isError: false
operationName: /ping
parentSpanId: -1
peer: ''
skipAnalysis: false
spanId: 0
spanLayer: Http
spanType: Entry
startTime: gt 0
- componentId: 9000
endTime: gt 0
isError: false
operationName: /pong
parentSpanId: 0
peer: provider:8081
skipAnalysis: false
spanId: 1
spanLayer: Http
spanType: Exit
startTime: gt 0
# Segment from consumer [consumer -> bridge -> provider] case.
- segmentId: not null
spans:
- componentId: 9000
endTime: gt 0
isError: false
operationName: /ping2
parentSpanId: -1
peer: ''
skipAnalysis: false
spanId: 0
spanLayer: Http
spanType: Entry
startTime: gt 0
- componentId: 9000
endTime: gt 0
isError: false
operationName: /users
parentSpanId: 0
peer: bridge:8082
skipAnalysis: false
spanId: 1
spanLayer: Http
spanType: Exit
startTime: gt 0
serviceName: consumer
102 changes: 0 additions & 102 deletions test/e2e/data/expected-python.yaml

This file was deleted.

Loading
Loading