Skip to content

Commit

Permalink
adding maxQueryCommentMetadata to Class struct
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmaheshwari committed Oct 8, 2020
1 parent 0f3027e commit dd8919f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
29 changes: 20 additions & 9 deletions class.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ type Class struct {
UniqueQueries uint // unique number of queries in class
Example *Example `json:",omitempty"` // sample query with max Query_time
// --
outliers uint64
lastDb string
sample bool
outliers uint64
lastDb string
sample bool
maxQueryTime float64
maxQueryCommentMetadata map[string]string
}

// A Example is a real query and its database, timestamp, and Query_time.
Expand All @@ -40,12 +42,14 @@ type Example struct {
// If sample is true, the query with the greatest Query_time is saved.
func NewClass(id, fingerprint string, sample bool) *Class {
return &Class{
Id: id,
Fingerprint: fingerprint,
Metrics: NewMetrics(),
TotalQueries: 0,
Example: &Example{},
sample: sample,
Id: id,
Fingerprint: fingerprint,
Metrics: NewMetrics(),
TotalQueries: 0,
Example: &Example{},
sample: sample,
maxQueryTime: 0,
maxQueryCommentMetadata: map[string]string{},
}
}

Expand Down Expand Up @@ -82,6 +86,13 @@ func (c *Class) AddEvent(e Event, outlier bool) {
}
}
}

if queryTime, ok := e.TimeMetrics["Query_time"]; ok {
if queryTime > c.maxQueryTime {
c.maxQueryCommentMetadata = e.CommentMetadata
}
}

}

// Finalize calculates all metric statistics. Call this function when done
Expand Down
5 changes: 0 additions & 5 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type Metrics struct {
TimeMetrics map[string]*TimeStats `json:",omitempty"`
NumberMetrics map[string]*NumberStats `json:",omitempty"`
BoolMetrics map[string]*BoolStats `json:",omitempty"`
// TODO(Yash): Add another metrics for metadata.
}

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

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

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

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

for _, s := range m.NumberMetrics {
Expand Down

0 comments on commit dd8919f

Please sign in to comment.