-
Notifications
You must be signed in to change notification settings - Fork 1
/
telemetry_test.py
133 lines (111 loc) · 3.78 KB
/
telemetry_test.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import pandas as pd
import numpy as np
import pytest
from . import telemetry as t
@pytest.fixture(scope="module", autouse=True)
def dont_show_figs():
"""We do not want to show the figures in test mode"""
t.auto_show_plots = True
def test_compute_proper():
df = pd.DataFrame([
{
"groupfield": np.nan,
"duration_ms": 32,
"span_id": "A",
},
{
"groupfield": "datastore",
"duration_ms": 14,
"span_id": "B",
"parent_span_id": "A",
},
{
"groupfield": np.nan,
"duration_ms": 13 ,
"span_id": "C",
"parent_span_id": "A",
},
{
"groupfield": "cache",
"duration_ms": 6,
"span_id": "D",
"parent_span_id": "B",
},
{
"groupfield": "google",
"duration_ms": 4,
"span_id": "E",
"parent_span_id": "B",
},
{
"groupfield": "datastore",
"duration_ms": 6,
"span_id": "F",
"parent_span_id": "C",
},
{
"groupfield": "cache",
"duration_ms": 2,
"span_id": "G",
"parent_span_id": "F",
},
{
"groupfield": "google",
"duration_ms": 2,
"span_id": "H",
"parent_span_id": "F",
},
{
"groupfield": "other",
"duration_ms": 3,
"span_id": "I",
"parent_span_id": "C",
},
])
out = t.compute_proper_durations_by_field(df, "groupfield", "myproper_duration", "myspan_depth")
assert out.myspan_depth.tolist() == [0, 1, 1, 2, 2, 2, 3, 3, 2]
assert out.myproper_duration.tolist() == [9, 4, 4, 6, 4, 2, 2, 2, 3]
def test_plot_durations():
df = pd.DataFrame([
{
"groupfield": np.nan,
"start_time": "2023-2-1T00:00",
"duration_ms": 32,
"span_id": "A",
},
{
"groupfield": "datastore",
"start_time": "2023-2-1T00:06",
"duration_ms": 14,
"span_id": "B",
"parent_span_id": "A",
},
{
"groupfield": np.nan,
"duration_ms": 13 ,
"start_time": "2023-2-1T00:11",
"span_id": "C",
"parent_span_id": "A",
},
])
df["trace_id"] = "traceid_abc"
df["start_time"] = pd.to_datetime(df["start_time"])
df["root_start_time"] = df["start_time"]
mask = t.Mask(lambda x: pd.Series(True, index=x.index), "ALL")
t.plot_durations(df, mask)
def test_plot_durations_colored():
df = pd.read_json("real_test_data/extended.json", orient="table")
mask = t.Mask(lambda x: pd.Series(True, index=x.index), "ALL")
t.plot_durations(df, mask, sample_rate="1H", color="method")
def test_plot_durations_extended():
df = pd.read_json("real_test_data/extended.json", orient="table")
mask = t.Mask(lambda x: pd.Series(True, index=x.index), "ALL")
t.plot_durations(df, mask, y="proper_ms", sample_rate="1H", color="span_thirdparty", display_trace_rest=True)
def test_plot_durations_extended_full():
df = pd.read_parquet("real_test_data/extended_full.parquet.gzip")
mask = t.Mask(lambda x: pd.Series(True, index=x.index), "ALL")
t.plot_durations(df, mask, y="proper_ms", sample_rate="1H", color="span_thirdparty", display_trace_rest=True)
def test_plot_durations_extended_full_norest():
df = pd.read_parquet("real_test_data/extended_full.parquet.gzip")
mask = t.Mask(lambda x: pd.Series(True, index=x.index), "ALL")
t.plot_durations(df, mask, y="proper_ms", sample_rate="1H", color="span_thirdparty", display_trace_rest=False)