Skip to content
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

Merged
merged 12 commits into from
Apr 29, 2024

Conversation

esevastyanov
Copy link
Contributor

No description provided.

@esevastyanov esevastyanov marked this pull request as ready for review April 26, 2024 15:11
@esevastyanov esevastyanov changed the title Alert number formatting Measure labels and formatting in alert emails Apr 26, 2024
Comment on lines 64 to 65
// 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) {
Copy link
Contributor

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.)

Comment on lines 895 to 917
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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
  2. 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.

Comment on lines 926 to 929
var measureLabel string
var f formatter.Formatter
for _, measure := range measures {
if v.MeasureName == measure.Name {
Copy link
Contributor

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

Base automatically changed from backend-formatter to main April 28, 2024 16:33
Copy link
Contributor

@begelundmuller begelundmuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@begelundmuller begelundmuller merged commit 1592884 into main Apr 29, 2024
4 checks passed
@begelundmuller begelundmuller deleted the alert-number-formatter branch April 29, 2024 12:32
k-anshul pushed a commit that referenced this pull request Apr 30, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants