Skip to content

Commit 631af46

Browse files
committed
Merge branch 'master' into react-panels-step1
2 parents 8ba865b + 5e9ef5f commit 631af46

File tree

18 files changed

+2123
-30
lines changed

18 files changed

+2123
-30
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ debug.test
6969
/vendor/**/*.yml
7070
/vendor/**/*_test.go
7171
/vendor/**/.editorconfig
72-
/vendor/**/appengine*
7372
*.orig
7473

7574
/devenv/bulk-dashboards/*.json

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
* **Datasource Proxy**: Keep trailing slash for datasource proxy requests [#13326](https://github.com/grafana/grafana/pull/13326), thx [@ryantxu](https://github.com/ryantxu)
1010
* **Elasticsearch**: Fix no limit size in terms aggregation for alerting queries [#13172](https://github.com/grafana/grafana/issues/13172), thx [@Yukinoshita-Yukino](https://github.com/Yukinoshita-Yukino)
11+
* **Units**: New clock time format, to format ms or second values as for example `01h:59m`, [#13635](https://github.com/grafana/grafana/issues/13635), thx [@franciscocpg](https://github.com/franciscocpg)
1112

1213
### Breaking changes
1314

@@ -16,6 +17,7 @@
1617
# 5.3.1 (unreleased)
1718

1819
* **Render**: Fix PhantomJS render of graph panel when legend displayed as table to the right [#13616](https://github.com/grafana/grafana/issues/13616)
20+
* **Stackdriver**: Filter option disappears after removing initial filter [#13607](https://github.com/grafana/grafana/issues/13607)
1921

2022
# 5.3.0 (2018-10-10)
2123

@@ -68,7 +70,7 @@
6870
* **Profile**: List teams that the user is member of in current/active organization [#12476](https://github.com/grafana/grafana/issues/12476)
6971
* **Configuration**: Allow auto-assigning users to specific organization (other than Main. Org) [#1823](https://github.com/grafana/grafana/issues/1823) [#12801](https://github.com/grafana/grafana/issues/12801), thx [@gzzo](https://github.com/gzzo) and [@ofosos](https://github.com/ofosos)
7072
* **Dataproxy**: Pass configured/auth headers to a Datasource [#10971](https://github.com/grafana/grafana/issues/10971), thx [@mrsiano](https://github.com/mrsiano)
71-
* ****: **: CloudWatch GetMetricData support [#11487](https://github.com/grafana/grafana/issues/11487), thx [@mtanda](https://github.com/mtanda)
73+
* **CloudWatch**: GetMetricData support [#11487](https://github.com/grafana/grafana/issues/11487), thx [@mtanda](https://github.com/mtanda)
7274
* **Postgres**: TimescaleDB support, e.g. use `time_bucket` for grouping by time when option enabled [#12680](https://github.com/grafana/grafana/pull/12680), thx [svenklemm](https://github.com/svenklemm)
7375
* **Cleanup**: Make temp file time to live configurable [#11607](https://github.com/grafana/grafana/issues/11607), thx [@xapon](https://github.com/xapon)
7476

docs/sources/plugins/developing/development.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ weight = 1
1010

1111
# Developer Guide
1212

13-
You can extend Grafana by writing your own plugins and then share then with other users in [our plugin repository](https://grafana.com/plugins).
13+
You can extend Grafana by writing your own plugins and then share them with other users in [our plugin repository](https://grafana.com/plugins).
1414

1515
## Short version
1616

@@ -33,7 +33,7 @@ There are two blog posts about authoring a plugin that might also be of interest
3333
## What languages?
3434

3535
Since everything turns into javascript it's up to you to choose which language you want. That said it's probably a good idea to choose es6 or typescript since
36-
we use es6 classes in Grafana. So it's easier to get inspiration from the Grafana repo is you choose one of those languages.
36+
we use es6 classes in Grafana. So it's easier to get inspiration from the Grafana repo if you choose one of those languages.
3737

3838
## Buildscript
3939

@@ -60,7 +60,6 @@ and [apps]({{< relref "apps.md" >}}) plugins in the documentation.
6060
The Grafana SDK is quite small so far and can be found here:
6161

6262
- [SDK file in Grafana](https://github.com/grafana/grafana/blob/master/public/app/plugins/sdk.ts)
63-
- [SDK Readme](https://github.com/grafana/grafana/blob/master/public/app/plugins/plugin_api.md)
6463

6564
The SDK contains three different plugin classes: PanelCtrl, MetricsPanelCtrl and QueryCtrl. For plugins of the panel type, the module.js file should export one of these. There are some extra classes for [data sources]({{< relref "datasources.md" >}}).
6665

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"style-loader": "^0.21.0",
8181
"systemjs": "0.20.19",
8282
"systemjs-plugin-css": "^0.1.36",
83-
"ts-jest": "^23.1.4",
83+
"ts-jest": "^23.10.4",
8484
"ts-loader": "^5.1.0",
8585
"tslib": "^1.9.3",
8686
"tslint": "^5.8.0",

pkg/api/http_server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/grafana/grafana/pkg/models"
2929
"github.com/grafana/grafana/pkg/plugins"
3030
"github.com/grafana/grafana/pkg/registry"
31+
"github.com/grafana/grafana/pkg/services/hooks"
3132
"github.com/grafana/grafana/pkg/services/rendering"
3233
"github.com/grafana/grafana/pkg/setting"
3334
)
@@ -52,6 +53,7 @@ type HTTPServer struct {
5253
Bus bus.Bus `inject:""`
5354
RenderService rendering.Service `inject:""`
5455
Cfg *setting.Cfg `inject:""`
56+
HooksService *hooks.HooksService `inject:""`
5557
}
5658

5759
func (hs *HTTPServer) Init() error {

pkg/api/index.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -316,27 +316,20 @@ func (hs *HTTPServer) setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, er
316316
}
317317

318318
if c.IsGrafanaAdmin {
319-
children := []*dtos.NavLink{
320-
{Text: "Users", Id: "global-users", Url: setting.AppSubUrl + "/admin/users", Icon: "gicon gicon-user"},
321-
{Text: "Orgs", Id: "global-orgs", Url: setting.AppSubUrl + "/admin/orgs", Icon: "gicon gicon-org"},
322-
{Text: "Settings", Id: "server-settings", Url: setting.AppSubUrl + "/admin/settings", Icon: "gicon gicon-preferences"},
323-
{Text: "Stats", Id: "server-stats", Url: setting.AppSubUrl + "/admin/stats", Icon: "fa fa-fw fa-bar-chart"},
324-
}
325-
326-
if setting.IsEnterprise {
327-
children = append(children, &dtos.NavLink{Text: "Licensing", Id: "licensing", Url: setting.AppSubUrl + "/admin/licensing", Icon: "fa fa-fw fa-unlock-alt"})
328-
}
329-
330-
children = append(children, &dtos.NavLink{Text: "Style Guide", Id: "styleguide", Url: setting.AppSubUrl + "/styleguide", Icon: "fa fa-fw fa-eyedropper"})
331-
332319
cfgNode.Children = append(cfgNode.Children, &dtos.NavLink{
333320
Text: "Server Admin",
334321
HideFromTabs: true,
335322
SubTitle: "Manage all users & orgs",
336323
Id: "admin",
337324
Icon: "gicon gicon-shield",
338325
Url: setting.AppSubUrl + "/admin/users",
339-
Children: children,
326+
Children: []*dtos.NavLink{
327+
{Text: "Users", Id: "global-users", Url: setting.AppSubUrl + "/admin/users", Icon: "gicon gicon-user"},
328+
{Text: "Orgs", Id: "global-orgs", Url: setting.AppSubUrl + "/admin/orgs", Icon: "gicon gicon-org"},
329+
{Text: "Settings", Id: "server-settings", Url: setting.AppSubUrl + "/admin/settings", Icon: "gicon gicon-preferences"},
330+
{Text: "Stats", Id: "server-stats", Url: setting.AppSubUrl + "/admin/stats", Icon: "fa fa-fw fa-bar-chart"},
331+
{Text: "Style Guide", Id: "styleguide", Url: setting.AppSubUrl + "/styleguide", Icon: "fa fa-fw fa-eyedropper"},
332+
},
340333
})
341334
}
342335

@@ -357,6 +350,7 @@ func (hs *HTTPServer) setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, er
357350
},
358351
})
359352

353+
hs.HooksService.RunIndexDataHooks(&data)
360354
return &data, nil
361355
}
362356

pkg/services/alerting/notifiers/telegram.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ func (this *TelegramNotifier) buildMessageInlineImage(evalContext *alerting.Eval
127127
var err error
128128

129129
imageFile, err = os.Open(evalContext.ImageOnDiskPath)
130-
defer imageFile.Close()
130+
defer func() {
131+
err := imageFile.Close()
132+
if err != nil {
133+
log.Error2("Could not close Telegram inline image.", "err", err)
134+
}
135+
}()
136+
131137
if err != nil {
132138
return nil, err
133139
}

pkg/services/hooks/hooks.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package hooks
2+
3+
import (
4+
"github.com/grafana/grafana/pkg/api/dtos"
5+
"github.com/grafana/grafana/pkg/registry"
6+
)
7+
8+
type IndexDataHook func(indexData *dtos.IndexViewData)
9+
10+
type HooksService struct {
11+
indexDataHooks []IndexDataHook
12+
}
13+
14+
func init() {
15+
registry.RegisterService(&HooksService{})
16+
}
17+
18+
func (srv *HooksService) Init() error {
19+
return nil
20+
}
21+
22+
func (srv *HooksService) AddIndexDataHook(hook IndexDataHook) {
23+
srv.indexDataHooks = append(srv.indexDataHooks, hook)
24+
}
25+
26+
func (srv *HooksService) RunIndexDataHooks(indexData *dtos.IndexViewData) {
27+
for _, hook := range srv.indexDataHooks {
28+
hook(indexData)
29+
}
30+
}

pkg/services/sqlstore/user_auth_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ func TestUserAuth(t *testing.T) {
1616
Convey("Given 5 users", t, func() {
1717
var err error
1818
var cmd *m.CreateUserCommand
19-
users := []m.User{}
2019
for i := 0; i < 5; i++ {
2120
cmd = &m.CreateUserCommand{
2221
Email: fmt.Sprint("user", i, "@test.com"),
@@ -25,7 +24,6 @@ func TestUserAuth(t *testing.T) {
2524
}
2625
err = CreateUser(context.Background(), cmd)
2726
So(err, ShouldBeNil)
28-
users = append(users, cmd.Result)
2927
}
3028

3129
Reset(func() {

pkg/tsdb/mssql/mssql_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ func TestMSSQL(t *testing.T) {
692692
},
693693
}
694694

695-
resp, err := endpoint.Query(nil, nil, query)
695+
resp, err := endpoint.Query(context.Background(), nil, query)
696696
So(err, ShouldBeNil)
697697
queryResult := resp.Results["A"]
698698
So(queryResult.Error, ShouldBeNil)

pkg/tsdb/mysql/mysql_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ func TestMySQL(t *testing.T) {
769769
},
770770
}
771771

772-
resp, err := endpoint.Query(nil, nil, query)
772+
resp, err := endpoint.Query(context.Background(), nil, query)
773773
So(err, ShouldBeNil)
774774
queryResult := resp.Results["A"]
775775
So(queryResult.Error, ShouldBeNil)

pkg/tsdb/postgres/postgres_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ func TestPostgres(t *testing.T) {
701701
},
702702
}
703703

704-
resp, err := endpoint.Query(nil, nil, query)
704+
resp, err := endpoint.Query(context.Background(), nil, query)
705705
So(err, ShouldBeNil)
706706
queryResult := resp.Results["A"]
707707
So(queryResult.Error, ShouldBeNil)

public/app/core/specs/kbn.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,77 @@ describe('duration', () => {
399399
});
400400
});
401401

402+
describe('clock', () => {
403+
it('null', () => {
404+
const str = kbn.toClock(null, 0);
405+
expect(str).toBe('');
406+
});
407+
it('size less than 1 second', () => {
408+
const str = kbn.toClock(999, 0);
409+
expect(str).toBe('999ms');
410+
});
411+
describe('size less than 1 minute', () => {
412+
it('default', () => {
413+
const str = kbn.toClock(59999);
414+
expect(str).toBe('59s:999ms');
415+
});
416+
it('decimals equals 0', () => {
417+
const str = kbn.toClock(59999, 0);
418+
expect(str).toBe('59s');
419+
});
420+
});
421+
describe('size less than 1 hour', () => {
422+
it('default', () => {
423+
const str = kbn.toClock(3599999);
424+
expect(str).toBe('59m:59s:999ms');
425+
});
426+
it('decimals equals 0', () => {
427+
const str = kbn.toClock(3599999, 0);
428+
expect(str).toBe('59m');
429+
});
430+
it('decimals equals 1', () => {
431+
const str = kbn.toClock(3599999, 1);
432+
expect(str).toBe('59m:59s');
433+
});
434+
});
435+
describe('size greater than or equal 1 hour', () => {
436+
it('default', () => {
437+
const str = kbn.toClock(7199999);
438+
expect(str).toBe('01h:59m:59s:999ms');
439+
});
440+
it('decimals equals 0', () => {
441+
const str = kbn.toClock(7199999, 0);
442+
expect(str).toBe('01h');
443+
});
444+
it('decimals equals 1', () => {
445+
const str = kbn.toClock(7199999, 1);
446+
expect(str).toBe('01h:59m');
447+
});
448+
it('decimals equals 2', () => {
449+
const str = kbn.toClock(7199999, 2);
450+
expect(str).toBe('01h:59m:59s');
451+
});
452+
});
453+
describe('size greater than or equal 1 day', () => {
454+
it('default', () => {
455+
const str = kbn.toClock(89999999);
456+
expect(str).toBe('24h:59m:59s:999ms');
457+
});
458+
it('decimals equals 0', () => {
459+
const str = kbn.toClock(89999999, 0);
460+
expect(str).toBe('24h');
461+
});
462+
it('decimals equals 1', () => {
463+
const str = kbn.toClock(89999999, 1);
464+
expect(str).toBe('24h:59m');
465+
});
466+
it('decimals equals 2', () => {
467+
const str = kbn.toClock(89999999, 2);
468+
expect(str).toBe('24h:59m:59s');
469+
});
470+
});
471+
});
472+
402473
describe('volume', () => {
403474
it('1000m3', () => {
404475
const str = kbn.valueFormats['m3'](1000, 1, null);

public/app/core/utils/kbn.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,51 @@ kbn.toDuration = (size, decimals, timeScale) => {
808808
return strings.join(', ');
809809
};
810810

811+
kbn.toClock = (size, decimals) => {
812+
if (size === null) {
813+
return '';
814+
}
815+
816+
// < 1 second
817+
if (size < 1000) {
818+
return moment.utc(size).format('SSS\\m\\s');
819+
}
820+
821+
// < 1 minute
822+
if (size < 60000) {
823+
let format = 'ss\\s:SSS\\m\\s';
824+
if (decimals === 0) {
825+
format = 'ss\\s';
826+
}
827+
return moment.utc(size).format(format);
828+
}
829+
830+
// < 1 hour
831+
if (size < 3600000) {
832+
let format = 'mm\\m:ss\\s:SSS\\m\\s';
833+
if (decimals === 0) {
834+
format = 'mm\\m';
835+
} else if (decimals === 1) {
836+
format = 'mm\\m:ss\\s';
837+
}
838+
return moment.utc(size).format(format);
839+
}
840+
841+
let format = 'mm\\m:ss\\s:SSS\\m\\s';
842+
843+
const hours = `${('0' + Math.floor(moment.duration(size, 'milliseconds').asHours())).slice(-2)}h`;
844+
845+
if (decimals === 0) {
846+
format = '';
847+
} else if (decimals === 1) {
848+
format = 'mm\\m';
849+
} else if (decimals === 2) {
850+
format = 'mm\\m:ss\\s';
851+
}
852+
853+
return format ? `${hours}:${moment.utc(size).format(format)}` : hours;
854+
};
855+
811856
kbn.valueFormats.dtdurationms = (size, decimals) => {
812857
return kbn.toDuration(size, decimals, 'millisecond');
813858
};
@@ -824,6 +869,14 @@ kbn.valueFormats.timeticks = (size, decimals, scaledDecimals) => {
824869
return kbn.valueFormats.s(size / 100, decimals, scaledDecimals);
825870
};
826871

872+
kbn.valueFormats.clockms = (size, decimals) => {
873+
return kbn.toClock(size, decimals);
874+
};
875+
876+
kbn.valueFormats.clocks = (size, decimals) => {
877+
return kbn.toClock(size * 1000, decimals);
878+
};
879+
827880
kbn.valueFormats.dateTimeAsIso = (epoch, isUtc) => {
828881
const time = isUtc ? moment.utc(epoch) : moment(epoch);
829882

@@ -901,6 +954,8 @@ kbn.getUnitFormats = () => {
901954
{ text: 'duration (s)', value: 'dtdurations' },
902955
{ text: 'duration (hh:mm:ss)', value: 'dthms' },
903956
{ text: 'Timeticks (s/100)', value: 'timeticks' },
957+
{ text: 'clock (ms)', value: 'clockms' },
958+
{ text: 'clock (s)', value: 'clocks' },
904959
],
905960
},
906961
{

public/app/plugins/datasource/prometheus/metric_find_query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class PrometheusMetricFindQuery {
1212
}
1313

1414
process() {
15-
const labelValuesRegex = /^label_values\((?:(.+),\s*)?([a-zA-Z_][a-zA-Z0-9_]+)\)\s*$/;
15+
const labelValuesRegex = /^label_values\((?:(.+),\s*)?([a-zA-Z_][a-zA-Z0-9_]*)\)\s*$/;
1616
const metricNamesRegex = /^metrics\((.+)\)\s*$/;
1717
const queryResultRegex = /^query_result\((.+)\)\s*$/;
1818

public/app/plugins/datasource/stackdriver/filter_segments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class FilterSegments {
8787
}
8888

8989
// remove condition if it is first segment
90-
if (index === 0 && this.filterSegments[0].type === 'condition') {
90+
if (index === 0 && this.filterSegments.length > 0 && this.filterSegments[0].type === 'condition') {
9191
this.filterSegments.splice(0, 1);
9292
}
9393
}

public/app/plugins/panel/graph/graph.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,9 @@ class GraphElement {
714714
if (min && max && ticks) {
715715
const range = max - min;
716716
const secPerTick = range / ticks / 1000;
717-
const oneDay = 86400000;
717+
// Need have 10 milisecond margin on the day range
718+
// As sometimes last 24 hour dashboard evaluates to more than 86400000
719+
const oneDay = 86400010;
718720
const oneYear = 31536000000;
719721

720722
if (secPerTick <= 45) {

0 commit comments

Comments
 (0)