-
Notifications
You must be signed in to change notification settings - Fork 109
Fix metric_custom_indicator
's good
and total
metrics array
#545
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
Merged
jloleysens
merged 7 commits into
elastic:main
from
jloleysens:fix-slo-custom-metric-good
Jan 31, 2024
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
12debcc
first fix attempt
jloleysens d0c697e
also support multiple metrics in total
jloleysens ef01b30
run test against fixed version
jloleysens 10c986a
Revert "run test against fixed version"
jloleysens 5ffaa40
fix name extraction
jloleysens 0027cfb
fixed slo read data
jloleysens e623433
oops
jloleysens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package kibana | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/elastic/terraform-provider-elasticstack/generated/slo" | ||
"github.com/elastic/terraform-provider-elasticstack/internal/clients" | ||
|
@@ -541,34 +542,42 @@ func getSloFromResourceData(d *schema.ResourceData) (models.Slo, diag.Diagnostic | |
} | ||
|
||
case "metric_custom_indicator": | ||
goodMetricsRaw := d.Get(indicatorType + ".0.good.0.metrics").([]interface{}) | ||
var goodMetrics []slo.IndicatorPropertiesCustomMetricParamsGoodMetricsInner | ||
for n := range goodMetricsRaw { | ||
idx := fmt.Sprint(n) | ||
goodMetrics = append(goodMetrics, slo.IndicatorPropertiesCustomMetricParamsGoodMetricsInner{ | ||
Name: d.Get(indicatorType + ".0.good.0.metrics." + idx + ".name").(string), | ||
Field: d.Get(indicatorType + ".0.good.0.metrics." + idx + ".field").(string), | ||
Aggregation: d.Get(indicatorType + ".0.good.0.metrics." + idx + ".aggregation").(string), | ||
Filter: getOrNilString(indicatorType+".0.good.0.metrics."+idx+".filter", d), | ||
}) | ||
} | ||
totalMetricsRaw := d.Get(indicatorType + ".0.total.0.metrics").([]interface{}) | ||
var totalMetrics []slo.IndicatorPropertiesCustomMetricParamsTotalMetricsInner | ||
for n := range totalMetricsRaw { | ||
idx := fmt.Sprint(n) | ||
totalMetrics = append(totalMetrics, slo.IndicatorPropertiesCustomMetricParamsTotalMetricsInner{ | ||
Name: d.Get(indicatorType + ".0.total.0.metrics.+" + idx + ".name").(string), | ||
Field: d.Get(indicatorType + ".0.total.0.metrics." + idx + ".field").(string), | ||
Aggregation: d.Get(indicatorType + ".0.total.0.metrics." + idx + ".aggregation").(string), | ||
Filter: getOrNilString(indicatorType+".0.total.0.metrics."+idx+".filter", d), | ||
}) | ||
} | ||
indicator = slo.SloResponseIndicator{ | ||
IndicatorPropertiesCustomMetric: &slo.IndicatorPropertiesCustomMetric{ | ||
Type: indicatorAddressToType[indicatorType], | ||
Params: slo.IndicatorPropertiesCustomMetricParams{ | ||
Filter: getOrNilString(indicatorType+".0.filter", d), | ||
Index: d.Get(indicatorType + ".0.index").(string), | ||
TimestampField: d.Get(indicatorType + ".0.timestamp_field").(string), | ||
Total: slo.IndicatorPropertiesCustomMetricParamsTotal{ | ||
Equation: d.Get(indicatorType + ".0.total.0.equation").(string), | ||
Metrics: []slo.IndicatorPropertiesCustomMetricParamsTotalMetricsInner{ //are there actually instances where there are more than one 'good' / 'total'? Need to build array if so. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes there are 😄 |
||
{ | ||
Name: d.Get(indicatorType + ".0.total.0.metrics.0.name").(string), | ||
Field: d.Get(indicatorType + ".0.total.0.metrics.0.field").(string), | ||
Aggregation: d.Get(indicatorType + ".0.total.0.metrics.0.aggregation").(string), | ||
Filter: getOrNilString(indicatorType+".0.total.0.metrics.0.filter", d), | ||
}, | ||
}, | ||
}, | ||
Good: slo.IndicatorPropertiesCustomMetricParamsGood{ | ||
Equation: d.Get(indicatorType + ".0.good.0.equation").(string), | ||
Metrics: []slo.IndicatorPropertiesCustomMetricParamsGoodMetricsInner{ //are there actually instances where there are more than one 'good' / 'total'? Need to build array if so. | ||
{ | ||
Name: d.Get(indicatorType + ".0.good.0.metrics.0.name").(string), | ||
Field: d.Get(indicatorType + ".0.good.0.metrics.0.field").(string), | ||
Aggregation: d.Get(indicatorType + ".0.good.0.metrics.0.aggregation").(string), | ||
Filter: getOrNilString(indicatorType+".0.good.0.metrics.0.filter", d), | ||
}, | ||
}, | ||
Metrics: goodMetrics, | ||
}, | ||
Total: slo.IndicatorPropertiesCustomMetricParamsTotal{ | ||
Equation: d.Get(indicatorType + ".0.total.0.equation").(string), | ||
Metrics: totalMetrics, | ||
}, | ||
}, | ||
}, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It seems that in the SLO UI the
total
can also accept an array of metrics. Should we also support an array of metrics for it?