-
Notifications
You must be signed in to change notification settings - Fork 117
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
Measure labels and formatting in alert emails #4731
Conversation
runtime/queries/proto.go
Outdated
// ProtoFromJSON builds a proto query from a query name, JSON args, and optional execution time. | ||
func ProtoFromJSON(qryName, qryArgsJSON string, executionTime *time.Time) (*runtimev1.Query, error) { | ||
func ProtoFromJSON(qryName, qryArgsJSON string, executionTime *time.Time) (*runtimev1.Query, string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we split this out into a func MetricsViewFromQuery(qry *runtimev1.Query) (name string, ok bool)
function instead? It would need to reproduce the switch
, but would nicely separate the concerns (e.g. in case we need to use ProtoFromJSON
for non-metrics queries in the future.)
runtime/reconcilers/alert.go
Outdated
m := row.AsMap() | ||
res := make(map[string]any) | ||
for k, v := range m { | ||
var measureLabel string | ||
var f formatter.Formatter | ||
for _, measure := range measures { | ||
if k == measure.Name { | ||
measureLabel = measure.Label | ||
var err error | ||
// D3 formatting isn't implemented yet so using the format preset for now | ||
f, err = formatter.NewPresetFormatter(measure.FormatPreset, false) | ||
if err != nil { | ||
return nil, false, err | ||
} | ||
break | ||
} | ||
} | ||
if measureLabel == "" { | ||
measureLabel = k | ||
} | ||
res[measureLabel] = formatValue(f, v, logger) | ||
} | ||
return res, true, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Can we pull this out into a util function to avoid too much nesting? E.g.
func formatResultRow(row map[string]any, metricsView) map[string]any
- Do you think it would make sense to log the error from
NewPresetFormatter
and output the non-formatted values? Instead of failing the alert due to an error in the format preset.
runtime/reconcilers/alert.go
Outdated
var measureLabel string | ||
var f formatter.Formatter | ||
for _, measure := range measures { | ||
if v.MeasureName == measure.Name { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments as above about a util func (probably a different one since the logic is quite different) and maybe falling back to non-formatted measures instead of failing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
* Measure value formatter * Turned most structures private * Formatting in alerts * Revert "Formatting in alerts" This reverts commit 0aa937b. * Fixed code style * Alert number formatting * Simplification * Split a function and reduced nesting level * Fixed nil dereference issue * Reduced nesting level
No description provided.