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

[ci] Scrape and verify metrics at the end of e2e tests #6330

Merged
merged 63 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
9e51b06
script to scrape metrics
chahatsagarmain Dec 9, 2024
cf2ee87
minor change
chahatsagarmain Dec 9, 2024
3472d1e
fix dir path
chahatsagarmain Dec 9, 2024
1c12682
add metric upload to each test and changes in the scrape script
chahatsagarmain Dec 9, 2024
d5ae8f5
minor changes
chahatsagarmain Dec 11, 2024
5170c8e
changes
chahatsagarmain Dec 13, 2024
a3d3252
shell lint
chahatsagarmain Dec 13, 2024
b0ef4d4
minor changes
chahatsagarmain Dec 14, 2024
2244ea9
reviewed changes
chahatsagarmain Dec 15, 2024
283bc5c
added cache save
chahatsagarmain Dec 28, 2024
0152cb2
Merge branch 'main' into e2e-metrics
chahatsagarmain Dec 28, 2024
6adf944
fixes
chahatsagarmain Dec 28, 2024
c6703b6
add schema in key
chahatsagarmain Dec 28, 2024
adbe80f
test ci
chahatsagarmain Dec 28, 2024
d46316b
test ci
chahatsagarmain Dec 29, 2024
0da4dbb
minor changes
chahatsagarmain Dec 29, 2024
a479e7f
test ci with fixed expression
chahatsagarmain Dec 29, 2024
519104e
shared action and a happy new yar
chahatsagarmain Jan 1, 2025
23ba35f
minor fixes
chahatsagarmain Jan 1, 2025
b620f09
shared action
chahatsagarmain Jan 2, 2025
15c775b
Merge branch 'main' into e2e-metrics
chahatsagarmain Jan 2, 2025
07fdbec
add shell property
chahatsagarmain Jan 2, 2025
7f3fe77
compare metrics
chahatsagarmain Jan 3, 2025
8c81c82
fix path
chahatsagarmain Jan 3, 2025
a76bcde
fix compare
chahatsagarmain Jan 3, 2025
2b27c95
minor changes
chahatsagarmain Jan 3, 2025
77ed741
compare metrics using python libraries
chahatsagarmain Jan 4, 2025
22e97a2
check path
chahatsagarmain Jan 4, 2025
8da8a07
resolved comments
chahatsagarmain Jan 4, 2025
90464e2
use simple unified diff
chahatsagarmain Jan 4, 2025
19835c4
exit cases
chahatsagarmain Jan 4, 2025
63a64f3
simplified action
chahatsagarmain Jan 4, 2025
0a1787f
exit case
chahatsagarmain Jan 4, 2025
b30dad5
fetch tags after checkout
chahatsagarmain Jan 4, 2025
d81694e
changes
chahatsagarmain Jan 6, 2025
6f5355c
exit code
chahatsagarmain Jan 6, 2025
1bdb77f
print diff
chahatsagarmain Jan 6, 2025
157822d
minor changes
chahatsagarmain Jan 6, 2025
2ea739b
added comment
chahatsagarmain Jan 7, 2025
20514ab
test
chahatsagarmain Jan 7, 2025
8d92555
fetch depth 0
chahatsagarmain Jan 7, 2025
a7f2b67
changes
chahatsagarmain Jan 7, 2025
1b16c35
Merge branch 'main' into e2e-metrics
chahatsagarmain Jan 7, 2025
ef56c4e
Merge branch 'main' into e2e-metrics
chahatsagarmain Jan 9, 2025
b93d66d
cummulative diff
chahatsagarmain Jan 9, 2025
e51bb3e
Merge branch 'e2e-metrics' of https://github.com/chahatsagarmain/jaeg…
chahatsagarmain Jan 9, 2025
41693c5
minor changes
chahatsagarmain Jan 11, 2025
4ffb260
use restore key
chahatsagarmain Jan 13, 2025
f1dc438
Merge branch 'main' into e2e-metrics
chahatsagarmain Jan 13, 2025
1249fdc
resolved changes
chahatsagarmain Jan 13, 2025
6cb60ef
Merge branch 'e2e-metrics' of https://github.com/chahatsagarmain/jaeg…
chahatsagarmain Jan 13, 2025
98968eb
fix
chahatsagarmain Jan 13, 2025
e43b1e3
fix
chahatsagarmain Jan 13, 2025
af10a81
change save path
chahatsagarmain Jan 14, 2025
5c8dfec
Merge branch 'main' into e2e-metrics
chahatsagarmain Jan 14, 2025
b29098a
fix restore keys
chahatsagarmain Jan 14, 2025
1accdfd
Merge branch 'e2e-metrics' of https://github.com/chahatsagarmain/jaeg…
chahatsagarmain Jan 14, 2025
5e2eac1
minor change in name
chahatsagarmain Jan 15, 2025
b6bd4c0
remove txt
chahatsagarmain Jan 15, 2025
9dad779
minor changes
chahatsagarmain Jan 16, 2025
be73e93
Update .github/workflows/ci-e2e-badger.yaml
yurishkuro Jan 16, 2025
f3b63e9
Update .github/actions/verify-metrics-snapshot/action.yaml
yurishkuro Jan 16, 2025
9d232bb
Merge branch 'main' into e2e-metrics
yurishkuro Jan 16, 2025
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
82 changes: 82 additions & 0 deletions .github/actions/verify-metrics-snapshot/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright (c) 2023 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0


