diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000000..3a0f40dcf59 --- /dev/null +++ b/.babelrc @@ -0,0 +1,11 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "targets": { "browsers": "last 3 versions" }, + "useBuiltIns": "entry" + } + ] + ] +} diff --git a/.circleci/config.yml b/.circleci/config.yml index dc30554fc5c..3dd8f800b94 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -162,8 +162,8 @@ jobs: name: Build Grafana.com master publisher command: 'go build -o scripts/publish scripts/build/publish.go' - run: - name: Build Grafana.com release publisher - command: 'cd scripts/build/release_publisher && go build -o release_publisher .' + name: Test and build Grafana.com release publisher + command: 'cd scripts/build/release_publisher && go test . && go build -o release_publisher .' - persist_to_workspace: root: . paths: @@ -191,6 +191,9 @@ jobs: - run: name: sha-sum packages command: 'go run build.go sha-dist' + - run: + name: Test Grafana.com release publisher + command: 'cd scripts/build/release_publisher && go test .' - persist_to_workspace: root: . paths: diff --git a/CHANGELOG.md b/CHANGELOG.md index 571989ea506..ab5263eba03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,21 @@ -# 5.4.0 (unreleased) +# 5.5.0 (unreleased) + +### Minor + +* **Elasticsearch**: Add support for offset in date histogram aggregation [#12653](https://github.com/grafana/grafana/issues/12653), thx [@mattiarossi](https://github.com/mattiarossi) +* **Auth**: Prevent password reset when login form is disabled or either LDAP or Auth Proxy is enabled [#14246](https://github.com/grafana/grafana/issues/14246), thx [@SilverFire](https://github.com/SilverFire) +* **Dataproxy**: Override incoming Authorization header [#13815](https://github.com/grafana/grafana/issues/13815), thx [@kornholi](https://github.com/kornholi) +* **Admin**: Fix prevent removing last grafana admin permissions [#11067](https://github.com/grafana/grafana/issues/11067), thx [@danielbh](https://github.com/danielbh) + +# 5.4.0 (2018-12-03) * **Cloudwatch**: Fix invalid time range causes segmentation fault [#14150](https://github.com/grafana/grafana/issues/14150) +* **Cloudwatch**: AWS/CodeBuild metrics and dimensions [#14167](https://github.com/grafana/grafana/issues/14167), thx [@mmcoltman](https://github.com/mmcoltman) +* **MySQL**: Fix `$__timeFrom()` and `$__timeTo()` should respect local time zone [#14228](https://github.com/grafana/grafana/issues/14228) + +### 5.4.0-beta1 fixes +* **Graph**: Fix legend always visible even if configured to be hidden [#14144](https://github.com/grafana/grafana/issues/14144) +* **Elasticsearch**: Fix regression when using datasource version 6.0+ and alerting [#14175](https://github.com/grafana/grafana/pull/14175) # 5.4.0-beta1 (2018-11-20) @@ -156,7 +171,7 @@ See [security announcement](https://community.grafana.com/t/grafana-5-3-3-and-4- * **Alerting**: Fix rendering timeout which could cause notifications to not be sent due to rendering timing out [#12151](https://github.com/grafana/grafana/issues/12151) * **Docker**: Make it possible to set a specific plugin url [#12861](https://github.com/grafana/grafana/pull/12861), thx [ClementGautier](https://github.com/ClementGautier) * **GrafanaCli**: Fixed issue with grafana-cli install plugin resulting in corrupt http response from source error. Fixes [#13079](https://github.com/grafana/grafana/issues/13079) -* **Provisioning**: Should allow one default datasource per organisation [#12229](https://github.com/grafana/grafana/issues/12229) +* **Provisioning**: Should allow one default datasource per organization [#12229](https://github.com/grafana/grafana/issues/12229) * **Github OAuth**: Allow changes of user info at Github to be synched to Grafana when signing in [#11818](https://github.com/grafana/grafana/issues/11818), thx [@rwaweber](https://github.com/rwaweber) * **OAuth**: Fix overriding tls_skip_verify_insecure using environment variable [#12747](https://github.com/grafana/grafana/issues/12747), thx [@jangaraj](https://github.com/jangaraj) * **Prometheus**: Fix graph panel bar width issue in aligned prometheus queries [#12379](https://github.com/grafana/grafana/issues/12379) @@ -279,7 +294,7 @@ See [security announcement](https://community.grafana.com/t/grafana-5-2-3-and-4- * **Dashboard**: Prevent double-click when saving dashboard [#11963](https://github.com/grafana/grafana/issues/11963) * **Dashboard**: AutoFocus the add-panel search filter [#12189](https://github.com/grafana/grafana/pull/12189) thx [@ryantxu](https://github.com/ryantxu) * **Units**: W/m2 (energy), l/h (flow) and kPa (pressure) [#11233](https://github.com/grafana/grafana/pull/11233), thx [@flopp999](https://github.com/flopp999) -* **Units**: Litre/min (flow) and milliLitre/min (flow) [#12282](https://github.com/grafana/grafana/pull/12282), thx [@flopp999](https://github.com/flopp999) +* **Units**: Liter/min (flow) and milliLiter/min (flow) [#12282](https://github.com/grafana/grafana/pull/12282), thx [@flopp999](https://github.com/flopp999) * **Alerting**: Fix mobile notifications for Microsoft Teams alert notifier [#11484](https://github.com/grafana/grafana/pull/11484), thx [@manacker](https://github.com/manacker) * **Influxdb**: Add support for mode function [#12286](https://github.com/grafana/grafana/issues/12286) * **Cloudwatch**: Fixes panic caused by bad timerange settings [#12199](https://github.com/grafana/grafana/issues/12199) @@ -414,7 +429,7 @@ See [security announcement](https://community.grafana.com/t/grafana-5-2-3-and-4- * **Units**: Use B/s instead Bps for Bytes per second [#9342](https://github.com/grafana/grafana/pull/9342), thx [@mayli](https://github.com/mayli) * **Units**: Radiation units [#11001](https://github.com/grafana/grafana/issues/11001), thx [@victorclaessen](https://github.com/victorclaessen) * **Units**: Timeticks unit [#11183](https://github.com/grafana/grafana/pull/11183), thx [@jtyr](https://github.com/jtyr) -* **Units**: Concentration units and "Normal cubic metre" [#11211](https://github.com/grafana/grafana/issues/11211), thx [@flopp999](https://github.com/flopp999) +* **Units**: Concentration units and "Normal cubic meter" [#11211](https://github.com/grafana/grafana/issues/11211), thx [@flopp999](https://github.com/flopp999) * **Units**: New currency - Czech koruna [#11384](https://github.com/grafana/grafana/pull/11384), thx [@Rohlik](https://github.com/Rohlik) * **Avatar**: Fix DISABLE_GRAVATAR option [#11095](https://github.com/grafana/grafana/issues/11095) * **Heatmap**: Disable log scale when using time time series buckets [#10792](https://github.com/grafana/grafana/issues/10792) @@ -731,7 +746,7 @@ See [security announcement](https://community.grafana.com/t/grafana-5-2-3-and-4- ## Enhancements * **GitHub OAuth**: Support for GitHub organizations with 100+ teams. [#8846](https://github.com/grafana/grafana/issues/8846), thx [@skwashd](https://github.com/skwashd) -* **Graphite**: Calls to Graphite api /metrics/find now include panel or dashboad time range (from & until) in most cases, [#8055](https://github.com/grafana/grafana/issues/8055) +* **Graphite**: Calls to Graphite api /metrics/find now include panel or dashboard time range (from & until) in most cases, [#8055](https://github.com/grafana/grafana/issues/8055) * **Graphite**: Added new graphite 1.0 functions, available if you set version to 1.0.x in data source settings. New Functions: mapSeries, reduceSeries, isNonNull, groupByNodes, offsetToZero, grep, weightedAverage, removeEmptySeries, aggregateLine, averageOutsidePercentile, delay, exponentialMovingAverage, fallbackSeries, integralByInterval, interpolate, invert, linearRegression, movingMin, movingMax, movingSum, multiplySeriesWithWildcards, pow, powSeries, removeBetweenPercentile, squareRoot, timeSlice, closes [#8261](https://github.com/grafana/grafana/issues/8261) - **Elasticsearch**: Ad-hoc filters now use query phrase match filters instead of term filters, works on non keyword/raw fields [#9095](https://github.com/grafana/grafana/issues/9095). @@ -896,7 +911,7 @@ Pull Request: [#8472](https://github.com/grafana/grafana/pull/8472) * **InfluxDB**: Influxb Datasource test passes even if the Database doesn't exist [#7864](https://github.com/grafana/grafana/issues/7864) * **Prometheus**: Displaying Prometheus annotations is incredibly slow [#7750](https://github.com/grafana/grafana/issues/7750), thx [@mtanda](https://github.com/mtanda) * **Graphite**: grafana generates empty find query to graphite -> 422 Unprocessable Entity [#7740](https://github.com/grafana/grafana/issues/7740) -* **Admin**: make organisation filter case insensitive [#8194](https://github.com/grafana/grafana/issues/8194), thx [@Alexander-N](https://github.com/Alexander-N) +* **Admin**: make organization filter case insensitive [#8194](https://github.com/grafana/grafana/issues/8194), thx [@Alexander-N](https://github.com/Alexander-N) ## Changes * **Elasticsearch**: Changed elasticsearch Terms aggregation to default to Min Doc Count to 1, and sort order to Top [#8321](https://github.com/grafana/grafana/issues/8321) @@ -1024,7 +1039,7 @@ Pull Request: [#8472](https://github.com/grafana/grafana/pull/8472) * **CLI**: Make it possible to reset the admin password using the grafana-cli. [#5479](https://github.com/grafana/grafana/issues/5479) * **Influxdb**: Support multiple tags in InfluxDB annotations. [#4550](https://github.com/grafana/grafana/pull/4550), thx [@adrianlzt](https://github.com/adrianlzt) * **LDAP**: Basic Auth now supports LDAP username and password, [#6940](https://github.com/grafana/grafana/pull/6940), thx [@utkarshcmu](https://github.com/utkarshcmu) -* **LDAP**: Now works with Auth Proxy, role and organisation mapping & sync will regularly be performed. [#6895](https://github.com/grafana/grafana/pull/6895), thx [@Seuf](https://github.com/seuf) +* **LDAP**: Now works with Auth Proxy, role and organization mapping & sync will regularly be performed. [#6895](https://github.com/grafana/grafana/pull/6895), thx [@Seuf](https://github.com/seuf) * **Alerting**: Adds OK as no data option. [#6866](https://github.com/grafana/grafana/issues/6866) * **Alert list**: Order alerts based on state. [#6676](https://github.com/grafana/grafana/issues/6676) * **Alerting**: Add api endpoint for pausing all alerts. [#6589](https://github.com/grafana/grafana/issues/6589) @@ -1163,7 +1178,7 @@ due to too many connections/file handles on the data source backend. This proble * **Scripts**: Use restart instead of start for deb package script, closes [#5282](https://github.com/grafana/grafana/pull/5282) * **Logging**: Moved to structured logging lib, and moved to component specific level filters via config file, closes [#4590](https://github.com/grafana/grafana/issues/4590) * **OpenTSDB**: Support nested template variables in tag_values function, closes [#4398](https://github.com/grafana/grafana/issues/4398) -* **Datasource**: Pending data source requests are cancelled before new ones are issues (Graphite & Prometheus), closes [#5321](https://github.com/grafana/grafana/issues/5321) +* **Datasource**: Pending data source requests are canceled before new ones are issues (Graphite & Prometheus), closes [#5321](https://github.com/grafana/grafana/issues/5321) ### Breaking changes * **Logging** : Changed default logging output format (now structured into message, and key value pairs, with logger key acting as component). You can also no change in config to json log output. @@ -1867,7 +1882,7 @@ Read this [blog post](https://grafana.com/blog/2014/09/11/grafana-1.8.0-rc1-rele #### Fixes - [Issue #126](https://github.com/grafana/grafana/issues/126). Graphite query lexer change, can now handle regex parameters for aliasSub function -- [Issue #447](https://github.com/grafana/grafana/issues/447). Filter option loading when having muliple nested filters now works better. Options are now reloaded correctly and there are no multiple renders/refresh in between. +- [Issue #447](https://github.com/grafana/grafana/issues/447). Filter option loading when having multiple nested filters now works better. Options are now reloaded correctly and there are no multiple renders/refresh in between. - [Issue #412](https://github.com/grafana/grafana/issues/412). After a filter option is changed and a nested template param is reloaded, if the current value exists after the options are reloaded the current selected value is kept. - [Issue #460](https://github.com/grafana/grafana/issues/460). Legend Current value did not display when value was zero - [Issue #328](https://github.com/grafana/grafana/issues/328). Fix to series toggling bug that caused annotations to be hidden when toggling/hiding series. @@ -1902,7 +1917,7 @@ Read this [blog post](https://grafana.com/blog/2014/09/11/grafana-1.8.0-rc1-rele - Graphite errors are now much easier to see and troubleshoot with the new inspector ([Issue #265](https://github.com/grafana/grafana/issues/265)) - Use influxdb aliases to distinguish between multiple columns ([Issue #283](https://github.com/grafana/grafana/issues/283)) - Correction to ms axis formater, now formats days correctly. ([Issue #189](https://github.com/grafana/grafana/issues/189)) -- Css fix for Firefox and using top menu dropdowns in panel fullscren / edit mode ([Issue #106](https://github.com/grafana/grafana/issues/106)) +- Css fix for Firefox and using top menu dropdowns in panel fullscreen / edit mode ([Issue #106](https://github.com/grafana/grafana/issues/106)) - Browser page title is now Grafana - {{dashboard title}} ([Issue #294](https://github.com/grafana/grafana/issues/294)) - Disable auto refresh zooming in (every time you change to an absolute time range), refresh will be restored when you change time range back to relative ([Issue #282](https://github.com/grafana/grafana/issues/282)) - More graphite functions diff --git a/Dockerfile b/Dockerfile index 28dd71952af..65260e1a6a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,7 +50,8 @@ ENV PATH=/usr/share/grafana/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bi WORKDIR $GF_PATHS_HOME -RUN apt-get update && apt-get install -qq -y libfontconfig ca-certificates && \ +RUN apt-get update && apt-get upgrade -y && \ + apt-get install -qq -y libfontconfig ca-certificates && \ apt-get autoremove -y && \ rm -rf /var/lib/apt/lists/* diff --git a/README.md b/README.md index 3961e86e3ac..03fe840d5f1 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,8 @@ Choose this option to build on platforms other than linux/amd64 and/or not have The resulting image will be tagged as `grafana/grafana:dev` +Notice: If you are using Docker for MacOS, be sure to let limit of Memory bigger than 2 GiB (at docker -> Perferences -> Advanced), otherwize you may faild at `grunt build` + ### Dev config Create a custom.ini in the conf directory to override default configuration options. diff --git a/UPGRADING_DEPENDENCIES.md b/UPGRADING_DEPENDENCIES.md index f3d2adbd71a..7d489556981 100644 --- a/UPGRADING_DEPENDENCIES.md +++ b/UPGRADING_DEPENDENCIES.md @@ -47,7 +47,7 @@ Our builds run on CircleCI through our build script. ### grafana/build-container -The main build step (in CircleCI) is built using a custom build container that comes pre-baked with some of the neccesary dependencies. +The main build step (in CircleCI) is built using a custom build container that comes pre-baked with some of the necessary dependencies. Link: [grafana-build-container](https://github.com/grafana/grafana-build-container) @@ -86,4 +86,4 @@ There is a Docker build for Grafana in the root of the project that allows anyon ### Local developer environments -Please send out a notice in the grafana-dev slack channel when updating Go or Node.js to make it easier for everyone to update their local developer environments. \ No newline at end of file +Please send out a notice in the grafana-dev slack channel when updating Go or Node.js to make it easier for everyone to update their local developer environments. diff --git a/conf/defaults.ini b/conf/defaults.ini index 306c625d980..a9aa2239b16 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -34,7 +34,7 @@ protocol = http # The ip address to bind to, empty will bind to all interfaces http_addr = -# The http port to use +# The http port to use http_port = 3000 # The public facing domain name used to access grafana from a browser @@ -166,7 +166,7 @@ google_tag_manager_id = # default admin user, created on startup admin_user = admin -# default admin password, can be changed before first start of grafana, or in profile settings +# default admin password, can be changed before first start of grafana, or in profile settings admin_password = admin # used for signing @@ -372,7 +372,7 @@ templates_pattern = emails/*.html #################################### Logging ########################## [log] -# Either "console", "file", "syslog". Default is console and file +# Either "console", "file", "syslog". Default is console and file # Use space to separate multiple modes, e.g. "console file" mode = console file @@ -565,4 +565,3 @@ enable_alpha = false [enterprise] license_path = - diff --git a/conf/provisioning/datasources/sample.yaml b/conf/provisioning/datasources/sample.yaml index 37487dc4b3b..7bef8618a31 100644 --- a/conf/provisioning/datasources/sample.yaml +++ b/conf/provisioning/datasources/sample.yaml @@ -7,7 +7,7 @@ apiVersion: 1 # orgId: 1 # # list of datasources to insert/update depending -# # on what's available in the datbase +# # on what's available in the database #datasources: # # name of the datasource. Required # - name: Graphite diff --git a/conf/sample.ini b/conf/sample.ini index c6b716a731d..3c61b2b61d1 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -145,6 +145,9 @@ log_queries = # Google Analytics universal tracking code, only enabled if you specify an id here ;google_analytics_ua_id = +# Google Tag Manager ID, only enabled if you specify an id here +;google_tag_manager_id = + #################################### Security #################################### [security] # default admin user, created on startup diff --git a/docs/sources/administration/provisioning.md b/docs/sources/administration/provisioning.md index 60e89b486a5..b2a1b1f42e7 100644 --- a/docs/sources/administration/provisioning.md +++ b/docs/sources/administration/provisioning.md @@ -230,4 +230,4 @@ By default Grafana will delete dashboards in the database if the file is removed > **Note.** Provisioning allows you to overwrite existing dashboards > which leads to problems if you re-use settings that are supposed to be unique. > Be careful not to re-use the same `title` multiple times within a folder -> or `uid` within the same installation as this will cause weird behaviours. +> or `uid` within the same installation as this will cause weird behaviors. diff --git a/docs/sources/alerting/notifications.md b/docs/sources/alerting/notifications.md index b232ee78f27..e791492495e 100644 --- a/docs/sources/alerting/notifications.md +++ b/docs/sources/alerting/notifications.md @@ -55,6 +55,10 @@ Alert rule evaluation interval | Send reminders every | Reminder sent every (aft
+### Disable resolve message + +When checked, this option will disable resolve message [OK] that is sent when alerting state returns to false. + ## Supported Notification Types Grafana ships with the following set of notification types: @@ -132,7 +136,7 @@ In DingTalk PC Client: 2. Click "Robot Manage" item in the pop menu, there will be a new panel call "Robot Manage". -3. In the "Robot Manage" panel, select "customised: customised robot with Webhook". +3. In the "Robot Manage" panel, select "customized: customized robot with Webhook". 4. In the next new panel named "robot detail", click "Add" button. diff --git a/docs/sources/auth/ldap.md b/docs/sources/auth/ldap.md index 4a884a60d15..d0ae9094d66 100644 --- a/docs/sources/auth/ldap.md +++ b/docs/sources/auth/ldap.md @@ -3,6 +3,7 @@ title = "LDAP Authentication" description = "Grafana LDAP Authentication Guide " keywords = ["grafana", "configuration", "documentation", "ldap", "active directory"] type = "docs" +aliases = ["/installation/ldap/"] [menu.docs] name = "LDAP" identifier = "ldap" @@ -162,9 +163,9 @@ org_role = "Viewer" Setting | Required | Description | Default ------------ | ------------ | ------------- | ------------- `group_dn` | Yes | LDAP distinguished name (DN) of LDAP group. If you want to match all (or no LDAP groups) then you can use wildcard (`"*"`) | -`org_role` | Yes | Assign users of `group_dn` the organisation role `"Admin"`, `"Editor"` or `"Viewer"` | +`org_role` | Yes | Assign users of `group_dn` the organization role `"Admin"`, `"Editor"` or `"Viewer"` | `org_id` | No | The Grafana organization database id. Setting this allows for multiple group_dn's to be assigned to the same `org_role` provided the `org_id` differs | `1` (default org id) -`grafana_admin` | No | When `true` makes user of `group_dn` Grafana server admin. A Grafana server admin has admin access over all organisations and users. Available in Grafana v5.3 and above | `false` +`grafana_admin` | No | When `true` makes user of `group_dn` Grafana server admin. A Grafana server admin has admin access over all organizations and users. Available in Grafana v5.3 and above | `false` ### Nested/recursive group membership diff --git a/docs/sources/contribute/cla.md b/docs/sources/contribute/cla.md index a073a9a4eae..9a78b651d28 100644 --- a/docs/sources/contribute/cla.md +++ b/docs/sources/contribute/cla.md @@ -1,6 +1,6 @@ +++ -title = "Contributor Licence Agreement (CLA)" -description = "Contributor Licence Agreement (CLA)" +title = "Contributor License Agreement (CLA)" +description = "Contributor License Agreement (CLA)" type = "docs" aliases = ["/project/cla", "docs/contributing/cla.html"] [menu.docs] diff --git a/docs/sources/enterprise/index.md b/docs/sources/enterprise/index.md index f65fa55f02b..5d524dcbee2 100644 --- a/docs/sources/enterprise/index.md +++ b/docs/sources/enterprise/index.md @@ -31,7 +31,7 @@ Datasource permissions allow you to restrict query access to only specific Teams ### Premium Plugins -With a Grafana Enterprise licence you will get access to premium plugins, including: +With a Grafana Enterprise license you will get access to premium plugins, including: * [Splunk](https://grafana.com/plugins/grafana-splunk-datasource) * [AppDynamics](https://grafana.com/plugins/dlopes7-appdynamics-datasource) diff --git a/docs/sources/features/datasources/mysql.md b/docs/sources/features/datasources/mysql.md index bc4e4df6cf9..371c92cde70 100644 --- a/docs/sources/features/datasources/mysql.md +++ b/docs/sources/features/datasources/mysql.md @@ -133,9 +133,9 @@ Macro example | Description ------------ | ------------- *$__time(dateColumn)* | Will be replaced by an expression to convert to a UNIX timestamp and rename the column to `time_sec`. For example, *UNIX_TIMESTAMP(dateColumn) as time_sec* *$__timeEpoch(dateColumn)* | Will be replaced by an expression to convert to a UNIX timestamp and rename the column to `time_sec`. For example, *UNIX_TIMESTAMP(dateColumn) as time_sec* -*$__timeFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name. For example, *dateColumn BETWEEN '2017-04-21T05:01:17Z' AND '2017-04-21T05:06:17Z'* -*$__timeFrom()* | Will be replaced by the start of the currently active time selection. For example, *'2017-04-21T05:01:17Z'* -*$__timeTo()* | Will be replaced by the end of the currently active time selection. For example, *'2017-04-21T05:06:17Z'* +*$__timeFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name. For example, *dateColumn BETWEEN FROM_UNIXTIME(1494410783) AND FROM_UNIXTIME(1494410983)* +*$__timeFrom()* | Will be replaced by the start of the currently active time selection. For example, *FROM_UNIXTIME(1494410783)* +*$__timeTo()* | Will be replaced by the end of the currently active time selection. For example, *FROM_UNIXTIME(1494410983)* *$__timeGroup(dateColumn,'5m')* | Will be replaced by an expression usable in GROUP BY clause. For example, *cast(cast(UNIX_TIMESTAMP(dateColumn)/(300) as signed)*300 as signed),* *$__timeGroup(dateColumn,'5m', 0)* | Same as above but with a fill parameter so missing points in that series will be added by grafana and 0 will be used as value. *$__timeGroup(dateColumn,'5m', NULL)* | Same as above but NULL will be used as value for missing points. diff --git a/docs/sources/guides/whats-new-in-v4.md b/docs/sources/guides/whats-new-in-v4.md index 7b0d2259580..1b4ed1c2a65 100644 --- a/docs/sources/guides/whats-new-in-v4.md +++ b/docs/sources/guides/whats-new-in-v4.md @@ -134,7 +134,7 @@ continue work on a `build mode` for a future release. The new row menu automatically slides out when you mouse over the edge of the row. You no longer need to hover over the small green icon and then click it to expand the row menu. -There are some minor improvements to drag and drop behaviour. Now when dragging a panel from one row +There are some minor improvements to drag and drop behavior. Now when dragging a panel from one row to another you will insert the panel and Grafana will automatically make room for it. When you drag a panel within a row you will simply reorder the panels. diff --git a/docs/sources/guides/whats-new-in-v5-4.md b/docs/sources/guides/whats-new-in-v5-4.md index e0a3fd5c4ba..18b7b61d621 100644 --- a/docs/sources/guides/whats-new-in-v5-4.md +++ b/docs/sources/guides/whats-new-in-v5-4.md @@ -12,6 +12,71 @@ weight = -10 # What's New in Grafana v5.4 +Grafana v5.4 brings new features, many enhancements and bug fixes. This article will detail the major new features and enhancements. + +- [Alerting]({{< relref "#alerting" >}}) Limit false positives with the new `For` setting +- [Google Stackdriver]({{< relref "#google-stackdriver" >}}) Now with support for templating queries +- [MySQL]({{< relref "#mysql-query-builder" >}}) gets a new query builder! +- [Graph Panel]({{< relref "#graph-panel-enhancements" >}}) Highlight time regions and more +- [Team Preferences]({{< relref "#team-preferences" >}}) Give your teams their own home dashboard + +## Alerting + +{{< docs-imagebox img="/img/docs/v54/alerting-for-dark-theme.png" max-width="600px" class="docs-image--right" >}} + +Grafana v5.4 ships with a new alert rule setting named `For` which is great for removing false positives. If an alert rule has a configured `For` and the query violates the configured threshold it will first go from `OK` to `Pending`. Going from `OK` to `Pending` Grafana will not send any notifications. Once the alert rule has been firing for more than `For` duration, it will change to `Alerting` and send alert notifications. Typically, it's always a good idea to use this setting since it's often worse to get false positive than wait a few minutes before the alert notification triggers. + +In the screenshot you can see an example timeline of an alert using the `For` setting. At ~16:04 the alert state changes to `Pending` and after 4 minutes it changes to `Alerting` which is when alert notifications are sent. Once the series falls back to normal the alert rule goes back to `OK`. [Learn more](/alerting/rules/#for). + +Additionally, there's now support for disable the sending of `OK` alert notifications. [Learn more](/alerting/notifications/#disable-resolve-message). + +
+ +## Google Stackdriver + +{{< docs-imagebox img="/img/docs/v54/stackdriver_template_query.png" max-width="600px" class="docs-image--right" >}} + +Grafana v5.3 included built-in support for [Google Stackdriver](https://cloud.google.com/stackdriver/) which enables you to visualize your Stackdriver metrics in Grafana. +One important feature missing was support for templating queries. This is now included together with a brand new templating query editor for Stackdriver. + +The Stackdriver templating query editor lets you choose from a set of different Query Types. This will in turn reveal additional drop downs to help you +find, filter and select the templating values you're interested in, see screenshot for details. The templating query editor also supports chaining multiple variables +making it easy to define variables that's dependent on other variables. + +Stackdriver is the first datasource which has support for a custom templating query editor. But starting from Grafana v5.4 it's now possible for all datasources, including plugin datasources, to +create their very own templating query editor. + +Additionally, if Grafana is running on a Google Compute Engine (GCE) virtual machine, it is now possible for Grafana to automatically retrieve default credentials from the metadata server. +This has the advantage of not needing to generate a private key file for the service account and also not having to upload the file to Grafana. [Learn more](/features/datasources/stackdriver/#using-gce-default-service-account). + +Please read [Using Google Stackdriver in Grafana](/features/datasources/stackdriver/) for more detailed information on how to get started and use it. + +
+ +## MySQL Query Builder + +Grafana v5.4 comes with a new graphical query builder for MySQL. This brings MySQL integration more in line with some of the other datasources and makes it easier for both advanced users and beginners to work with timeseries in MySQL. Learn more about it in the [documentation](/features/datasources/mysql/#query-editor). + +{{< docs-imagebox img="/img/docs/v54/mysql_query_still.png" animated-gif="/img/docs/v54/mysql_query.gif" >}} + +## Graph Panel Enhancements + +Grafana v5.4 adds support for highlighting weekdays and/or certain timespans in the graph panel. This should make it easier to compare for example weekends, business hours and/or off work hours. + +{{< docs-imagebox img="/img/docs/v54/graph_time_regions.png" max-width= "800px" >}} + +Additionally, when rendering series as lines in the graph panel, should there be only one data point available for one series so that a connecting line cannot be established, a point will +automatically be rendered for that data point. This should make it easier to understand what's going on when only receiving a single data point. + +{{< docs-imagebox img="/img/docs/v54/graph_dot_single_point.png" max-width= "800px" >}} + +## Team Preferences + +Grafana v5.4 adds support for customizing home dashboard, timezone and theme for teams, in addition to the existing customization on Organization and user Profile level. + +1. Specifying a preference on User Profile level will override preference on Team and/or Organization level +2. Specifying a preference on Team level will override preference on Organization level. + ## Changelog Checkout the [CHANGELOG.md](https://github.com/grafana/grafana/blob/master/CHANGELOG.md) file for a complete list diff --git a/docs/sources/http_api/alerting.md b/docs/sources/http_api/alerting.md index 2d70a6d2017..0684f65f166 100644 --- a/docs/sources/http_api/alerting.md +++ b/docs/sources/http_api/alerting.md @@ -160,11 +160,14 @@ Content-Type: application/json `POST /api/admin/pause-all-alerts` +Only works with Basic Authentication (username and password). See [introduction](http://docs.grafana.org/http_api/admin/#admin-api) for an explanation. + +**Example Request**: + ```http POST /api/admin/pause-all-alerts HTTP/1.1 Accept: application/json Content-Type: application/json -Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk { "paused": true diff --git a/docs/sources/http_api/index.md b/docs/sources/http_api/index.md index 2a74917a9fd..9e3d69363e8 100644 --- a/docs/sources/http_api/index.md +++ b/docs/sources/http_api/index.md @@ -26,7 +26,7 @@ dashboards, creating users and updating data sources. * [Folder Permissions API]({{< relref "http_api/folder_permissions.md" >}}) * [Folder/dashboard search API]({{< relref "/http_api/folder_dashboard_search.md" >}}) * [Data Source API]({{< relref "http_api/data_source.md" >}}) -* [Organisation API]({{< relref "http_api/org.md" >}}) +* [Organization API]({{< relref "http_api/org.md" >}}) * [Snapshot API]({{< relref "http_api/snapshot.md" >}}) * [Annotations API]({{< relref "http_api/annotations.md" >}}) * [Alerting API]({{< relref "http_api/alerting.md" >}}) diff --git a/docs/sources/http_api/org.md b/docs/sources/http_api/org.md index c55107d42f8..d1eb4ea0972 100644 --- a/docs/sources/http_api/org.md +++ b/docs/sources/http_api/org.md @@ -1,24 +1,24 @@ +++ -title = "Organisation HTTP API " -description = "Grafana Organisation HTTP API" -keywords = ["grafana", "http", "documentation", "api", "organisation"] -aliases = ["/http_api/organisation/"] +title = "Organization HTTP API " +description = "Grafana Organization HTTP API" +keywords = ["grafana", "http", "documentation", "api", "organization"] +aliases = ["/http_api/organization/"] type = "docs" [menu.docs] -name = "Organisation" +name = "Organization" parent = "http_api" +++ -# Organisation API +# Organization API -The Organisation HTTP API is divided in two resources, `/api/org` (current organisation) -and `/api/orgs` (admin organisations). One big difference between these are that -the admin of all organisations API only works with basic authentication, see [Admin Organisations API](#admin-organisations-api) for more information. +The Organization HTTP API is divided in two resources, `/api/org` (current organization) +and `/api/orgs` (admin organizations). One big difference between these are that +the admin of all organizations API only works with basic authentication, see [Admin Organizations API](#admin-organizations-api) for more information. -## Current Organisation API +## Current Organization API -### Get current Organisation +### Get current Organization `GET /api/org/` @@ -43,7 +43,7 @@ Content-Type: application/json } ``` -### Get all users within the current organisation +### Get all users within the current organization `GET /api/org/users` @@ -99,7 +99,7 @@ Content-Type: application/json {"message":"Organization user updated"} ``` -### Delete user in current organisation +### Delete user in current organization `DELETE /api/org/users/:userId` @@ -121,7 +121,7 @@ Content-Type: application/json {"message":"User removed from organization"} ``` -### Update current Organisation +### Update current Organization `PUT /api/org` @@ -147,11 +147,11 @@ Content-Type: application/json {"message":"Organization updated"} ``` -### Add a new user to the current organisation +### Add a new user to the current organization `POST /api/org/users` -Adds a global user to the current organisation. +Adds a global user to the current organization. **Example Request**: @@ -176,19 +176,19 @@ Content-Type: application/json {"message":"User added to organization"} ``` -## Admin Organisations API +## Admin Organizations API -The Admin Organisations HTTP API does not currently work with an API Token. API Tokens are currently +The Admin Organizations HTTP API does not currently work with an API Token. API Tokens are currently only linked to an organization and an organization role. They cannot be given the permission of server admin, only users can be given that permission. So in order to use these API calls you will have to use Basic Auth and the Grafana user must have the Grafana Admin permission (The default admin user is called `admin` and has permission to use this API). -### Get Organisation by Id +### Get Organization by Id `GET /api/orgs/:orgId` -Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api). +Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api). **Example Request**: @@ -217,11 +217,11 @@ Content-Type: application/json } } ``` -### Get Organisation by Name +### Get Organization by Name `GET /api/orgs/name/:orgName` -Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api). +Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api). **Example Request**: @@ -251,11 +251,11 @@ Content-Type: application/json } ``` -### Create Organisation +### Create Organization `POST /api/orgs` -Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api). +Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api). **Example Request**: @@ -284,11 +284,11 @@ Content-Type: application/json } ``` -### Search all Organisations +### Search all Organizations `GET /api/orgs` -Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api). +Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api). **Example Request**: @@ -314,12 +314,12 @@ Content-Type: application/json ] ``` -### Update Organisation +### Update Organization `PUT /api/orgs/:orgId` -Update Organisation, fields *Address 1*, *Address 2*, *City* are not implemented yet. -Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api). +Update Organization, fields *Address 1*, *Address 2*, *City* are not implemented yet. +Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api). **Example Request**: @@ -342,11 +342,11 @@ Content-Type: application/json {"message":"Organization updated"} ``` -### Delete Organisation +### Delete Organization `DELETE /api/orgs/:orgId` -Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api). +Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api). **Example Request**: @@ -364,11 +364,11 @@ Content-Type: application/json {"message":"Organization deleted"} ``` -### Get Users in Organisation +### Get Users in Organization `GET /api/orgs/:orgId/users` -Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api). +Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api). **Example Request**: @@ -397,11 +397,11 @@ Content-Type: application/json ] ``` -### Add User in Organisation +### Add User in Organization `POST /api/orgs/:orgId/users` -Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api). +Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api). **Example Request**: @@ -425,11 +425,11 @@ Content-Type: application/json {"message":"User added to organization"} ``` -### Update Users in Organisation +### Update Users in Organization `PATCH /api/orgs/:orgId/users/:userId` -Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api). +Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api). **Example Request**: @@ -452,11 +452,11 @@ Content-Type: application/json {"message":"Organization user updated"} ``` -### Delete User in Organisation +### Delete User in Organization `DELETE /api/orgs/:orgId/users/:userId` -Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api). +Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api). **Example Request**: diff --git a/docs/sources/http_api/user.md b/docs/sources/http_api/user.md index 047d4473603..a7b6c96aac5 100644 --- a/docs/sources/http_api/user.md +++ b/docs/sources/http_api/user.md @@ -196,7 +196,7 @@ Content-Type: application/json {"message":"User updated"} ``` -## Get Organisations for user +## Get Organizations for user `GET /api/users/:id/orgs` @@ -367,11 +367,11 @@ Content-Type: application/json {"message":"Active organization changed"} ``` -## Organisations of the actual User +## Organizations of the actual User `GET /api/user/orgs` -Return a list of all organisations of the current user. +Return a list of all organizations of the current user. **Example Request**: diff --git a/docs/sources/index.md b/docs/sources/index.md index e9a900d93f1..3e8e014e606 100644 --- a/docs/sources/index.md +++ b/docs/sources/index.md @@ -60,9 +60,9 @@ aliases = ["v1.1", "guides/reference/admin"]

