From 3331506660c527bd998886dcc29f82fdbd0b8354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 4 Jun 2021 16:19:44 +0200 Subject: [PATCH 01/24] Docs: Adds docs for histogram visualization (#35241) * Docs: Adds docs for histogram visualization * Bucket offset clarification * tweaks * less bad math * Update docs/sources/panels/visualizations/histogram.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/panels/visualizations/histogram.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/panels/visualizations/histogram.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/panels/visualizations/histogram.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/panels/visualizations/histogram.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/panels/visualizations/histogram.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/panels/visualizations/histogram.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/panels/visualizations/histogram.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> Co-authored-by: Leon Sorokin Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> --- .../panels/visualizations/histogram.md | 66 +++++++++++++++++++ docs/sources/whatsnew/whats-new-in-v8-0.md | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 docs/sources/panels/visualizations/histogram.md diff --git a/docs/sources/panels/visualizations/histogram.md b/docs/sources/panels/visualizations/histogram.md new file mode 100644 index 00000000000..31321f1cb7d --- /dev/null +++ b/docs/sources/panels/visualizations/histogram.md @@ -0,0 +1,66 @@ ++++ +title = "Histogram" +description = "Histogram visualization" +keywords = ["grafana", "docs", "bar chart", "panel", "barchart"] +weight = 605 ++++ + +# Histogram + +The histogram visualization calculates the distribution of values and presents them as a bar chart. The Y-axis and the height of each bar represent the count of values that fall into each bracket while the X-axis represents the value range. + +{{< figure src="/static/img/docs/histogram-panel/histogram-example-v8-0.png" max-width="625px" caption="Bar chart example" >}} + +## Supported data formats + +Histogram visualization supports time series and any table results with one or more numerical fields. + +## Display options + +Use the following options to refine your visualization. + +### Bucket size + +The size of the buckets. Leave this empty for automatic bucket sizing (~10% of the full range). + +### Bucket offset + +If the first bucket should not start at zero. A non-zero offset has the effect of shifting the aggregation window. For example, 5-sized buckets that are 0-5, 5-10, 10-15 with a default 0 offset would become 2-7, 7-12, 12-17 with an offset of 2; offsets of 0, 5, or 10, in this case, would effectively do nothing. Typically, this option would be used with an explicitly defined bucket size rather than automatic. For this setting to affect, the offset amount should be greater than 0 and less than the bucket size; values outside this range will have the same effect as values within this range. + +### Combine series + +This will merge all series and fields into a combined histogram. + +### Line width + +Controls line width of the bars. + +### Fill opacity + +Controls the fill opacity bars. + +### Gradient mode + +Set the mode of the gradient fill. Fill gradient is based on the line color. To change the color, use the standard [color scheme]({{< relref "../standard-options.md#color-scheme" >}}) field option. + +Gradient display is influenced by the **Fill opacity** setting. + +#### None + +No gradient fill. This is the default setting. + +#### Opacity + +Transparency of the gradient is calculated based on the values on the Y-axis. The opacity of the fill is increasing with the values on the Y-axis. + +#### Hue + +Gradient color is generated based on the hue of the line color. + +{{< docs/shared "visualizations/tooltip-mode.md" >}} + +{{< docs/shared "visualizations/legend-mode.md" >}} + +### Legend calculations + +Choose a [standard calculations]({{< relref "../calculations-list.md">}}) to show in the legend. You can select more than one. diff --git a/docs/sources/whatsnew/whats-new-in-v8-0.md b/docs/sources/whatsnew/whats-new-in-v8-0.md index c20f39a443f..143a363ecca 100644 --- a/docs/sources/whatsnew/whats-new-in-v8-0.md +++ b/docs/sources/whatsnew/whats-new-in-v8-0.md @@ -81,7 +81,7 @@ A sister panel to the state timeline is the new Status history panel visualizati This hidden feature of the old Graph panel is now a standalone visualization. It combines a histogram transformation and bar chart visualization into a single, integrated, easy-to-use panel. There is also a new standalone histogram transformation that can be paired with any visualization. -![Histogram visualization](/static/img/docs/histogram/histogram-8-0.png) +{{< figure src="/static/img/docs/histogram/histogram-8-0.png" max-width="1025px" caption="Histogram example" >}} ### Time series visualization updates From 70155c7fd0b12acdf90f88b10f01a0fce9a35e17 Mon Sep 17 00:00:00 2001 From: Uchechukwu Obasi Date: Fri, 4 Jun 2021 15:22:11 +0100 Subject: [PATCH 02/24] Graph: fixes storybook crashing when using the story (#35251) * Graph: fixes storybook crashing when using the story * fixes the GraphWithLegend story too --- packages/grafana-ui/src/components/Graph/Graph.story.tsx | 4 ++-- .../grafana-ui/src/components/Graph/GraphWithLegend.story.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/grafana-ui/src/components/Graph/Graph.story.tsx b/packages/grafana-ui/src/components/Graph/Graph.story.tsx index 0e72bda3f51..4ea98a79d25 100644 --- a/packages/grafana-ui/src/components/Graph/Graph.story.tsx +++ b/packages/grafana-ui/src/components/Graph/Graph.story.tsx @@ -85,7 +85,7 @@ export default { disable: true, }, controls: { - exclude: ['className', 'series', 'timeRange', 'ariaLabel'], + exclude: ['className', 'ariaLabel'], }, }, args: { @@ -107,7 +107,7 @@ export default { tooltipMode: { control: { type: 'radio', options: ['multi', 'single'] } }, timeZone: { control: { type: 'radio', options: ['browser', 'utc'] } }, width: { control: { type: 'range', min: 200, max: 800 } }, - height: { control: { type: 'range', min: 200, max: 800 } }, + height: { control: { type: 'range', min: 200, max: 1700, step: 300 } }, lineWidth: { control: { type: 'range', min: 1, max: 10 } }, }, }; diff --git a/packages/grafana-ui/src/components/Graph/GraphWithLegend.story.tsx b/packages/grafana-ui/src/components/Graph/GraphWithLegend.story.tsx index 792e929568c..f5b14baa7f0 100644 --- a/packages/grafana-ui/src/components/Graph/GraphWithLegend.story.tsx +++ b/packages/grafana-ui/src/components/Graph/GraphWithLegend.story.tsx @@ -15,7 +15,7 @@ export default { disable: true, }, controls: { - exclude: ['className', 'series', 'timeRange', 'ariaLabel', 'legendDisplayMode'], + exclude: ['className', 'ariaLabel', 'legendDisplayMode'], }, }, argTypes: { @@ -24,7 +24,7 @@ export default { rightAxisSeries: { name: 'Right y-axis series, i.e. A,C' }, timeZone: { control: { type: 'radio', options: ['browser', 'utc'] } }, width: { control: { type: 'range', min: 200, max: 800 } }, - height: { control: { type: 'range', min: 200, max: 800 } }, + height: { control: { type: 'range', min: 1700, step: 300 } }, lineWidth: { control: { type: 'range', min: 1, max: 10 } }, }, }; From 7a304223e69f6a9c06405ed7ec6ff817ebb4787d Mon Sep 17 00:00:00 2001 From: Giordano Ricci Date: Fri, 4 Jun 2021 15:42:00 +0100 Subject: [PATCH 03/24] Elasticsearch: Fix min_doc_count value when alerting (#35254) * Elasticsearch: Fix min_doc_count value when alerting * Add tests --- pkg/tsdb/elasticsearch/time_series_query.go | 49 +++++++++---- .../elasticsearch/time_series_query_test.go | 72 +++++++++++++++++++ 2 files changed, 107 insertions(+), 14 deletions(-) diff --git a/pkg/tsdb/elasticsearch/time_series_query.go b/pkg/tsdb/elasticsearch/time_series_query.go index 57c18febd14..08e893e1ff7 100644 --- a/pkg/tsdb/elasticsearch/time_series_query.go +++ b/pkg/tsdb/elasticsearch/time_series_query.go @@ -100,6 +100,9 @@ func (e *timeSeriesQuery) processQuery(q *Query, ms *es.MultiSearchRequestBuilde // iterate backwards to create aggregations bottom-down for _, bucketAgg := range q.BucketAggs { + bucketAgg.Settings = simplejson.NewFromAny( + bucketAgg.generateSettingsForDSL(), + ) switch bucketAgg.Type { case dateHistType: aggBuilder = addDateHistogramAgg(aggBuilder, bucketAgg, from, to) @@ -182,26 +185,34 @@ func (e *timeSeriesQuery) processQuery(q *Query, ms *es.MultiSearchRequestBuilde return nil } -// Casts values to int when required by Elastic's query DSL -func (metricAggregation MetricAgg) generateSettingsForDSL(version *semver.Version) map[string]interface{} { - setFloatPath := func(path ...string) { - if stringValue, err := metricAggregation.Settings.GetPath(path...).String(); err == nil { - if value, err := strconv.ParseFloat(stringValue, 64); err == nil { - metricAggregation.Settings.SetPath(path, value) - } +func setFloatPath(settings *simplejson.Json, path ...string) { + if stringValue, err := settings.GetPath(path...).String(); err == nil { + if value, err := strconv.ParseFloat(stringValue, 64); err == nil { + settings.SetPath(path, value) } } +} +func setIntPath(settings *simplejson.Json, path ...string) { + if stringValue, err := settings.GetPath(path...).String(); err == nil { + if value, err := strconv.ParseInt(stringValue, 10, 64); err == nil { + settings.SetPath(path, value) + } + } +} + +// Casts values to float when required by Elastic's query DSL +func (metricAggregation MetricAgg) generateSettingsForDSL(version *semver.Version) map[string]interface{} { switch metricAggregation.Type { case "moving_avg": - setFloatPath("window") - setFloatPath("predict") - setFloatPath("settings", "alpha") - setFloatPath("settings", "beta") - setFloatPath("settings", "gamma") - setFloatPath("settings", "period") + setFloatPath(metricAggregation.Settings, "window") + setFloatPath(metricAggregation.Settings, "predict") + setFloatPath(metricAggregation.Settings, "settings", "alpha") + setFloatPath(metricAggregation.Settings, "settings", "beta") + setFloatPath(metricAggregation.Settings, "settings", "gamma") + setFloatPath(metricAggregation.Settings, "settings", "period") case "serial_diff": - setFloatPath("lag") + setFloatPath(metricAggregation.Settings, "lag") } if isMetricAggregationWithInlineScriptSupport(metricAggregation.Type) { @@ -225,6 +236,16 @@ func (metricAggregation MetricAgg) generateSettingsForDSL(version *semver.Versio return metricAggregation.Settings.MustMap() } +func (bucketAgg BucketAgg) generateSettingsForDSL() map[string]interface{} { + // TODO: This might also need to be applied to other bucket aggregations and other fields. + switch bucketAgg.Type { + case "date_histogram": + setIntPath(bucketAgg.Settings, "min_doc_count") + } + + return bucketAgg.Settings.MustMap() +} + func addDateHistogramAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg, timeFrom, timeTo string) es.AggBuilder { aggBuilder.DateHistogram(bucketAgg.ID, bucketAgg.Field, func(a *es.DateHistogramAgg, b es.AggBuilder) { a.Interval = bucketAgg.Settings.Get("interval").MustString("auto") diff --git a/pkg/tsdb/elasticsearch/time_series_query_test.go b/pkg/tsdb/elasticsearch/time_series_query_test.go index 5a3d8a02b5e..b33c23fe286 100644 --- a/pkg/tsdb/elasticsearch/time_series_query_test.go +++ b/pkg/tsdb/elasticsearch/time_series_query_test.go @@ -934,6 +934,78 @@ func TestSettingsCasting(t *testing.T) { assert.Equal(t, 1., serialDiffSettings["lag"]) }) + t.Run("Date Histogram Settings", func(t *testing.T) { + t.Run("Correctly transforms date_histogram settings", func(t *testing.T) { + c := newFakeClient("5.0.0") + _, err := executeTsdbQuery(c, `{ + "timeField": "@timestamp", + "bucketAggs": [ + { + "type": "date_histogram", + "field": "@timestamp", + "id": "2", + "settings": { + "min_doc_count": "1" + } + } + ], + "metrics": [ + { "id": "1", "type": "average", "field": "@value" }, + { + "id": "3", + "type": "serial_diff", + "field": "1", + "pipelineAgg": "1", + "settings": { + "lag": "1" + } + } + ] + }`, from, to, 15*time.Second) + assert.Nil(t, err) + sr := c.multisearchRequests[0].Requests[0] + + dateHistogramAgg := sr.Aggs[0].Aggregation.Aggregation.(*es.DateHistogramAgg) + + assert.Equal(t, 1, dateHistogramAgg.MinDocCount) + }) + + t.Run("Correctly uses already int min_doc_count", func(t *testing.T) { + c := newFakeClient("5.0.0") + _, err := executeTsdbQuery(c, `{ + "timeField": "@timestamp", + "bucketAggs": [ + { + "type": "date_histogram", + "field": "@timestamp", + "id": "2", + "settings": { + "min_doc_count": 10 + } + } + ], + "metrics": [ + { "id": "1", "type": "average", "field": "@value" }, + { + "id": "3", + "type": "serial_diff", + "field": "1", + "pipelineAgg": "1", + "settings": { + "lag": "1" + } + } + ] + }`, from, to, 15*time.Second) + assert.Nil(t, err) + sr := c.multisearchRequests[0].Requests[0] + + dateHistogramAgg := sr.Aggs[0].Aggregation.Aggregation.(*es.DateHistogramAgg) + + assert.Equal(t, 10, dateHistogramAgg.MinDocCount) + }) + }) + t.Run("Inline Script", func(t *testing.T) { t.Run("Correctly handles scripts for ES < 5.6", func(t *testing.T) { c := newFakeClient("5.0.0") From aae6e86547066703facf58f0f6b5764f665466bd Mon Sep 17 00:00:00 2001 From: David Date: Fri, 4 Jun 2021 16:50:17 +0200 Subject: [PATCH 04/24] Prometheus: Metrics browser layout (#35035) * Metrics browser layout * Simplified layout --- .../components/PrometheusMetricsBrowser.tsx | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/components/PrometheusMetricsBrowser.tsx b/public/app/plugins/datasource/prometheus/components/PrometheusMetricsBrowser.tsx index 400bb60939e..d56b24e0c8a 100644 --- a/public/app/plugins/datasource/prometheus/components/PrometheusMetricsBrowser.tsx +++ b/public/app/plugins/datasource/prometheus/components/PrometheusMetricsBrowser.tsx @@ -13,6 +13,8 @@ const MAX_LABEL_COUNT = 10000; const MAX_VALUE_COUNT = 50000; const EMPTY_SELECTOR = '{}'; const METRIC_LABEL = '__name__'; +const LIST_ITEM_SIZE = 25; + export const LAST_USED_LABELS_KEY = 'grafana.datasources.prometheus.browser.labels'; export interface BrowserProps { @@ -105,7 +107,7 @@ export function facetLabels( const getStyles = stylesFactory((theme: GrafanaTheme) => ({ wrapper: css` background-color: ${theme.colors.bg2}; - padding: ${theme.spacing.md}; + padding: ${theme.spacing.sm}; width: 100%; `, list: css` @@ -114,6 +116,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => ({ flex-wrap: wrap; max-height: 200px; overflow: auto; + align-content: flex-start; `, section: css` & + & { @@ -177,6 +180,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => ({ * to create a single, generic component. */ export class UnthemedPrometheusMetricsBrowser extends React.Component { + valueListsRef = React.createRef(); state: BrowserState = { labels: [] as SelectableLabel[], labelSearchTerm: '', @@ -439,7 +443,7 @@ export class UnthemedPrometheusMetricsBrowser extends React.Component
- +
(metrics!.values as FacettableValue[])[i].name} width={300} className={styles.valueList} @@ -526,7 +532,7 @@ export class UnthemedPrometheusMetricsBrowser extends React.Component
-