yurishkuro marked this conversation as resolved.
Show resolved Hide resolved

name: 'Verify Metric Snapshot and Upload Metrics'
description: 'Upload or cache the metrics data after verification'
inputs:
snapshot:
description: 'Path to the metric file'
required: true
artifact_key:
description: 'Artifact key used for uploading and fetching artifacts'
required: true
cache_key:
description: 'Cache key used for uploading and fetching the correct cached metric'
required: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cache_key:
description: 'Cache key used for uploading and fetching the correct cached metric'
required: true

runs:
using: 'composite'
steps:
- name: Upload Metrics Artifact
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: ${{ inputs.artifact_key }}
path: ./.metrics/${{ inputs.snapshot }}
retention-days: 7

- name: Get v2 tag
shell: bash
run: |
v2_tag=$(make echo-v2)
echo "v2_tag=$v2_tag" >> $GITHUB_ENV
echo "$v2_tag"
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved

# The github cache restore successfully restores when cache saved has same key and same path.
# Hence to restore release metric with name relese_{metric_name} , the name must be changed to the same.
- name: Change file name before caching
if: github.ref_name == 'main'
shell: bash
run: |
mv ./.metrics/${{ inputs.snapshot }} ./.metrics/release_${{ inputs.snapshot}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changed the meaning of this cache items, it's no longer "release" snapshot. We can call it baseline_*


- name: Cache scraped metrics for tagged release for longer retention
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
id: tagged-metrics
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
if: github.ref_name == 'main'
uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57
with:
path: ./.metrics/release_${{ inputs.snapshot}}
chahatsagarmain marked this conversation as resolved.
Show resolved Hide resolved
key: ${{ env.v2_tag }}_${{ inputs.artifact_key }}_${{ github.run_id }}
restore-keys: |
${{ env.v2_tag }}_${{ inputs.artifact_key }}_
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved


- name: Download the cached tagged metrics
id: download-release-snapshot
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
if: github.ref_name != 'main'
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57
with:
path: ./.metrics/release_${{ inputs.snapshot}}
key: ${{ env.v2_tag }}_${{ inputs.artifact_key }}_${{ github.run_id }}
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved

- name: Calculate diff between the snapshots
id: compare-snapshots
if: ${{ (steps.download-release-snapshot.outputs.cache-hit == 'true') && (github.ref_name != 'main') }}
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
run: |
python3 -m pip install prometheus-client
python3 ./scripts/e2e/compare_metrics.py --file1 ./.metrics/${{ inputs.snapshot }} --file2 ./.metrics/release_${{ inputs.snapshot}} --output ./.metrics/diff_${{ inputs.snapshot }}
if [ $? -eq 1 ]; then
echo "🛑 Differences found in metrics"
exit 1
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
fi

- name: Upload the diff artifact
if: ${{ (github.ref_name != 'main') && (steps.compare-snapshots.outcome == 'failure') }}
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: diff_${{ inputs.artifact_key }}
path: ./.metrics/diff_${{ inputs.snapshot }}
retention-days: 7


4 changes: 0 additions & 4 deletions .github/workflows/ci-e2e-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,3 @@ jobs:
opensearch:
uses: ./.github/workflows/ci-e2e-opensearch.yml





yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 9 additions & 1 deletion .github/workflows/ci-e2e-badger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

with:
fetch-depth: 0

yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: 1.23.x
Expand All @@ -41,6 +43,12 @@ jobs:
;;
esac

- uses: ./.github/actions/verify-metrics-snapshot
if: matrix.version == 'v2'
with:
snapshot: badger_metrics.txt
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
artifact_key: badger-metrics-${{ matrix.version }}.txt
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved

- name: Upload coverage to codecov
uses: ./.github/actions/upload-codecov
with:
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/ci-e2e-cassandra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
fetch-depth: 0

- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
Expand All @@ -48,9 +50,17 @@ jobs:
run: bash scripts/e2e/cassandra.sh ${{ matrix.version.major }} ${{ matrix.version.schema }} ${{ matrix.jaeger-version }}
env:
SKIP_APPLY_SCHEMA: ${{ matrix.create-schema == 'auto' && true || false }}

- uses: ./.github/actions/verify-metrics-snapshot
if: matrix.jaeger-version == 'v2'
with:
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
snapshot: cassandra_metrics.txt
artifact_key: cassandra_metrics_${{ matrix.version.major }}_${{ matrix.version.schema }}_${{ matrix.jaeger-version }}_${{ matrix.create-schema }}.txt

- name: Upload coverage to codecov
uses: ./.github/actions/upload-codecov
with:
files: cover.out
flags: cassandra-${{ matrix.version.major }}-${{ matrix.jaeger-version }}-${{ matrix.create-schema }}


13 changes: 8 additions & 5 deletions .github/workflows/ci-e2e-elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ jobs:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
submodules: true

- name: Fetch git tags
run: |
git fetch --prune --unshallow --tags

fetch-depth: 0

- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: 1.23.x
Expand All @@ -58,6 +55,12 @@ jobs:
- name: Run ${{ matrix.version.distribution }} integration tests
id: test-execution
run: bash scripts/e2e/elasticsearch.sh ${{ matrix.version.distribution }} ${{ matrix.version.major }} ${{ matrix.version.jaeger }}

- uses: ./.github/actions/verify-metrics-snapshot
if: matrix.version.jaeger == 'v2'
with:
snapshot: elasticsearch_metrics.txt
artifact_key: elasticsearch-metrics-${{ matrix.version.major }}_${{ matrix.version.jaeger}}.txt

- name: Upload coverage to codecov
uses: ./.github/actions/upload-codecov
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ci-e2e-grpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
fetch-depth: 0

- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
Expand All @@ -41,6 +43,12 @@ jobs:
;;
esac

- uses: ./.github/actions/verify-metrics-snapshot
if: matrix.version == 'v2'
with:
snapshot: grpc_metrics.txt
artifact_key: grpc-metrics-${{ matrix.version }}.txt

- name: Upload coverage to codecov
uses: ./.github/actions/upload-codecov
with:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ci-e2e-kafka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
fetch-depth: 0

- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
Expand All @@ -35,6 +37,12 @@ jobs:
- name: Run kafka integration tests
id: test-execution
run: bash scripts/e2e/kafka.sh -j ${{ matrix.jaeger-version }} -v ${{ matrix.kafka-version }}

- uses: ./.github/actions/verify-metrics-snapshot
if: matrix.jaeger-version == 'v2'
with:
snapshot: kafka_metrics.txt
artifact_key: kafka-metrics-${{ matrix.jaeger-version }}.txt

- name: Upload coverage to codecov
uses: ./.github/actions/upload-codecov
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/ci-e2e-memory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

with:
fetch-depth: 0

- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: 1.23.x

- name: Run Memory storage integration tests
run: |
STORAGE=memory_v2 make jaeger-v2-storage-integration-test


- uses: ./.github/actions/verify-metrics-snapshot
with:
snapshot: memory_metrics.txt
artifact_key: memory-metrics.txt

- name: Upload coverage to codecov
uses: ./.github/actions/upload-codecov
with:
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/ci-e2e-opensearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ jobs:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
submodules: true

- name: Fetch git tags
run: |
git fetch --prune --unshallow --tags
fetch-depth: 0

- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
Expand All @@ -52,6 +49,12 @@ jobs:
id: test-execution
run: bash scripts/e2e/elasticsearch.sh ${{ matrix.version.distribution }} ${{ matrix.version.major }} ${{ matrix.version.jaeger }}

- uses: ./.github/actions/verify-metrics-snapshot
if: matrix.version.jaeger == 'v2'
with:
snapshot: opensearch_metrics.txt
artifact_key: opensearch-metrics-${{ matrix.version.major }}.txt

- name: Upload coverage to codecov
uses: ./.github/actions/upload-codecov
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ sha256sum.combined.txt
resource.syso
.gocache
test-results.json
.metrics/
21 changes: 21 additions & 0 deletions cmd/jaeger/internal/integration/e2e_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,32 @@ func (s *E2EStorageIntegration) e2eInitialize(t *testing.T, storage string) {
require.NoError(t, err)

t.Cleanup(func() {
scrapeMetrics(t, storage)
require.NoError(t, s.TraceReader.(io.Closer).Close())
require.NoError(t, s.TraceWriter.(io.Closer).Close())
})
}

func scrapeMetrics(t *testing.T, storage string) {
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://localhost:8888/metrics", nil)
chahatsagarmain marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)

client := &http.Client{}
resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()

outputDir := "../../../../.metrics"
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, os.MkdirAll(outputDir, os.ModePerm))