Provisioning

A guide to help you automate your Grafana setup & configuration.

- }}" class="nav-cards__item nav-cards__item--guide"> -

What's new in v5.3

-

Article on all the new cool features and enhancements in v5.3

+
}}" class="nav-cards__item nav-cards__item--guide"> +

What's new in v5.4

+

Article on all the new cool features and enhancements in v5.4

}}" class="nav-cards__item nav-cards__item--guide">

Screencasts

diff --git a/docs/sources/reference/export_import.md b/docs/sources/reference/export_import.md index 31f32d890f6..501e9aca62b 100644 --- a/docs/sources/reference/export_import.md +++ b/docs/sources/reference/export_import.md @@ -107,3 +107,5 @@ it as usual and then update the data source option in the metrics tab so that th data source. Another alternative is to open the json file in a a text editor and update the data source properties to value that matches a name of your data source. +## Note +In Grafana v5.3.4+ the export modal has new checkbox for sharing for external use (other instances). If the checkbox is not checked then the `__inputs` section will not be included in the exported JSON file. diff --git a/docs/sources/reference/templating.md b/docs/sources/reference/templating.md index 403dabba8ae..f20cc0ccfc9 100644 --- a/docs/sources/reference/templating.md +++ b/docs/sources/reference/templating.md @@ -25,7 +25,7 @@ the value, using the dropdown at the top of the dashboard, your panel's metric q Panel titles and metric queries can refer to variables using two different syntaxes: -- `$` Example: apps.frontend.$server.requests.count +- `$varname` Example: apps.frontend.$server.requests.count - `[[varname]]` Example: apps.frontend.[[server]].requests.count Why two ways? The first syntax is easier to read and write but does not allow you to use a variable in the middle of word. Use diff --git a/docs/versions.json b/docs/versions.json index 48962a783ae..b1e447d5aa0 100644 --- a/docs/versions.json +++ b/docs/versions.json @@ -1,5 +1,6 @@ [ - { "version": "v5.3", "path": "/", "archived": false, "current": true }, + { "version": "v5.4", "path": "/", "archived": false, "current": true }, + { "version": "v5.3", "path": "/v5.3", "archived": true }, { "version": "v5.2", "path": "/v5.2", "archived": true }, { "version": "v5.1", "path": "/v5.1", "archived": true }, { "version": "v5.0", "path": "/v5.0", "archived": true }, diff --git a/latest.json b/latest.json index 5e72c11c1f2..d36158608bf 100644 --- a/latest.json +++ b/latest.json @@ -1,4 +1,4 @@ { - "stable": "5.3.4", - "testing": "5.3.4" + "stable": "5.4.0", + "testing": "5.4.0" } diff --git a/package.json b/package.json index 452e4ecb742..f8014197c4b 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,18 @@ "company": "Grafana Labs" }, "name": "grafana", - "version": "5.4.0-pre1", + "version": "5.5.0-pre1", "repository": { "type": "git", "url": "http://github.com/grafana/grafana.git" }, "devDependencies": { + "@babel/core": "^7.1.2", + "@rtsao/plugin-proposal-class-properties": "^7.0.1-patch.1", + "@babel/plugin-syntax-dynamic-import": "^7.0.0", + "@babel/preset-env": "^7.1.0", + "@babel/preset-react": "^7.0.0", + "@babel/preset-typescript": "^7.1.0", "@types/d3": "^4.10.1", "@types/enzyme": "^3.1.13", "@types/jest": "^23.3.2", @@ -21,10 +27,10 @@ "angular-mocks": "1.6.6", "autoprefixer": "^6.4.0", "axios": "^0.17.1", - "babel-core": "^6.26.0", - "babel-loader": "^7.1.4", - "babel-plugin-syntax-dynamic-import": "^6.18.0", - "babel-preset-es2015": "^6.24.1", + "babel-core": "^7.0.0-bridge", + "babel-jest": "^23.6.0", + "babel-loader": "^8.0.4", + "babel-plugin-angularjs-annotate": "^0.9.0", "clean-webpack-plugin": "^0.1.19", "css-loader": "^0.28.7", "enzyme": "^3.6.0", @@ -108,18 +114,9 @@ "precommit": "lint-staged && grunt precommit" }, "lint-staged": { - "*.{ts,tsx}": [ - "prettier --write", - "git add" - ], - "*.scss": [ - "prettier --write", - "git add" - ], - "*pkg/**/*.go": [ - "gofmt -w -s", - "git add" - ] + "*.{ts,tsx}": ["prettier --write", "git add"], + "*.scss": ["prettier --write", "git add"], + "*pkg/**/*.go": ["gofmt -w -s", "git add"] }, "prettier": { "trailingComma": "es5", @@ -128,13 +125,12 @@ }, "license": "Apache-2.0", "dependencies": { + "@babel/polyfill": "^7.0.0", "angular": "1.6.6", "angular-bindonce": "0.3.1", "angular-native-dragdrop": "1.2.2", "angular-route": "1.6.6", "angular-sanitize": "1.6.6", - "babel-jest": "^23.6.0", - "babel-polyfill": "^6.26.0", "baron": "^3.0.3", "brace": "^0.10.0", "classnames": "^2.2.5", @@ -156,8 +152,8 @@ "react-custom-scrollbars": "^4.2.1", "react-dom": "^16.6.3", "react-grid-layout": "0.16.6", - "react-highlight-words": "^0.10.0", "react-popper": "^1.3.0", + "react-highlight-words": "0.11.0", "react-redux": "^5.0.7", "react-select": "2.1.0", "react-sizeme": "^2.3.6", diff --git a/packaging/docker/Dockerfile b/packaging/docker/Dockerfile index dc8972b0ba0..4d4f6539972 100644 --- a/packaging/docker/Dockerfile +++ b/packaging/docker/Dockerfile @@ -25,7 +25,8 @@ ENV PATH=/usr/share/grafana/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bi WORKDIR $GF_PATHS_HOME -RUN apt-get update && apt-get install -qq -y libfontconfig ca-certificates curl && \ +RUN apt-get update && apt-get -y upgrade && \ + apt-get install -qq -y libfontconfig ca-certificates curl && \ apt-get autoremove -y && \ rm -rf /var/lib/apt/lists/* diff --git a/packaging/docker/build-enterprise.sh b/packaging/docker/build-enterprise.sh index e10e0d691e8..10c24784d5c 100755 --- a/packaging/docker/build-enterprise.sh +++ b/packaging/docker/build-enterprise.sh @@ -18,3 +18,8 @@ docker build \ . docker push "${_docker_repo}:${_grafana_tag}" + +if echo "$_raw_grafana_tag" | grep -q "^v" && echo "$_raw_grafana_tag" | grep -qv "beta"; then + docker tag "${_docker_repo}:${_grafana_tag}" "${_docker_repo}:latest" + docker push "${_docker_repo}:latest" +fi diff --git a/pkg/api/admin_users.go b/pkg/api/admin_users.go index dc3d390dda9..efc760d2b51 100644 --- a/pkg/api/admin_users.go +++ b/pkg/api/admin_users.go @@ -76,6 +76,7 @@ func AdminUpdateUserPassword(c *m.ReqContext, form dtos.AdminUpdateUserPasswordF c.JsonOK("User password updated") } +// PUT /api/admin/users/:id/permissions func AdminUpdateUserPermissions(c *m.ReqContext, form dtos.AdminUpdateUserPermissionsForm) { userID := c.ParamsInt64(":id") @@ -85,6 +86,11 @@ func AdminUpdateUserPermissions(c *m.ReqContext, form dtos.AdminUpdateUserPermis } if err := bus.Dispatch(&cmd); err != nil { + if err == m.ErrLastGrafanaAdmin { + c.JsonApiErr(400, m.ErrLastGrafanaAdmin.Error(), nil) + return + } + c.JsonApiErr(500, "Failed to update user permissions", err) return } diff --git a/pkg/api/admin_users_test.go b/pkg/api/admin_users_test.go new file mode 100644 index 00000000000..0b94a64b3fb --- /dev/null +++ b/pkg/api/admin_users_test.go @@ -0,0 +1,50 @@ +package api + +import ( + "testing" + + "github.com/grafana/grafana/pkg/api/dtos" + "github.com/grafana/grafana/pkg/bus" + m "github.com/grafana/grafana/pkg/models" + + . "github.com/smartystreets/goconvey/convey" +) + +func TestAdminApiEndpoint(t *testing.T) { + role := m.ROLE_ADMIN + Convey("Given a server admin attempts to remove themself as an admin", t, func() { + + updateCmd := dtos.AdminUpdateUserPermissionsForm{ + IsGrafanaAdmin: false, + } + + bus.AddHandler("test", func(cmd *m.UpdateUserPermissionsCommand) error { + return m.ErrLastGrafanaAdmin + }) + + putAdminScenario("When calling PUT on", "/api/admin/users/1/permissions", "/api/admin/users/:id/permissions", role, updateCmd, func(sc *scenarioContext) { + sc.fakeReqWithParams("PUT", sc.url, map[string]string{}).exec() + So(sc.resp.Code, ShouldEqual, 400) + }) + }) +} + +func putAdminScenario(desc string, url string, routePattern string, role m.RoleType, cmd dtos.AdminUpdateUserPermissionsForm, fn scenarioFunc) { + Convey(desc+" "+url, func() { + defer bus.ClearBusHandlers() + + sc := setupScenarioContext(url) + sc.defaultHandler = Wrap(func(c *m.ReqContext) { + sc.context = c + sc.context.UserId = TestUserID + sc.context.OrgId = TestOrgID + sc.context.OrgRole = role + + AdminUpdateUserPermissions(c, cmd) + }) + + sc.m.Put(routePattern, sc.defaultHandler) + + fn(sc) + }) +} diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go index 6abb72f1559..2789b0bf51e 100644 --- a/pkg/api/dashboard.go +++ b/pkg/api/dashboard.go @@ -277,10 +277,6 @@ func PostDashboard(c *m.ReqContext, cmd m.SaveDashboardCommand) Response { return Error(500, "Failed to save dashboard", err) } - if err == m.ErrDashboardFailedToUpdateAlertData { - return Error(500, "Invalid alert data. Cannot save dashboard", err) - } - c.TimeRequest(metrics.M_Api_Dashboard_Save) return JSON(200, util.DynMap{ "status": "success", diff --git a/pkg/api/dashboard_test.go b/pkg/api/dashboard_test.go index 2726623c242..8ee40920cbc 100644 --- a/pkg/api/dashboard_test.go +++ b/pkg/api/dashboard_test.go @@ -727,7 +727,6 @@ func TestDashboardApiEndpoint(t *testing.T) { {SaveError: m.ErrDashboardTitleEmpty, ExpectedStatusCode: 400}, {SaveError: m.ErrDashboardFolderCannotHaveParent, ExpectedStatusCode: 400}, {SaveError: alerting.ValidationError{Reason: "Mu"}, ExpectedStatusCode: 422}, - {SaveError: m.ErrDashboardFailedToUpdateAlertData, ExpectedStatusCode: 500}, {SaveError: m.ErrDashboardFailedGenerateUniqueUid, ExpectedStatusCode: 500}, {SaveError: m.ErrDashboardTypeMismatch, ExpectedStatusCode: 400}, {SaveError: m.ErrDashboardFolderWithSameNameAsDashboard, ExpectedStatusCode: 400}, diff --git a/pkg/api/password.go b/pkg/api/password.go index 7dd901c898e..4776c6a3064 100644 --- a/pkg/api/password.go +++ b/pkg/api/password.go @@ -4,10 +4,18 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/bus" m "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" ) func SendResetPasswordEmail(c *m.ReqContext, form dtos.SendResetPasswordEmailForm) Response { + if setting.LdapEnabled || setting.AuthProxyEnabled { + return Error(401, "Not allowed to reset password when LDAP or Auth Proxy is enabled", nil) + } + if setting.DisableLoginForm { + return Error(401, "Not allowed to reset password when login form is disabled", nil) + } + userQuery := m.GetUserByLoginQuery{LoginOrEmail: form.UserOrEmail} if err := bus.Dispatch(&userQuery); err != nil { diff --git a/pkg/api/pluginproxy/ds_auth_provider.go b/pkg/api/pluginproxy/ds_auth_provider.go index edf43085c7c..5c5776eec07 100644 --- a/pkg/api/pluginproxy/ds_auth_provider.go +++ b/pkg/api/pluginproxy/ds_auth_provider.go @@ -51,7 +51,7 @@ func ApplyRoute(ctx context.Context, req *http.Request, proxyPath string, route if token, err := tokenProvider.getAccessToken(data); err != nil { logger.Error("Failed to get access token", "error", err) } else { - req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token)) + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) } } @@ -60,7 +60,7 @@ func ApplyRoute(ctx context.Context, req *http.Request, proxyPath string, route if token, err := tokenProvider.getJwtAccessToken(ctx, data); err != nil { logger.Error("Failed to get access token", "error", err) } else { - req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token)) + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) } } @@ -73,7 +73,7 @@ func ApplyRoute(ctx context.Context, req *http.Request, proxyPath string, route if err != nil { logger.Error("Failed to get default access token from meta data server", "error", err) } else { - req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token.AccessToken)) + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token.AccessToken)) } } } diff --git a/pkg/api/pluginproxy/pluginproxy.go b/pkg/api/pluginproxy/pluginproxy.go index ffbe470cb20..66e4498c283 100644 --- a/pkg/api/pluginproxy/pluginproxy.go +++ b/pkg/api/pluginproxy/pluginproxy.go @@ -87,7 +87,7 @@ func NewApiPluginProxy(ctx *m.ReqContext, proxyPath string, route *plugins.AppPl } for key, value := range headers { - log.Trace("setting key %v value %v", key, value[0]) + log.Trace("setting key %v value ", key) req.Header.Set(key, value[0]) } } diff --git a/pkg/models/dashboards.go b/pkg/models/dashboards.go index e8aebb1d1f4..3a8010e797b 100644 --- a/pkg/models/dashboards.go +++ b/pkg/models/dashboards.go @@ -21,7 +21,6 @@ var ( ErrDashboardVersionMismatch = errors.New("The dashboard has been changed by someone else") ErrDashboardTitleEmpty = errors.New("Dashboard title cannot be empty") ErrDashboardFolderCannotHaveParent = errors.New("A Dashboard Folder cannot be added to another folder") - ErrDashboardFailedToUpdateAlertData = errors.New("Failed to save alert data") ErrDashboardsWithSameSlugExists = errors.New("Multiple dashboards with the same slug exists") ErrDashboardFailedGenerateUniqueUid = errors.New("Failed to generate unique dashboard id") ErrDashboardTypeMismatch = errors.New("Dashboard cannot be changed to a folder") diff --git a/pkg/models/user.go b/pkg/models/user.go index e3c7b556d35..69031e40338 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -7,7 +7,8 @@ import ( // Typed errors var ( - ErrUserNotFound = errors.New("User not found") + ErrUserNotFound = errors.New("User not found") + ErrLastGrafanaAdmin = errors.New("Cannot remove last grafana admin") ) type Password string diff --git a/pkg/services/dashboards/dashboard_service.go b/pkg/services/dashboards/dashboard_service.go index b52d1845a0b..7e334ff656f 100644 --- a/pkg/services/dashboards/dashboard_service.go +++ b/pkg/services/dashboards/dashboard_service.go @@ -165,7 +165,7 @@ func (dr *dashboardServiceImpl) updateAlerting(cmd *models.SaveDashboardCommand, } if err := bus.Dispatch(&alertCmd); err != nil { - return models.ErrDashboardFailedToUpdateAlertData + return err } return nil diff --git a/pkg/services/sqlstore/user.go b/pkg/services/sqlstore/user.go index 99a77ecabc3..a3ccb93b30c 100644 --- a/pkg/services/sqlstore/user.go +++ b/pkg/services/sqlstore/user.go @@ -504,8 +504,18 @@ func UpdateUserPermissions(cmd *m.UpdateUserPermissionsCommand) error { user.IsAdmin = cmd.IsGrafanaAdmin sess.UseBool("is_admin") + _, err := sess.ID(user.Id).Update(&user) - return err + if err != nil { + return err + } + + // validate that after update there is at least one server admin + if err := validateOneAdminLeft(sess); err != nil { + return err + } + + return nil }) } @@ -522,3 +532,17 @@ func SetUserHelpFlag(cmd *m.SetUserHelpFlagCommand) error { return err }) } + +func validateOneAdminLeft(sess *DBSession) error { + // validate that there is an admin user left + count, err := sess.Where("is_admin=?", true).Count(&m.User{}) + if err != nil { + return err + } + + if count == 0 { + return m.ErrLastGrafanaAdmin + } + + return nil +} diff --git a/pkg/services/sqlstore/user_test.go b/pkg/services/sqlstore/user_test.go index b26dd235772..627f2ab1ca5 100644 --- a/pkg/services/sqlstore/user_test.go +++ b/pkg/services/sqlstore/user_test.go @@ -155,6 +155,32 @@ func TestUserDataAccess(t *testing.T) { }) }) }) + + Convey("Given one grafana admin user", func() { + var err error + createUserCmd := &m.CreateUserCommand{ + Email: fmt.Sprint("admin", "@test.com"), + Name: fmt.Sprint("admin"), + Login: fmt.Sprint("admin"), + IsAdmin: true, + } + err = CreateUser(context.Background(), createUserCmd) + So(err, ShouldBeNil) + + Convey("Cannot make themselves a non-admin", func() { + updateUserPermsCmd := m.UpdateUserPermissionsCommand{IsGrafanaAdmin: false, UserId: 1} + updatePermsError := UpdateUserPermissions(&updateUserPermsCmd) + + So(updatePermsError, ShouldEqual, m.ErrLastGrafanaAdmin) + + query := m.GetUserByIdQuery{Id: createUserCmd.Result.Id} + getUserError := GetUserById(&query) + + So(getUserError, ShouldBeNil) + + So(query.Result.IsAdmin, ShouldEqual, true) + }) + }) }) } diff --git a/pkg/tsdb/cloudwatch/metric_find_query.go b/pkg/tsdb/cloudwatch/metric_find_query.go index 76eadf1c8dc..dd026bbb79e 100644 --- a/pkg/tsdb/cloudwatch/metric_find_query.go +++ b/pkg/tsdb/cloudwatch/metric_find_query.go @@ -47,6 +47,7 @@ func init() { "AWS/CloudFront": {"Requests", "BytesDownloaded", "BytesUploaded", "TotalErrorRate", "4xxErrorRate", "5xxErrorRate"}, "AWS/CloudSearch": {"SuccessfulRequests", "SearchableDocuments", "IndexUtilization", "Partitions"}, "AWS/CloudHSM": {"HsmUnhealthy", "HsmTemperature", "HsmKeysSessionOccupied", "HsmKeysTokenOccupied", "HsmSslCtxsOccupied", "HsmSessionCount", "HsmUsersAvailable", "HsmUsersMax", "InterfaceEth2OctetsInput", "InterfaceEth2OctetsOutput"}, + "AWS/CodeBuild": {"BuildDuration", "Builds", "DownloadSourceDuration", "Duration", "FailedBuilds", "FinalizingDuration", "InstallDuration", "PostBuildDuration", "PreBuildDuration", "ProvisioningDuration", "QueuedDuration", "SubmittedDuration", "SucceededBuilds", "UploadArtifactsDuration"}, "AWS/Connect": {"CallsBreachingConcurrencyQuota", "CallBackNotDialableNumber", "CallRecordingUploadError", "CallsPerInterval", "ConcurrentCalls", "ConcurrentCallsPercentage", "ContactFlowErrors", "ContactFlowFatalErrors", "LongestQueueWaitTime", "MissedCalls", "MisconfiguredPhoneNumbers", "PublicSigningKeyUsage", "QueueCapacityExceededError", "QueueSize", "ThrottledCalls", "ToInstancePacketLossRate"}, "AWS/DMS": {"FreeableMemory", "WriteIOPS", "ReadIOPS", "WriteThroughput", "ReadThroughput", "WriteLatency", "ReadLatency", "SwapUsage", "NetworkTransmitThroughput", "NetworkReceiveThroughput", "FullLoadThroughputBandwidthSource", "FullLoadThroughputBandwidthTarget", "FullLoadThroughputRowsSource", "FullLoadThroughputRowsTarget", "CDCIncomingChanges", "CDCChangesMemorySource", "CDCChangesMemoryTarget", "CDCChangesDiskSource", "CDCChangesDiskTarget", "CDCThroughputBandwidthTarget", "CDCThroughputRowsSource", "CDCThroughputRowsTarget", "CDCLatencySource", "CDCLatencyTarget"}, "AWS/DX": {"ConnectionState", "ConnectionBpsEgress", "ConnectionBpsIngress", "ConnectionPpsEgress", "ConnectionPpsIngress", "ConnectionCRCErrorCount", "ConnectionLightLevelTx", "ConnectionLightLevelRx"}, @@ -123,6 +124,7 @@ func init() { "AWS/CloudFront": {"DistributionId", "Region"}, "AWS/CloudSearch": {}, "AWS/CloudHSM": {"Region", "ClusterId", "HsmId"}, + "AWS/CodeBuild": {"ProjectName"}, "AWS/Connect": {"InstanceId", "MetricGroup", "Participant", "QueueName", "Stream Type", "Type of Connection"}, "AWS/DMS": {"ReplicationInstanceIdentifier", "ReplicationTaskIdentifier"}, "AWS/DX": {"ConnectionId"}, diff --git a/pkg/tsdb/elasticsearch/client/client.go b/pkg/tsdb/elasticsearch/client/client.go index 4ebe0db8f89..f5a200f60ce 100644 --- a/pkg/tsdb/elasticsearch/client/client.go +++ b/pkg/tsdb/elasticsearch/client/client.go @@ -65,7 +65,7 @@ var NewClient = func(ctx context.Context, ds *models.DataSource, timeRange *tsdb clientLog.Debug("Creating new client", "version", version, "timeField", timeField, "indices", strings.Join(indices, ", ")) switch version { - case 2, 5, 56: + case 2, 5, 56, 60: return &baseClientImpl{ ctx: ctx, ds: ds, diff --git a/pkg/tsdb/elasticsearch/client/client_test.go b/pkg/tsdb/elasticsearch/client/client_test.go index 540a999688a..7002aa5db4f 100644 --- a/pkg/tsdb/elasticsearch/client/client_test.go +++ b/pkg/tsdb/elasticsearch/client/client_test.go @@ -90,6 +90,19 @@ func TestClient(t *testing.T) { So(err, ShouldBeNil) So(c.GetVersion(), ShouldEqual, 56) }) + + Convey("When version 60 should return v6.0 client", func() { + ds := &models.DataSource{ + JsonData: simplejson.NewFromAny(map[string]interface{}{ + "esVersion": 60, + "timeField": "@timestamp", + }), + } + + c, err := NewClient(context.Background(), ds, nil) + So(err, ShouldBeNil) + So(c.GetVersion(), ShouldEqual, 60) + }) }) Convey("Given a fake http client", func() { @@ -153,8 +166,6 @@ func TestClient(t *testing.T) { jBody, err := simplejson.NewJson(bodyBytes) So(err, ShouldBeNil) - fmt.Println("body", string(headerBytes)) - So(jHeader.Get("index").MustString(), ShouldEqual, "metrics-2018.05.15") So(jHeader.Get("ignore_unavailable").MustBool(false), ShouldEqual, true) So(jHeader.Get("search_type").MustString(), ShouldEqual, "count") @@ -209,8 +220,6 @@ func TestClient(t *testing.T) { jBody, err := simplejson.NewJson(bodyBytes) So(err, ShouldBeNil) - fmt.Println("body", string(headerBytes)) - So(jHeader.Get("index").MustString(), ShouldEqual, "metrics-2018.05.15") So(jHeader.Get("ignore_unavailable").MustBool(false), ShouldEqual, true) So(jHeader.Get("search_type").MustString(), ShouldEqual, "query_then_fetch") @@ -265,8 +274,6 @@ func TestClient(t *testing.T) { jBody, err := simplejson.NewJson(bodyBytes) So(err, ShouldBeNil) - fmt.Println("body", string(headerBytes)) - So(jHeader.Get("index").MustString(), ShouldEqual, "metrics-2018.05.15") So(jHeader.Get("ignore_unavailable").MustBool(false), ShouldEqual, true) So(jHeader.Get("search_type").MustString(), ShouldEqual, "query_then_fetch") diff --git a/pkg/tsdb/elasticsearch/client/models.go b/pkg/tsdb/elasticsearch/client/models.go index a0d257d01a6..5307dc34b27 100644 --- a/pkg/tsdb/elasticsearch/client/models.go +++ b/pkg/tsdb/elasticsearch/client/models.go @@ -240,6 +240,7 @@ type DateHistogramAgg struct { Missing *string `json:"missing,omitempty"` ExtendedBounds *ExtendedBounds `json:"extended_bounds"` Format string `json:"format"` + Offset string `json:"offset,omitempty"` } // FiltersAggregation represents a filters aggregation diff --git a/pkg/tsdb/elasticsearch/time_series_query.go b/pkg/tsdb/elasticsearch/time_series_query.go index 869e23e21ce..a25c3cf693d 100644 --- a/pkg/tsdb/elasticsearch/time_series_query.go +++ b/pkg/tsdb/elasticsearch/time_series_query.go @@ -134,6 +134,10 @@ func addDateHistogramAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg, timeFro a.Interval = "$__interval" } + if offset, err := bucketAgg.Settings.Get("offset").String(); err == nil { + a.Offset = offset + } + if missing, err := bucketAgg.Settings.Get("missing").String(); err == nil { a.Missing = &missing } diff --git a/pkg/tsdb/mssql/macros.go b/pkg/tsdb/mssql/macros.go index 0a260f7ad70..dac18f3ac03 100644 --- a/pkg/tsdb/mssql/macros.go +++ b/pkg/tsdb/mssql/macros.go @@ -66,6 +66,10 @@ func (m *msSqlMacroEngine) evaluateMacro(name string, args []string) (string, er } return fmt.Sprintf("%s BETWEEN '%s' AND '%s'", args[0], m.timeRange.GetFromAsTimeUTC().Format(time.RFC3339), m.timeRange.GetToAsTimeUTC().Format(time.RFC3339)), nil + case "__timeFrom": + return fmt.Sprintf("'%s'", m.timeRange.GetFromAsTimeUTC().Format(time.RFC3339)), nil + case "__timeTo": + return fmt.Sprintf("'%s'", m.timeRange.GetToAsTimeUTC().Format(time.RFC3339)), nil case "__timeGroup": if len(args) < 2 { return "", fmt.Errorf("macro %v needs time column and interval", name) diff --git a/pkg/tsdb/mssql/macros_test.go b/pkg/tsdb/mssql/macros_test.go index 7456238efa4..43cbe9fefda 100644 --- a/pkg/tsdb/mssql/macros_test.go +++ b/pkg/tsdb/mssql/macros_test.go @@ -52,6 +52,20 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("WHERE time_column BETWEEN '%s' AND '%s'", from.Format(time.RFC3339), to.Format(time.RFC3339))) }) + Convey("interpolate __timeFrom function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__timeFrom()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, "select '2018-04-12T18:00:00Z'") + }) + + Convey("interpolate __timeTo function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__timeTo()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, "select '2018-04-12T18:05:00Z'") + }) + Convey("interpolate __timeGroup function", func() { sql, err := engine.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column,'5m')") So(err, ShouldBeNil) diff --git a/pkg/tsdb/mysql/macros.go b/pkg/tsdb/mysql/macros.go index 839f805568e..c0ed64aa65c 100644 --- a/pkg/tsdb/mysql/macros.go +++ b/pkg/tsdb/mysql/macros.go @@ -61,6 +61,10 @@ func (m *mySqlMacroEngine) evaluateMacro(name string, args []string) (string, er } return fmt.Sprintf("%s BETWEEN FROM_UNIXTIME(%d) AND FROM_UNIXTIME(%d)", args[0], m.timeRange.GetFromAsSecondsEpoch(), m.timeRange.GetToAsSecondsEpoch()), nil + case "__timeFrom": + return fmt.Sprintf("FROM_UNIXTIME(%d)", m.timeRange.GetFromAsSecondsEpoch()), nil + case "__timeTo": + return fmt.Sprintf("FROM_UNIXTIME(%d)", m.timeRange.GetToAsSecondsEpoch()), nil case "__timeGroup": if len(args) < 2 { return "", fmt.Errorf("macro %v needs time column and interval", name) diff --git a/pkg/tsdb/mysql/macros_test.go b/pkg/tsdb/mysql/macros_test.go index 24bf18873d5..49633347a4c 100644 --- a/pkg/tsdb/mysql/macros_test.go +++ b/pkg/tsdb/mysql/macros_test.go @@ -63,6 +63,20 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("WHERE time_column BETWEEN FROM_UNIXTIME(%d) AND FROM_UNIXTIME(%d)", from.Unix(), to.Unix())) }) + Convey("interpolate __timeFrom function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__timeFrom()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select FROM_UNIXTIME(%d)", from.Unix())) + }) + + Convey("interpolate __timeTo function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__timeTo()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select FROM_UNIXTIME(%d)", to.Unix())) + }) + Convey("interpolate __unixEpochFilter function", func() { sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilter(time)") So(err, ShouldBeNil) diff --git a/pkg/tsdb/mysql/mysql_test.go b/pkg/tsdb/mysql/mysql_test.go index 476e3ba6586..fe59a4b9d9d 100644 --- a/pkg/tsdb/mysql/mysql_test.go +++ b/pkg/tsdb/mysql/mysql_test.go @@ -761,7 +761,7 @@ func TestMySQL(t *testing.T) { { DataSource: &models.DataSource{JsonData: simplejson.New()}, Model: simplejson.NewFromAny(map[string]interface{}{ - "rawSql": `SELECT time FROM metric_values WHERE time > $__timeFrom() OR time < $__timeFrom() OR 1 < $__unixEpochFrom() OR $__unixEpochTo() > 1 ORDER BY 1`, + "rawSql": `SELECT time FROM metric_values WHERE time > $__timeFrom() OR time < $__timeTo() OR 1 < $__unixEpochFrom() OR $__unixEpochTo() > 1 ORDER BY 1`, "format": "time_series", }), RefId: "A", @@ -773,7 +773,7 @@ func TestMySQL(t *testing.T) { So(err, ShouldBeNil) queryResult := resp.Results["A"] So(queryResult.Error, ShouldBeNil) - So(queryResult.Meta.Get("sql").MustString(), ShouldEqual, "SELECT time FROM metric_values WHERE time > '2018-03-15T12:55:00Z' OR time < '2018-03-15T12:55:00Z' OR 1 < 1521118500 OR 1521118800 > 1 ORDER BY 1") + So(queryResult.Meta.Get("sql").MustString(), ShouldEqual, "SELECT time FROM metric_values WHERE time > FROM_UNIXTIME(1521118500) OR time < FROM_UNIXTIME(1521118800) OR 1 < 1521118500 OR 1521118800 > 1 ORDER BY 1") }) diff --git a/pkg/tsdb/postgres/macros.go b/pkg/tsdb/postgres/macros.go index 0fa5d8077e1..26a3d1e53ee 100644 --- a/pkg/tsdb/postgres/macros.go +++ b/pkg/tsdb/postgres/macros.go @@ -87,6 +87,10 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string, } return fmt.Sprintf("%s BETWEEN '%s' AND '%s'", args[0], m.timeRange.GetFromAsTimeUTC().Format(time.RFC3339), m.timeRange.GetToAsTimeUTC().Format(time.RFC3339)), nil + case "__timeFrom": + return fmt.Sprintf("'%s'", m.timeRange.GetFromAsTimeUTC().Format(time.RFC3339)), nil + case "__timeTo": + return fmt.Sprintf("'%s'", m.timeRange.GetToAsTimeUTC().Format(time.RFC3339)), nil case "__timeGroup": if len(args) < 2 { return "", fmt.Errorf("macro %v needs time column and interval and optional fill value", name) diff --git a/pkg/tsdb/postgres/macros_test.go b/pkg/tsdb/postgres/macros_test.go index 8a3699f82b2..6a71caedeb9 100644 --- a/pkg/tsdb/postgres/macros_test.go +++ b/pkg/tsdb/postgres/macros_test.go @@ -44,6 +44,20 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("WHERE time_column BETWEEN '%s' AND '%s'", from.Format(time.RFC3339), to.Format(time.RFC3339))) }) + Convey("interpolate __timeFrom function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__timeFrom()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, "select '2018-04-12T18:00:00Z'") + }) + + Convey("interpolate __timeTo function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__timeTo()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, "select '2018-04-12T18:05:00Z'") + }) + Convey("interpolate __timeGroup function pre 5.3 compatibility", func() { sql, err := engine.Interpolate(query, timeRange, "SELECT $__timeGroup(time_column,'5m'), value") diff --git a/pkg/tsdb/sql_engine.go b/pkg/tsdb/sql_engine.go index 1a4e2bd3943..ab7230e9b02 100644 --- a/pkg/tsdb/sql_engine.go +++ b/pkg/tsdb/sql_engine.go @@ -196,8 +196,6 @@ var Interpolate = func(query *Query, timeRange *TimeRange, sql string) (string, sql = strings.Replace(sql, "$__interval_ms", strconv.FormatInt(interval.Milliseconds(), 10), -1) sql = strings.Replace(sql, "$__interval", interval.Text, -1) - sql = strings.Replace(sql, "$__timeFrom()", fmt.Sprintf("'%s'", timeRange.GetFromAsTimeUTC().Format(time.RFC3339)), -1) - sql = strings.Replace(sql, "$__timeTo()", fmt.Sprintf("'%s'", timeRange.GetToAsTimeUTC().Format(time.RFC3339)), -1) sql = strings.Replace(sql, "$__unixEpochFrom()", fmt.Sprintf("%d", timeRange.GetFromAsSecondsEpoch()), -1) sql = strings.Replace(sql, "$__unixEpochTo()", fmt.Sprintf("%d", timeRange.GetToAsSecondsEpoch()), -1) diff --git a/pkg/tsdb/sql_engine_test.go b/pkg/tsdb/sql_engine_test.go index bfcc82aac47..bc77a95734d 100644 --- a/pkg/tsdb/sql_engine_test.go +++ b/pkg/tsdb/sql_engine_test.go @@ -44,20 +44,6 @@ func TestSqlEngine(t *testing.T) { So(sql, ShouldEqual, "select 60000 ") }) - Convey("interpolate __timeFrom function", func() { - sql, err := Interpolate(query, timeRange, "select $__timeFrom()") - So(err, ShouldBeNil) - - So(sql, ShouldEqual, fmt.Sprintf("select '%s'", from.Format(time.RFC3339))) - }) - - Convey("interpolate __timeTo function", func() { - sql, err := Interpolate(query, timeRange, "select $__timeTo()") - So(err, ShouldBeNil) - - So(sql, ShouldEqual, fmt.Sprintf("select '%s'", to.Format(time.RFC3339))) - }) - Convey("interpolate __unixEpochFrom function", func() { sql, err := Interpolate(query, timeRange, "select $__unixEpochFrom()") So(err, ShouldBeNil) diff --git a/public/app/app.ts b/public/app/app.ts index 9647fbe5416..2b94ec0fe33 100644 --- a/public/app/app.ts +++ b/public/app/app.ts @@ -1,4 +1,4 @@ -import 'babel-polyfill'; +import '@babel/polyfill'; import 'file-saver'; import 'lodash'; import 'jquery'; diff --git a/public/app/core/components/code_editor/theme-grafana-dark.js b/public/app/core/components/code_editor/theme-grafana-dark.js index a48715e698e..33d4a84b527 100644 --- a/public/app/core/components/code_editor/theme-grafana-dark.js +++ b/public/app/core/components/code_editor/theme-grafana-dark.js @@ -14,7 +14,7 @@ ace.define("ace/theme/grafana-dark",["require","exports","module","ace/lib/dom"] background: #555651\ }\ .gf-code-dark {\ - background-color: #111;\ + background-color: #09090b;\ color: #e0e0e0\ }\ .gf-code-dark .ace_cursor {\ diff --git a/public/app/core/controllers/reset_password_ctrl.ts b/public/app/core/controllers/reset_password_ctrl.ts index 933655399e8..9ad6864ece2 100644 --- a/public/app/core/controllers/reset_password_ctrl.ts +++ b/public/app/core/controllers/reset_password_ctrl.ts @@ -1,4 +1,5 @@ import coreModule from '../core_module'; +import config from 'app/core/config'; export class ResetPasswordCtrl { /** @ngInject */ @@ -6,6 +7,9 @@ export class ResetPasswordCtrl { contextSrv.sidemenu = false; $scope.formModel = {}; $scope.mode = 'send'; + $scope.ldapEnabled = config.ldapEnabled; + $scope.authProxyEnabled = config.authProxyEnabled; + $scope.disableLoginForm = config.disableLoginForm; const params = $location.search(); if (params.code) { diff --git a/public/app/core/logs_model.ts b/public/app/core/logs_model.ts index 21f518a682b..1efe26d28ef 100644 --- a/public/app/core/logs_model.ts +++ b/public/app/core/logs_model.ts @@ -3,25 +3,26 @@ import { TimeSeries } from 'app/core/core'; import colors from 'app/core/utils/colors'; export enum LogLevel { - crit = 'crit', - warn = 'warn', + crit = 'critical', + critical = 'critical', + warn = 'warning', + warning = 'warning', err = 'error', error = 'error', info = 'info', debug = 'debug', trace = 'trace', - none = 'none', + unkown = 'unkown', } export const LogLevelColor = { - [LogLevel.crit]: colors[7], - [LogLevel.warn]: colors[1], - [LogLevel.err]: colors[4], + [LogLevel.critical]: colors[7], + [LogLevel.warning]: colors[1], [LogLevel.error]: colors[4], [LogLevel.info]: colors[0], - [LogLevel.debug]: colors[3], - [LogLevel.trace]: colors[3], - [LogLevel.none]: '#eee', + [LogLevel.debug]: colors[5], + [LogLevel.trace]: colors[2], + [LogLevel.unkown]: '#ddd', }; export interface LogSearchMatch { @@ -34,22 +35,37 @@ export interface LogRow { duplicates?: number; entry: string; key: string; // timestamp + labels - labels: string; + labels: LogsStreamLabels; logLevel: LogLevel; searchWords?: string[]; timestamp: string; // ISO with nanosec precision timeFromNow: string; timeEpochMs: number; timeLocal: string; - uniqueLabels?: string; + uniqueLabels?: LogsStreamLabels; +} + +export interface LogsLabelStat { + active?: boolean; + count: number; + proportion: number; + value: string; +} + +export enum LogsMetaKind { + Number, + String, + LabelsMap, } export interface LogsMetaItem { label: string; - value: string; + value: string | number | LogsStreamLabels; + kind: LogsMetaKind; } export interface LogsModel { + id: string; // Identify one logs result from another meta?: LogsMetaItem[]; rows: LogRow[]; series?: TimeSeries[]; @@ -60,7 +76,7 @@ export interface LogsStream { entries: LogsStreamEntry[]; search?: string; parsedLabels?: LogsStreamLabels; - uniqueLabels?: string; + uniqueLabels?: LogsStreamLabels; } export interface LogsStreamEntry { @@ -79,6 +95,22 @@ export enum LogsDedupStrategy { signature = 'signature', } +export function calculateLogsLabelStats(rows: LogRow[], label: string): LogsLabelStat[] { + // Consider only rows that have the given label + const rowsWithLabel = rows.filter(row => row.labels[label] !== undefined); + const rowCount = rowsWithLabel.length; + + // Get label value counts for eligible rows + const countsByValue = _.countBy(rowsWithLabel, row => (row as LogRow).labels[label]); + const sortedCounts = _.chain(countsByValue) + .map((count, value) => ({ count, value, proportion: count / rowCount })) + .sortBy('count') + .reverse() + .value(); + + return sortedCounts; +} + const isoDateRegexp = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-6]\d[,\.]\d+([+-][0-2]\d:[0-5]\d|Z)/g; function isDuplicateRow(row: LogRow, other: LogRow, strategy: LogsDedupStrategy): boolean { switch (strategy) { @@ -119,6 +151,24 @@ export function dedupLogRows(logs: LogsModel, strategy: LogsDedupStrategy): Logs }; } +export function filterLogLevels(logs: LogsModel, hiddenLogLevels: Set): LogsModel { + if (hiddenLogLevels.size === 0) { + return logs; + } + + const filteredRows = logs.rows.reduce((result: LogRow[], row: LogRow, index, list) => { + if (!hiddenLogLevels.has(row.logLevel)) { + result.push(row); + } + return result; + }, []); + + return { + ...logs, + rows: filteredRows, + }; +} + export function makeSeriesForLogs(rows: LogRow[], intervalMs: number): TimeSeries[] { // Graph time series by log level const seriesByLevel = {}; diff --git a/public/app/core/specs/logs_model.test.ts b/public/app/core/specs/logs_model.test.ts index 5e427468339..22673278b13 100644 --- a/public/app/core/specs/logs_model.test.ts +++ b/public/app/core/specs/logs_model.test.ts @@ -1,4 +1,4 @@ -import { dedupLogRows, LogsDedupStrategy, LogsModel } from '../logs_model'; +import { calculateLogsLabelStats, dedupLogRows, LogsDedupStrategy, LogsModel } from '../logs_model'; describe('dedupLogRows()', () => { test('should return rows as is when dedup is set to none', () => { @@ -106,3 +106,56 @@ describe('dedupLogRows()', () => { ]); }); }); + +describe('calculateLogsLabelStats()', () => { + test('should return no stats for empty rows', () => { + expect(calculateLogsLabelStats([], '')).toEqual([]); + }); + + test('should return no stats of label is not found', () => { + const rows = [ + { + entry: 'foo 1', + labels: { + foo: 'bar', + }, + }, + ]; + + expect(calculateLogsLabelStats(rows as any, 'baz')).toEqual([]); + }); + + test('should return stats for found labels', () => { + const rows = [ + { + entry: 'foo 1', + labels: { + foo: 'bar', + }, + }, + { + entry: 'foo 0', + labels: { + foo: 'xxx', + }, + }, + { + entry: 'foo 2', + labels: { + foo: 'bar', + }, + }, + ]; + + expect(calculateLogsLabelStats(rows as any, 'foo')).toMatchObject([ + { + value: 'bar', + count: 2, + }, + { + value: 'xxx', + count: 1, + }, + ]); + }); +}); diff --git a/public/app/core/utils/explore.test.ts b/public/app/core/utils/explore.test.ts index 37d3d3bfac9..7ceebbd8047 100644 --- a/public/app/core/utils/explore.test.ts +++ b/public/app/core/utils/explore.test.ts @@ -16,7 +16,7 @@ const DEFAULT_EXPLORE_STATE: ExploreState = { datasourceMissing: false, datasourceName: '', exploreDatasources: [], - graphRange: DEFAULT_RANGE, + graphInterval: 1000, history: [], initialQueries: [], queryTransactions: [], diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index 9ecc36a192f..e268508b833 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -1,7 +1,10 @@ +import _ from 'lodash'; + import { renderUrl } from 'app/core/utils/url'; -import { ExploreState, ExploreUrlState, HistoryItem } from 'app/types/explore'; +import { ExploreState, ExploreUrlState, HistoryItem, QueryTransaction } from 'app/types/explore'; import { DataQuery, RawTimeRange } from 'app/types/series'; +import TableModel, { mergeTablesIntoModel } from 'app/core/table_model'; import kbn from 'app/core/utils/kbn'; import colors from 'app/core/utils/colors'; import TimeSeries from 'app/core/time_series2'; @@ -127,10 +130,44 @@ export function ensureQueries(queries?: DataQuery[]): DataQuery[] { } /** - * A target is non-empty when it has keys other than refId and key. + * A target is non-empty when it has keys (with non-empty values) other than refId and key. */ export function hasNonEmptyQuery(queries: DataQuery[]): boolean { - return queries.some(query => Object.keys(query).length > 2); + return queries.some( + query => + Object.keys(query) + .map(k => query[k]) + .filter(v => v).length > 2 + ); +} + +export function calculateResultsFromQueryTransactions( + queryTransactions: QueryTransaction[], + datasource: any, + graphInterval: number +) { + const graphResult = _.flatten( + queryTransactions.filter(qt => qt.resultType === 'Graph' && qt.done && qt.result).map(qt => qt.result) + ); + const tableResult = mergeTablesIntoModel( + new TableModel(), + ...queryTransactions.filter(qt => qt.resultType === 'Table' && qt.done && qt.result).map(qt => qt.result) + ); + const logsResult = + datasource && datasource.mergeStreams + ? datasource.mergeStreams( + _.flatten( + queryTransactions.filter(qt => qt.resultType === 'Logs' && qt.done && qt.result).map(qt => qt.result) + ), + graphInterval + ) + : undefined; + + return { + graphResult, + tableResult, + logsResult, + }; } export function getIntervals( diff --git a/public/app/core/utils/kbn.ts b/public/app/core/utils/kbn.ts index 37f1a609652..30fdf2bac6f 100644 --- a/public/app/core/utils/kbn.ts +++ b/public/app/core/utils/kbn.ts @@ -429,10 +429,16 @@ kbn.valueFormats.hex0x = (value, decimals) => { }; kbn.valueFormats.sci = (value, decimals) => { + if (value == null) { + return ''; + } return value.toExponential(decimals); }; kbn.valueFormats.locale = (value, decimals) => { + if (value == null) { + return ''; + } return value.toLocaleString(undefined, { maximumFractionDigits: decimals }); }; @@ -585,8 +591,8 @@ kbn.valueFormats.flowcms = kbn.formatBuilders.fixedUnit('cms'); kbn.valueFormats.flowcfs = kbn.formatBuilders.fixedUnit('cfs'); kbn.valueFormats.flowcfm = kbn.formatBuilders.fixedUnit('cfm'); kbn.valueFormats.litreh = kbn.formatBuilders.fixedUnit('l/h'); -kbn.valueFormats.flowlpm = kbn.formatBuilders.decimalSIPrefix('l/min'); -kbn.valueFormats.flowmlpm = kbn.formatBuilders.decimalSIPrefix('mL/min', -1); +kbn.valueFormats.flowlpm = kbn.formatBuilders.fixedUnit('l/min'); +kbn.valueFormats.flowmlpm = kbn.formatBuilders.fixedUnit('mL/min'); // Angle kbn.valueFormats.degree = kbn.formatBuilders.fixedUnit('°'); diff --git a/public/app/core/utils/text.test.ts b/public/app/core/utils/text.test.ts index 4f9d8367218..206e8507f9d 100644 --- a/public/app/core/utils/text.test.ts +++ b/public/app/core/utils/text.test.ts @@ -16,9 +16,20 @@ describe('findMatchesInText()', () => { expect(findMatchesInText(' foo ', 'foo')).toEqual([{ length: 3, start: 1, text: 'foo', end: 4 }]); }); - expect(findMatchesInText(' foo foo bar ', 'foo|bar')).toEqual([ - { length: 3, start: 1, text: 'foo', end: 4 }, - { length: 3, start: 5, text: 'foo', end: 8 }, - { length: 3, start: 9, text: 'bar', end: 12 }, - ]); + test('should find all matches for a complete regex', () => { + expect(findMatchesInText(' foo foo bar ', 'foo|bar')).toEqual([ + { length: 3, start: 1, text: 'foo', end: 4 }, + { length: 3, start: 5, text: 'foo', end: 8 }, + { length: 3, start: 9, text: 'bar', end: 12 }, + ]); + }); + + test('not fail on incomplete regex', () => { + expect(findMatchesInText(' foo foo bar ', 'foo|')).toEqual([ + { length: 3, start: 1, text: 'foo', end: 4 }, + { length: 3, start: 5, text: 'foo', end: 8 }, + ]); + expect(findMatchesInText('foo foo bar', '(')).toEqual([]); + expect(findMatchesInText('foo foo bar', '(foo|')).toEqual([]); + }); }); diff --git a/public/app/core/utils/text.ts b/public/app/core/utils/text.ts index 5d7591a31e2..4e948116dba 100644 --- a/public/app/core/utils/text.ts +++ b/public/app/core/utils/text.ts @@ -8,6 +8,10 @@ export function findHighlightChunksInText({ searchWords, textToHighlight }) { return findMatchesInText(textToHighlight, searchWords.join(' ')); } +const cleanNeedle = (needle: string): string => { + return needle.replace(/[[{(][\w,.-?:*+]+$/, ''); +}; + /** * Returns a list of substring regexp matches. */ @@ -16,17 +20,25 @@ export function findMatchesInText(haystack: string, needle: string): TextMatch[] if (!haystack || !needle) { return []; } - const regexp = new RegExp(`(?:${needle})`, 'g'); const matches = []; - let match = regexp.exec(haystack); - while (match) { - matches.push({ - text: match[0], - start: match.index, - length: match[0].length, - end: match.index + match[0].length, - }); - match = regexp.exec(haystack); + const cleaned = cleanNeedle(needle); + let regexp; + try { + regexp = new RegExp(`(?:${cleaned})`, 'g'); + } catch (error) { + return matches; } + haystack.replace(regexp, (substring, ...rest) => { + if (substring) { + const offset = rest[rest.length - 2]; + matches.push({ + text: substring, + start: offset, + length: substring.length, + end: offset + substring.length, + }); + } + return ''; + }); return matches; } diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index 345ccd472ce..e18ddb25d79 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -16,6 +16,7 @@ import { TimeRange, DataQuery } from 'app/types/series'; import store from 'app/core/store'; import { DEFAULT_RANGE, + calculateResultsFromQueryTransactions, ensureQueries, getIntervals, generateKey, @@ -28,7 +29,7 @@ import ResetStyles from 'app/core/components/Picker/ResetStyles'; import PickerOption from 'app/core/components/Picker/PickerOption'; import IndicatorsContainer from 'app/core/components/Picker/IndicatorsContainer'; import NoOptionsMessage from 'app/core/components/Picker/NoOptionsMessage'; -import TableModel, { mergeTablesIntoModel } from 'app/core/table_model'; +import TableModel from 'app/core/table_model'; import { DatasourceSrv } from 'app/features/plugins/datasource_srv'; import { Emitter } from 'app/core/utils/emitter'; import * as dateMath from 'app/core/utils/datemath'; @@ -70,9 +71,9 @@ interface ExploreProps { * contain one empty DataQuery. While the user modifies the DataQuery, the * modifications are being tracked in `this.modifiedQueries`, which need to be * used whenever a query is sent to the datasource to reflect what the user sees - * on the screen. Query rows can be initialized or reset using `initialQueries`, - * by giving the respective row a new key. This wipes the old row and its state. - * This property is also used to govern how many query rows there are (minimum 1). + * on the screen. Query"react-popper": "^0.7.5", rows can be initialized or reset using `initialQueries`, + * by giving the respec"react-popper": "^0.7.5",tive row a new key. This wipes the old row and its state. + * This property is als"react-popper": "^0.7.5",o used to govern how many query rows there are (minimum 1). * * This flow makes sure that a query row can be arbitrarily complex without the * fear of being wiped or re-initialized via props. The query row is free to keep @@ -101,6 +102,11 @@ export class Explore extends React.PureComponent { * Local ID cache to compare requested vs selected datasource */ requestedDatasourceId: string; + scanTimer: NodeJS.Timer; + /** + * Timepicker to control scanning + */ + timepickerRef: React.RefObject; constructor(props) { super(props); @@ -114,6 +120,8 @@ export class Explore extends React.PureComponent { const { datasource, queries, range } = props.urlState as ExploreUrlState; initialQueries = ensureQueries(queries); const initialRange = range || { ...DEFAULT_RANGE }; + // Millies step for helper bar charts + const initialGraphInterval = 15 * 1000; this.state = { datasource: null, datasourceError: null, @@ -121,11 +129,14 @@ export class Explore extends React.PureComponent { datasourceMissing: false, datasourceName: datasource, exploreDatasources: [], - graphRange: initialRange, + graphInterval: initialGraphInterval, + graphResult: [], initialQueries, history: [], + logsResult: null, queryTransactions: [], range: initialRange, + scanning: false, showingGraph: true, showingLogs: true, showingStartPage: false, @@ -133,10 +144,12 @@ export class Explore extends React.PureComponent { supportsGraph: null, supportsLogs: null, supportsTable: null, + tableResult: new TableModel(), }; } this.modifiedQueries = initialQueries.slice(); this.exploreEvents = new Emitter(); + this.timepickerRef = React.createRef(); } async componentDidMount() { @@ -168,9 +181,12 @@ export class Explore extends React.PureComponent { componentWillUnmount() { this.exploreEvents.removeAllListeners(); + clearTimeout(this.scanTimer); } async setDatasource(datasource: any, origin?: DataSource) { + const { initialQueries, range } = this.state; + const supportsGraph = datasource.meta.metrics; const supportsLogs = datasource.meta.logs; const supportsTable = datasource.meta.tables; @@ -215,7 +231,7 @@ export class Explore extends React.PureComponent { } // Reset edit state with new queries - const nextQueries = this.state.initialQueries.map((q, i) => ({ + const nextQueries = initialQueries.map((q, i) => ({ ...modifiedQueries[i], ...generateQueryKeys(i), })); @@ -224,11 +240,15 @@ export class Explore extends React.PureComponent { // Custom components const StartPage = datasource.pluginExports.ExploreStartPage; + // Calculate graph bucketing interval + const graphInterval = getIntervals(range, datasource, this.el ? this.el.offsetWidth : 0).intervalMs; + this.setState( { StartPage, datasource, datasourceError, + graphInterval, history, supportsGraph, supportsLogs, @@ -236,6 +256,7 @@ export class Explore extends React.PureComponent { datasourceLoading: false, datasourceName: datasource.name, initialQueries: nextQueries, + logsHighlighterExpressions: undefined, showingStartPage: Boolean(StartPage), }, () => { @@ -274,7 +295,11 @@ export class Explore extends React.PureComponent { return qt; }); - return { initialQueries: nextQueries, queryTransactions: nextQueryTransactions }; + return { + initialQueries: nextQueries, + logsHighlighterExpressions: undefined, + queryTransactions: nextQueryTransactions, + }; }); }; @@ -320,23 +345,24 @@ export class Explore extends React.PureComponent { queryTransactions: nextQueryTransactions, }; }, this.onSubmit); + } else if (this.state.datasource.getHighlighterExpression && this.modifiedQueries.length === 1) { + // Live preview of log search matches. Can only work on single row query for now + this.updateLogsHighlights(value); } }; - // onChangeTime = (nextRange: RawTimeRange) => { - // const range: RawTimeRange = { - // ...nextRange, - // }; - // this.setState({ range }, () => this.onSubmit()); - // }; - onChangeTime = (nextRange: TimeRange) => { + onChangeTime = (nextRange: TimeRange, scanning?: boolean) => { const range: TimeRange = { ...nextRange, }; - this.setState({ range }, () => this.onSubmit()); + if (this.state.scanning && !scanning) { + this.onStopScanning(); + } + this.setState({ range, scanning }, () => this.onSubmit()); }; onClickClear = () => { + this.onStopScanning(); this.modifiedQueries = ensureQueries(); this.setState( prevState => ({ @@ -412,12 +438,19 @@ export class Explore extends React.PureComponent { this.setState( state => { const showingTable = !state.showingTable; - let nextQueryTransactions = state.queryTransactions; - if (!showingTable) { - // Discard transactions related to Table query - nextQueryTransactions = state.queryTransactions.filter(qt => qt.resultType !== 'Table'); + if (showingTable) { + return { showingTable, queryTransactions: state.queryTransactions }; } - return { queryTransactions: nextQueryTransactions, showingTable }; + + // Toggle off needs discarding of table queries + const nextQueryTransactions = state.queryTransactions.filter(qt => qt.resultType !== 'Table'); + const results = calculateResultsFromQueryTransactions( + nextQueryTransactions, + state.datasource, + state.graphInterval + ); + + return { ...results, queryTransactions: nextQueryTransactions, showingTable }; }, () => { if (this.state.showingTable) { @@ -427,8 +460,8 @@ export class Explore extends React.PureComponent { ); }; - onClickTableCell = (columnKey: string, rowValue: string) => { - this.onModifyQueries({ type: 'ADD_FILTER', key: columnKey, value: rowValue }); + onClickLabel = (key: string, value: string) => { + this.onModifyQueries({ type: 'ADD_FILTER', key, value }); }; onModifyQueries = (action, index?: number) => { @@ -498,9 +531,16 @@ export class Explore extends React.PureComponent { // Discard transactions related to row query const nextQueryTransactions = queryTransactions.filter(qt => qt.rowIndex !== index); + const results = calculateResultsFromQueryTransactions( + nextQueryTransactions, + state.datasource, + state.graphInterval + ); return { + ...results, initialQueries: nextQueries, + logsHighlighterExpressions: undefined, queryTransactions: nextQueryTransactions, }; }, @@ -508,6 +548,24 @@ export class Explore extends React.PureComponent { ); }; + onStartScanning = () => { + this.setState({ scanning: true }, this.scanPreviousRange); + }; + + scanPreviousRange = () => { + const scanRange = this.timepickerRef.current.move(-1, true); + this.setState({ scanRange }); + }; + + onStopScanning = () => { + clearTimeout(this.scanTimer); + this.setState(state => { + const { queryTransactions } = state; + const nextQueryTransactions = queryTransactions.filter(qt => qt.scanning && !qt.done); + return { queryTransactions: nextQueryTransactions, scanning: false, scanRange: undefined }; + }); + }; + onSubmit = () => { const { showingLogs, showingGraph, showingTable, supportsGraph, supportsLogs, supportsTable } = this.state; // Keep table queries first since they need to return quickly @@ -542,7 +600,12 @@ export class Explore extends React.PureComponent { const { datasource, range } = this.state; const { interval, intervalMs } = getIntervals(range, datasource, this.el.offsetWidth); - const configuredQueries = [Object.assign(query, queryOptions)]; + const configuredQueries = [ + { + ...query, + ...queryOptions, + }, + ]; // Clone range for query request // const queryRange: RawTimeRange = { ...range }; @@ -575,6 +638,7 @@ export class Explore extends React.PureComponent { done: false, latency: 0, options: queryOptions, + scanning: this.state.scanning, }; // Using updater style because we might be modifying queryTransactions in quick succession @@ -588,7 +652,14 @@ export class Explore extends React.PureComponent { // Append new transaction const nextQueryTransactions = [...remainingTransactions, transaction]; + const results = calculateResultsFromQueryTransactions( + nextQueryTransactions, + state.datasource, + state.graphInterval + ); + return { + ...results, queryTransactions: nextQueryTransactions, showingStartPage: false, }; @@ -611,7 +682,7 @@ export class Explore extends React.PureComponent { } this.setState(state => { - const { history, queryTransactions } = state; + const { history, queryTransactions, scanning } = state; // Transaction might have been discarded const transaction = queryTransactions.find(qt => qt.id === transactionId); @@ -639,22 +710,30 @@ export class Explore extends React.PureComponent { return qt; }); + const results = calculateResultsFromQueryTransactions( + nextQueryTransactions, + state.datasource, + state.graphInterval + ); + const nextHistory = updateHistory(history, datasourceId, queries); + // Keep scanning for results if this was the last scanning transaction + if (_.size(result) === 0 && scanning) { + const other = nextQueryTransactions.find(qt => qt.scanning && !qt.done); + if (!other) { + this.scanTimer = setTimeout(this.scanPreviousRange, 1000); + } + } + return { + ...results, history: nextHistory, queryTransactions: nextQueryTransactions, }; }); } - discardTransactions(rowIndex: number) { - this.setState(state => { - const remainingTransactions = state.queryTransactions.filter(qt => qt.rowIndex !== rowIndex); - return { queryTransactions: remainingTransactions }; - }); - } - failQueryTransaction(transactionId: string, response: any, datasourceId: string) { const { datasource } = this.state; if (datasource.meta.id !== datasourceId || response.cancelled) { @@ -666,14 +745,20 @@ export class Explore extends React.PureComponent { let error: string | JSX.Element = response; if (response.data) { - error = response.data.error; - if (response.data.response) { - error = ( - <> - {response.data.error} -
{response.data.response}
- - ); + if (typeof response.data === 'string') { + error = response.data; + } else if (response.data.error) { + error = response.data.error; + if (response.data.response) { + error = ( + <> + {response.data.error} +
{response.data.response}
+ + ); + } + } else { + throw new Error('Could not handle error response'); } } @@ -704,6 +789,9 @@ export class Explore extends React.PureComponent { async runQueries(resultType: ResultType, queryOptions: any, resultGetter?: any) { const queries = [...this.modifiedQueries]; if (!hasNonEmptyQuery(queries)) { + this.setState({ + queryTransactions: [], + }); return; } const { datasource } = this.state; @@ -718,7 +806,6 @@ export class Explore extends React.PureComponent { const latency = Date.now() - now; const results = resultGetter ? resultGetter(res.data) : res.data; this.completeQueryTransaction(transaction.id, results, latency, queries, datasourceId); - this.setState({ graphRange: transaction.options.range }); } catch (response) { this.exploreEvents.emit('data-error', response); this.failQueryTransaction(transaction.id, response, datasourceId); @@ -726,6 +813,17 @@ export class Explore extends React.PureComponent { }); } + updateLogsHighlights = _.debounce((value: DataQuery, index: number) => { + this.setState(state => { + const { datasource } = state; + if (datasource.getHighlighterExpression) { + const logsHighlighterExpressions = [state.datasource.getHighlighterExpression(value)]; + return { logsHighlighterExpressions }; + } + return null; + }); + }, 500); + cloneState(): ExploreState { // Copy state, but copy queries including modifications return { @@ -749,11 +847,15 @@ export class Explore extends React.PureComponent { datasourceLoading, datasourceMissing, exploreDatasources, - graphRange, + graphResult, history, initialQueries, + logsHighlighterExpressions, + logsResult, queryTransactions, range, + scanning, + scanRange, showingGraph, showingLogs, showingStartPage, @@ -761,34 +863,14 @@ export class Explore extends React.PureComponent { supportsGraph, supportsLogs, supportsTable, + tableResult, } = this.state; const graphHeight = showingGraph && showingTable ? '200px' : '400px'; const exploreClass = split ? 'explore explore-split' : 'explore'; const selectedDatasource = datasource ? exploreDatasources.find(d => d.label === datasource.name) : undefined; - const graphRangeIntervals = getIntervals(graphRange, datasource, this.el ? this.el.offsetWidth : 0); const graphLoading = queryTransactions.some(qt => qt.resultType === 'Graph' && !qt.done); const tableLoading = queryTransactions.some(qt => qt.resultType === 'Table' && !qt.done); const logsLoading = queryTransactions.some(qt => qt.resultType === 'Logs' && !qt.done); - // TODO don't recreate those on each re-render - const graphResult = _.flatten( - queryTransactions.filter(qt => qt.resultType === 'Graph' && qt.done && qt.result).map(qt => qt.result) - ); - - //Temp solution... How do detect if ds supports table format? - let tableResult; - tableResult = mergeTablesIntoModel( - new TableModel(), - ...queryTransactions.filter(qt => qt.resultType === 'Table' && qt.done && qt.result).map(qt => qt.result) - ); - const logsResult = - datasource && datasource.mergeStreams - ? datasource.mergeStreams( - _.flatten( - queryTransactions.filter(qt => qt.resultType === 'Logs' && qt.done && qt.result).map(qt => qt.result) - ), - graphRangeIntervals.intervalMs - ) - : undefined; const loading = queryTransactions.some(qt => !qt.done); return ( @@ -839,7 +921,7 @@ export class Explore extends React.PureComponent { ) : null} - +