Skip to content

Commit

Permalink
Merge branch 'main' into feature/gofiber-trace-propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
dianashevchenko committed Nov 21, 2022
2 parents 8555f99 + 9b50352 commit 39b6003
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
stages:
- benchmarks

include: ".gitlab/benchmarks.yml"
28 changes: 28 additions & 0 deletions .gitlab/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
variables:
# This base image is created here: https://gitlab.ddbuild.io/DataDog/apm-reliability/relenv-microbenchmarking-platform
BASE_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/relenv-microbenchmarking-platform:dd-trace-go_knusbaum_test
INDEX_FILE: index.txt

benchmark:
stage: benchmarks
image: $BASE_CI_IMAGE
timeout: 1h
only:
refs:
- branches
interruptible: true
tags: ["runner:apm-k8s-tweaked-metal"]
script:
- ./.gitlab/scripts/capture-hardware-software-info.sh
- ./.gitlab/scripts/run-benchmarks.sh
# - ./.gitlab/scripts/upload-results-to-s3.sh #commented out until we have merged our permissions changes
- ./.gitlab/scripts/analyze-results.sh
- ./.gitlab/scripts/post-pr-comment.sh
artifacts:
name: "reports"
paths:
- reports/
expire_in: 3 months
variables:
KUBERNETES_SERVICE_ACCOUNT_OVERWRITE: dd-trace-go
FF_USE_LEGACY_KUBERNETES_EXECUTION_STRATEGY: "true"
26 changes: 26 additions & 0 deletions .gitlab/scripts/analyze-results.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

ARTIFACTS_DIR="/artifacts/${CI_JOB_ID}"
REPORTS_DIR="$(pwd)/reports/"
mkdir "${REPORTS_DIR}" || :

BASELINE_BRANCH=$(github-find-merge-into-branch --for-repo="$CI_PROJECT_NAME" --for-pr="$CI_COMMIT_REF_NAME" || :)

source /benchmark-analyzer/.venv/bin/activate
cd /benchmark-analyzer

./benchmark_analyzer convert \
--framework=GoBench \
--outpath="pr.json" \
--extra-params="{\"dd_trace_go\":\"${CI_COMMIT_REF_NAME}\"}" \
"${ARTIFACTS_DIR}/pr_bench.txt"

./benchmark_analyzer convert \
--framework=GoBench \
--outpath="main.json" \
--extra-params="{\"dd_trace_go\":\"main\"}" \
"${ARTIFACTS_DIR}/main_bench.txt"

./benchmark_analyzer compare pairwise --outpath ${REPORTS_DIR}/report.md --format md-nodejs main.json pr.json
./benchmark_analyzer compare pairwise --outpath ${REPORTS_DIR}/report_full.html --format html main.json pr.json

27 changes: 27 additions & 0 deletions .gitlab/scripts/capture-hardware-software-info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

REPORTS_DIR="$(pwd)/reports/"
mkdir "${REPORTS_DIR}" || :

ARTIFACTS_DIR="/artifacts/${CI_JOB_ID}"
mkdir -p "${ARTIFACTS_DIR}" && cd "${ARTIFACTS_DIR}"

# Collect software information

(which top && top -b -n 1 > top.txt) || :
(which uname && uname -a > uname.txt) || :
(which ldconfig && ldconfig -v > ldconfig.txt) || :
(which sysctl && sysctl -a > sysctl.txt) || :

# Collect hardware information

(which lscpu && lscpu -e > lscpu-e.txt) || :
(which lscpu && lscpu > lscpu.txt) || :
(which hwinfo && hwinfo --short > hwinfo-short.txt) || :
(which hwinfo && hwinfo > hwinfo-full.txt) || :
#cpupower frequency-info > cpupower-frequency-info.txt
#turbostat -n 1 > turbostat.txt

# Save all collected information to Gitlab reports as well

cp * "${REPORTS_DIR}"
5 changes: 5 additions & 0 deletions .gitlab/scripts/post-pr-comment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

REPORTS_DIR="$(pwd)/reports/"

cat ${REPORTS_DIR}/report.md | /usr/local/bin/pr-commenter --for-repo="$CI_PROJECT_NAME" --for-pr="$CI_COMMIT_REF_NAME" --header="Benchmarks"
12 changes: 12 additions & 0 deletions .gitlab/scripts/run-benchmarks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

