Skip to content

refactor: unify the ObjectRef and GroupingKey types #267

refactor: unify the ObjectRef and GroupingKey types

refactor: unify the ObjectRef and GroupingKey types #267

Workflow file for this run

name: Build artifacts
on:
push:
pull_request:
workflow_dispatch:
permissions:
contents: read
packages: write
pages: write
id-token: write
jobs:
compile-binary:
name: Build executable
runs-on: [ubuntu-20.04]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.20'
- name: Compile executable
run: make output/kelemetry
- name: Upload executable
uses: actions/upload-artifact@v3
with:
name: kelemetry-linux-amd64
path: output/kelemetry
dot-usage:
name: Generate dependency graph and usage file
runs-on: [ubuntu-20.04]
needs: [compile-binary]
steps:
- name: Install graphviz
run: sudo apt-get install -y graphviz
- uses: actions/checkout@v3
- name: Download executable
uses: actions/download-artifact@v3
with:
name: kelemetry-linux-amd64
path: output
- run: chmod +x output/kelemetry
- name: Re-generate USAGE.txt
run: make usage
- name: Generate depgraph
run: make dot
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: dot-usage
path: |
depgraph.*
USAGE.txt
build-docker:
name: Build docker image for quickstart
runs-on: [ubuntu-20.04]
steps:
- uses: actions/checkout@v3
- name: Build docker image
run: docker build -t kelemetry:ci .
- name: Export docker image to file
run: mkdir output && docker save -o output/kelemetry-ci.tar kelemetry:ci
- name: Upload docker image artifact
uses: actions/upload-artifact@v3
with:
name: ci-docker-image
path: output/kelemetry-ci.tar
demo-traces:
name: Generate demo traces
runs-on: [ubuntu-20.04]
needs: [build-docker]
strategy:
matrix:
scripts:
- |
cat <<EOF >>"$GITHUB_OUTPUT"
TRACE_NAME=deployment
CURL_PARAMS=--data-urlencode cluster=tracetest --data-urlencode resource=deployments --data-urlencode namespace=default --data-urlencode name=demo
EOF
kubectl create deployment demo --image=alpine:3.16 --replicas=2 -- sleep infinity
sleep 5
kubectl scale deployment demo --replicas=4
sleep 5
kubectl set image deployments demo alpine=alpine:3.17
sleep 5
kubectl scale deployment demo --replicas=2
sleep 5
kubectl delete deployment demo
sleep 30
steps:
- uses: actions/checkout@v3
- name: Install kind
run: wget -O kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-linux-amd64 && chmod +x kind && sudo mv kind /usr/local/bin/kind
- name: Start test cluster
run: make kind
- name: Download docker image
uses: actions/download-artifact@v3
with:
name: ci-docker-image
path: local
- name: Load docker image
run: docker load -i local/kelemetry-ci.tar
- name: Start quickstart setup
run: make quickstart KELEMETRY_IMAGE=kelemetry:ci
- name: Install kubectl
run: |
wget -O kubectl https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && \
chmod +x kubectl && \
sudo mv kubectl /usr/local/bin/kubectl
- name: Trigger test trace
id: script
run: echo "${{matrix.scripts}}" | bash
- name: Kelemetry process logs
run: make quickstart KELEMETRY_IMAGE=kelemetry:ci COMPOSE_COMMAND="logs kelemetry"
- name: Invoke jaeger-query
id: curl-jaeger-query
run: |
set -x
set -o pipefail
curl -i -G \
--data-urlencode ts="$(date --iso-8601=seconds)" \
${{steps.script.outputs.CURL_PARAMS}} \
localhost:8080/redirect >curl-output.http
TRACE_ID=$(grep "Location: /trace/" curl-output.http | cut -d/ -f3 | tr -d '\r')
mkdir -p output/api/traces
for mode in ff{0,1,2,3}{0,1}00000{0,1}; do
mode_trace=${mode}${TRACE_ID:10}
curl -o output/api/traces/$mode_trace http://localhost:16686/api/traces/$mode_trace
done
echo ${{steps.script.outputs.TRACE_NAME}} >output/trace_name
echo ${TRACE_ID:10} >output/trace_id
- name: Upload trace output
uses: actions/upload-artifact@v3
with:
name: trace-${{steps.script.outputs.TRACE_NAME}}
path: output
build-github-pages:
name: Build GitHub Pages
runs-on: [ubuntu-20.04]
needs: [compile-binary, dot-usage, demo-traces]
steps:
- uses: actions/download-artifact@v3
with:
path: output
- name: Download Jaeger UI
run: |
rm -r output/ci-docker-image # too large and not relevant
mkdir -p local/jaeger-ui
wget -O - https://github.com/jaegertracing/jaeger-ui/releases/download/v1.28.1/assets.tar.gz | tar xzv -C local/jaeger-ui
mv local/jaeger-ui/packages/jaeger-ui/build/static output/static
sed 's#<base href="/"#<base href="/kelemetry/"#g' local/jaeger-ui/packages/jaeger-ui/build/index.html >spa.html
mkdir -p output/api/traces
for trace_dir in output/trace-*; do
basename=$(basename $trace_dir)
cat <<EOF >$trace_dir/index.html
<html>
<head>
<title>Redirecting to ${basename}</title>
<meta http-equiv="refresh" content="0;URL='/kelemetry/trace/ff20000000$(cat $trace_dir/trace_id)'" />
</head>
</html>
EOF
mkdir -p output/trace/ff20000000$(cat $trace_dir/trace_id)
cp spa.html output/trace/ff20000000$(cat $trace_dir/trace_id)/index.html
cp $trace_dir/api/traces/* output/api/traces/
done
mv output/dot-usage/* output/
- run: |
cat <<EOF >output/index.html
<html>
<head>
<title>Kelemetry</title>
<base href="/kelemetry/" />
</head>
<body>
<h1>Kelemetry</h1>
<p>Check repo on <a href="https://github.com/kubewharf/kelemetry">GitHub</a>.
<h2>Artifacts</h2>
<p>
This site hosts artifacts built from the latest development version of Kelemetry, including:
</p>
<ul>
<li><a href="kelemetry-linux-amd64/kelemetry">Executable binary (Linux, amd64)</a></li>
<li><a href="USAGE.txt">Executable options</a></li>
<li><a href="depgraph.png">Internal dependency graph</a></li>
</ul>
<h2>Previews</h2>
<p>
This site hosts a few demo traces from Kelemetry rendered on <a href="https://github.com/kubewharf/kelemetry/actions">GitHub CI</a>.
This preview contains assets from <a href="https://github.com/jaegertracing/jaeger-ui">Jaeger UI</a>,
which is distributed under <a href="https://github.com/jaegertracing/jaeger-ui/raw/main/LICENSE">Apache License 2.0</a>.
Part of the Jaeger UI assets may have been modified to facilitate serving on GitHub Pages.
</p>
<ul>
EOF
for trace_dir in output/trace-*; do
basename=$(basename $trace_dir)
cat <<EOF >>output/index.html
<li><a href="$basename/">$(cat $trace_dir/trace_name)</a></li>
EOF
done
cat <<EOF >>output/index.html
</ul>
</body>
</html>
EOF
- name: Upload pages artifact
uses: actions/upload-pages-artifact@v1
with:
path: output
take-screenshot:
name: Take screenshot
runs-on: [ubuntu-20.04]
needs: [build-github-pages]
steps:
- uses: actions/download-artifact@v3
with:
name: github-pages
path: pages-artifact
- name: Extract pages artifact
run: mkdir pages && tar xf pages-artifact/artifact.tar -C pages
- name: Start static HTTP server in background
run: docker run -d -v $PWD/pages:/var/www/html/kelemetry -p 5000:5000 busybox httpd -f -p 0.0.0.0:5000 -h /var/www/html
- run: npm install puppeteer
- name: Take screenshots
run: |
node <<'EOF'
const pt = require("puppeteer")
const fs = require("fs/promises")
;(async () => {
const browser = await pt.launch({headless: "new"})
const traces = await fs.readdir("pages")
console.log("traces:", traces)
await fs.mkdir("pages/screenshots")
const promises = []
for(const trace of traces) {
if(!trace.startsWith("trace-")) continue
promises.push((async () => {
const traceName = await fs.readFile(`pages/${trace}/trace_name`, {encoding: "utf8"})
const partialTraceId = await fs.readFile(`pages/${trace}/trace_id`, {encoding: "utf8"})
const traceId = "ff20000000" + partialTraceId
console.log(`Loading trace ${traceName}`)
const page = await browser.newPage()
await page.goto(`http://localhost:5000/kelemetry/trace/${traceId}/`)
await page.setViewport({width: 1920, height: 1080})
console.log("waiting for service element")
await page.waitForSelector(".span-svc-name")
const services = await page.$$(".span-svc-name")
await services[5].click()
console.log("waiting for log header element")
const logHeader = await page.waitForSelector(".AccordianLogs--header")
await logHeader.click()
await new Promise(resolve => setTimeout(resolve, 1000))
console.log("dump screenshot")
await page.screenshot({path: `pages/screenshots/${traceName.trim()}.png`})
})())
}
console.log("waiting", promises)
await Promise.all(promises)
await browser.close()
console.log("ok")
})()
EOF
- name: Upload screenshots as artifacts
uses: actions/upload-artifact@v3
with:
name: screenshots
path: pages/screenshots
deploy-github-pages:
name: Deploy GitHub Pages
runs-on: [ubuntu-20.04]
needs: [build-github-pages]
if: github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'ci-test')
concurrency:
group: gh-pages
steps:
- uses: actions/deploy-pages@v2
id: deployment
publish-image:
name: Publish docker image
runs-on: [ubuntu-20.04]
needs: [build-docker]
concurrency:
group: ${{github.ref_type}}-${{github.ref}}
cancel-in-progress: true
if: github.event_name == 'push' && (github.ref_type == 'tag' || (github.ref_type == 'branch' && github.ref_name == 'main'))
steps:
- name: Download docker image
uses: actions/download-artifact@v3
with:
name: ci-docker-image
path: local
- name: Load docker image
run: docker load -i local/kelemetry-ci.tar
- name: Determine image tag for release
id: tag-name
run: |
if [[ ${{github.ref_type}} == tag ]]; then
echo "IMAGE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
else
echo "IMAGE_TAG=dev" >> $GITHUB_OUTPUT
fi
- name: Re-tag docker image
run: docker tag kelemetry:ci ghcr.io/kubewharf/kelemetry:${{steps.tag-name.outputs.IMAGE_TAG}}
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- run: docker push ghcr.io/kubewharf/kelemetry:${{steps.tag-name.outputs.IMAGE_TAG}}