-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathset_data_cardinality.py
More file actions
executable file
·90 lines (72 loc) · 2.8 KB
/
Copy pathset_data_cardinality.py
File metadata and controls
executable file
·90 lines (72 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
"""Script to set the data cardinality for fake exporters in the quickstart demo."""
import argparse
import re
import sys
def update_docker_compose(
file_path: str, num_labels: int, num_values_per_label: int
) -> None:
"""Update docker-compose.yml with the specified cardinality settings."""
with open(file_path, "r") as f:
content = f.read()
# Replace all --num-labels=N occurrences
content, num_labels_count = re.subn(
r'("--num-labels=)\d+(")',
rf"\g<1>{num_labels}\g<2>",
content,
)
# Replace all --num-values-per-label=N[,N,...] occurrences
# Build comma-separated value string matching the number of labels
values_str = ",".join([str(num_values_per_label)] * num_labels)
content, num_values_count = re.subn(
r'("--num-values-per-label=)[\d,]+(")',
rf"\g<1>{values_str}\g<2>",
content,
)
if num_labels_count == 0 or num_values_count == 0:
print("ERROR: Could not find exporter configuration in docker-compose.yml")
sys.exit(1)
with open(file_path, "w") as f:
f.write(content)
total_cardinality = num_values_per_label**num_labels
print("Updated docker-compose.yml:")
print(f" --num-labels={num_labels}")
print(f" --num-values-per-label={num_values_per_label}")
print(f" Cardinality per exporter: {total_cardinality:,}")
def main():
parser = argparse.ArgumentParser(
description="Set the data cardinality for fake exporters in the quickstart demo"
)
parser.add_argument(
"num_labels",
type=int,
help="Number of label dimensions (e.g., 3)",
)
parser.add_argument(
"num_values_per_label",
type=int,
help="Number of unique values per label (e.g., 20)",
)
parser.add_argument(
"--docker-compose",
default="docker-compose.yml",
help="Path to docker-compose.yml (default: docker-compose.yml)",
)
args = parser.parse_args()
if args.num_labels < 1 or args.num_labels > 10:
print("ERROR: Number of labels must be between 1 and 10")
sys.exit(1)
if args.num_values_per_label < 1 or args.num_values_per_label > 1000:
print("ERROR: Number of values per label must be between 1 and 1000")
sys.exit(1)
total_cardinality = args.num_values_per_label**args.num_labels
print("\nConfiguring fake exporters with cardinality settings...")
print(f" Labels: {args.num_labels}")
print(f" Values per label: {args.num_values_per_label}")
print(f" Total cardinality per exporter: {total_cardinality:,}\n")
update_docker_compose(
args.docker_compose, args.num_labels, args.num_values_per_label
)
print("\nSuccessfully updated exporter cardinality settings!")
if __name__ == "__main__":
main()