ARTIFACTS_DIR="/artifacts/${CI_JOB_ID}"
mkdir -p "${ARTIFACTS_DIR}"

git clone --branch ${CI_COMMIT_REF_NAME} https://github.com/DataDog/dd-trace-go

cd dd-trace-go/ddtrace/tracer/
go test -run=XXX -bench "BenchmarkConcurrentTracing|BenchmarkStartSpan" -benchmem -count 10 -benchtime 2s ./... | tee ${ARTIFACTS_DIR}/pr_bench.txt

git checkout main
go test -run=XXX -bench "BenchmarkConcurrentTracing|BenchmarkStartSpan" -benchmem -count 10 -benchtime 2s ./... | tee ${ARTIFACTS_DIR}/main_bench.txt
8 changes: 8 additions & 0 deletions .gitlab/scripts/upload-results-to-s3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

PROJECT="${CI_PROJECT_NAME:-$CI_PROJECT_NAME}"
BRANCH="${CI_COMMIT_REF_NAME:-$CI_COMMIT_REF_NAME}"

S3_URL=s3://relenv-benchmarking-data/${PROJECT}/${BRANCH}/${CI_JOB_ID}/

aws s3 cp --recursive --acl bucket-owner-full-control /artifacts/${CI_JOB_ID}/ $S3_URL
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ git update-index --no-assume-unchanged go.*
### Milestones

The maintainers of this repository assign milestones to pull requests to classify them. `Triage` indicates that it is yet to be decided which version the change will go into. Pull requests that are ready get the upcoming release version assigned.

### Benchmarks

Some benchmarks will run on any new PR commits, the results will be commented into the PR on completion. To see the list of benchmarks or to add additional benchmarks run go to `.gitlab/scripts/run-benchmarks.sh`.
23 changes: 15 additions & 8 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1704,14 +1704,20 @@ func BenchmarkConcurrentTracing(b *testing.B) {

b.ResetTimer()
for n := 0; n < b.N; n++ {
go func() {
parent := tracer.StartSpan("pylons.request", ServiceName("pylons"), ResourceName("/"))
defer parent.Finish()

for i := 0; i < 10; i++ {
tracer.StartSpan("redis.command", ChildOf(parent.Context())).Finish()
}
}()
wg := sync.WaitGroup{}
for i := 0; i < 100; i++ {
wg.Add(1)
go func() {
defer wg.Done()
parent := tracer.StartSpan("pylons.request", ServiceName("pylons"), ResourceName("/"))
defer parent.Finish()

for i := 0; i < 10; i++ {
tracer.StartSpan("redis.command", ChildOf(parent.Context())).Finish()
}
}()
}
wg.Wait()
}
}

Expand All @@ -1730,6 +1736,7 @@ func BenchmarkTracerAddSpans(b *testing.B) {
func BenchmarkStartSpan(b *testing.B) {
tracer, _, _, stop := startTestTracer(b, WithLogger(log.DiscardLogger{}), WithSampler(NewRateSampler(0)))
defer stop()

root := tracer.StartSpan("pylons.request", ServiceName("pylons"), ResourceName("/"))
ctx := ContextWithSpan(context.TODO(), root)

Expand Down
1 change: 1 addition & 0 deletions profiler/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type profileType struct {
// profileTypes maps every ProfileType to its implementation.
var profileTypes = map[ProfileType]profileType{
CPUProfile: {
Name: "cpu",
Filename: "cpu.pprof",
Collect: func(p *profiler) ([]byte, error) {
var buf bytes.Buffer
Expand Down
4 changes: 2 additions & 2 deletions profiler/profiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func TestStart(t *testing.T) {
// that we log some default configuration, e.g. enabled profiles
assert.LessOrEqual(t, 1, len(rl.Logs()))
startupLog := strings.Join(rl.Logs(), " ")
assert.Contains(t, startupLog, "cpu")
assert.Contains(t, startupLog, "heap")
assert.Contains(t, startupLog, "\"cpu\"")
assert.Contains(t, startupLog, "\"heap\"")

mu.Lock()
require.NotNil(t, activeProfiler)
Expand Down

0 comments on commit 39b6003

Please sign in to comment.