Skip to content

Commit 2cd8462

Browse files
adding maxQueryCommentMetadata to Class struct
1 parent 49bed63 commit 2cd8462

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

class.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ type Class struct {
2121
UniqueQueries uint // unique number of queries in class
2222
Example *Example `json:",omitempty"` // sample query with max Query_time
2323
// --
24-
outliers uint64
25-
lastDb string
26-
sample bool
24+
outliers uint64
25+
lastDb string
26+
sample bool
27+
maxQueryTime float64
28+
maxQueryCommentMetadata map[string]string
2729
}
2830

2931
// A Example is a real query and its database, timestamp, and Query_time.
@@ -40,12 +42,14 @@ type Example struct {
4042
// If sample is true, the query with the greatest Query_time is saved.
4143
func NewClass(id, fingerprint string, sample bool) *Class {
4244
return &Class{
43-
Id: id,
44-
Fingerprint: fingerprint,
45-
Metrics: NewMetrics(),
46-
TotalQueries: 0,
47-
Example: &Example{},
48-
sample: sample,
45+
Id: id,
46+
Fingerprint: fingerprint,
47+
Metrics: NewMetrics(),
48+
TotalQueries: 0,
49+
Example: &Example{},
50+
sample: sample,
51+
maxQueryTime: 0,
52+
maxQueryCommentMetadata: map[string]string{},
4953
}
5054
}
5155

@@ -82,6 +86,13 @@ func (c *Class) AddEvent(e Event, outlier bool) {
8286
}
8387
}
8488
}
89+
90+
if queryTime, ok := e.TimeMetrics["Query_time"]; ok {
91+
if queryTime > c.maxQueryTime {
92+
c.maxQueryCommentMetadata = e.CommentMetadata
93+
}
94+
}
95+
8596
}
8697

8798
// Finalize calculates all metric statistics. Call this function when done

metrics.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ type Metrics struct {
1414
TimeMetrics map[string]*TimeStats `json:",omitempty"`
1515
NumberMetrics map[string]*NumberStats `json:",omitempty"`
1616
BoolMetrics map[string]*BoolStats `json:",omitempty"`
17-
// TODO(Yash): Add another metrics for metadata.
1817
}
1918

2019
// TimeStats are microsecond-based metrics like Query_time and Lock_time.
@@ -27,8 +26,6 @@ type TimeStats struct {
2726
P95 float64 `json:",omitempty"` // 95th percentile
2827
Max float64 `json:",omitempty"`
2928
outlierSum float64
30-
// TODO(Yash) timeTakeToTraceId as map. Move this to Metrics class or create another struct parallel to TImeMetrics, NumberMetrics, BoolMetrics
31-
// traceIdOfMaxSql
3229
}
3330

3431
// NumberStats are integer-based metrics like Rows_sent and Merge_passes.
@@ -75,7 +72,6 @@ func (m *Metrics) AddEvent(e Event, outlier bool) {
7572
stats.Sum += val
7673
}
7774
stats.vals = append(stats.vals, float64(val))
78-
// TODO(Yash): Add traceIdProto to the map defined in TimeMetrics
7975
}
8076

8177
for metric, val := range e.NumberMetrics {
@@ -137,7 +133,6 @@ func (m *Metrics) Finalize(rateLimit uint) {
137133

138134
// Update sum last because avg ^ needs the original value.
139135
s.Sum = (s.Sum * float64(rateLimit)) + s.outlierSum
140-
//TODO(Yash): Do timeTakenToTraceIdProto[s.Max] to know the traceId and populate traceIdOfMaxSql
141136
}
142137

143138
for _, s := range m.NumberMetrics {

0 commit comments

Comments
 (0)