metricsFile, err := os.Create(fmt.Sprintf("%s/%v_metrics.txt", outputDir, storage))
require.NoError(t, err)
defer metricsFile.Close()

_, err = io.Copy(metricsFile, resp.Body)
require.NoError(t, err)
}

func createStorageCleanerConfig(t *testing.T, configFile string, storage string) string {
data, err := os.ReadFile(configFile)
require.NoError(t, err)
Expand Down
77 changes: 77 additions & 0 deletions scripts/e2e/compare_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (c) 2024 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0

import argparse
from difflib import unified_diff
from bisect import insort
from prometheus_client.parser import text_string_to_metric_families

def read_metric_file(file_path):
with open(file_path, 'r') as f:
return f.readlines()

def parse_metrics(content):
metrics = []
for family in text_string_to_metric_families(content):
for sample in family.samples:
labels = dict(sample.labels)
#simply pop undesirable metric labels
labels.pop('service_instance_id',None)
label_pairs = sorted(labels.items(), key=lambda x: x[0])
label_str = ','.join(f'{k}="{v}"' for k,v in label_pairs)
metric = f"{family.name}{{{label_str}}}"
insort(metrics , metric)

return metrics


def generate_diff(file1_content, file2_content):
if isinstance(file1_content, list):
file1_content = ''.join(file1_content)
if isinstance(file2_content, list):
file2_content = ''.join(file2_content)

metrics1 = parse_metrics(file1_content)
metrics2 = parse_metrics(file2_content)

diff = unified_diff(metrics1, metrics2,lineterm='',n=0)

return '\n'.join(diff)

def write_diff_file(diff_lines, output_path):

with open(output_path, 'w') as f:
f.write(diff_lines)
f.write('\n') # Add final newline
print(f"Diff file successfully written to: {output_path}")

def main():
parser = argparse.ArgumentParser(description='Generate diff between two Jaeger metric files')
parser.add_argument('--file1', help='Path to first metric file')
parser.add_argument('--file2', help='Path to second metric file')
parser.add_argument('--output', '-o', default='metrics_diff.txt',
help='Output diff file path (default: metrics_diff.txt)')

args = parser.parse_args()

# Read input files
file1_lines = read_metric_file(args.file1)
file2_lines = read_metric_file(args.file2)

# Generate diff
diff_lines = generate_diff(file1_lines, file2_lines)

# Check if there are any differences
if diff_lines:
print("differences found between the metric files.")
print("=== Metrics Comparison Results ===")
print(diff_lines)
write_diff_file(diff_lines, args.output)

return 1

print("no difference found")
return 0

if __name__ == '__main__':
main()
Loading