Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
14cb2b01
Commit
14cb2b01
authored
Sep 06, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
began work on support index time patterns
parent
b24c5392
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
127 additions
and
22 deletions
+127
-22
public/app/features/org/partials/datasourceHttpConfig.html
+1
-3
public/app/plugins/datasource/elasticsearch/datasource.js
+11
-10
public/app/plugins/datasource/elasticsearch/indexPattern.js
+28
-0
public/app/plugins/datasource/elasticsearch/partials/config.html
+21
-5
public/app/plugins/datasource/elasticsearch/queryCtrl.js
+1
-1
public/test/specs/elasticsearch-indexPattern-specs.js
+35
-0
public/test/specs/elasticsearch-specs.js
+29
-3
public/test/test-main.js
+1
-0
No files found.
public/app/features/org/partials/datasourceHttpConfig.html
View file @
14cb2b01
...
...
@@ -23,9 +23,7 @@
Basic Auth
</li>
<li
class=
"tight-form-item"
>
Enable
<input
class=
"cr1"
id=
"current.basicAuth"
type=
"checkbox"
ng-model=
"current.basicAuth"
ng-checked=
"current.basicAuth"
>
<label
for=
"current.basicAuth"
class=
"cr1"
></label>
<editor-checkbox
text=
"Enable"
model=
"current.basicAuth"
></editor-checkbox>
</li>
<li
class=
"tight-form-item"
ng-if=
"current.basicAuth"
>
User
...
...
public/app/plugins/datasource/elasticsearch/datasource.js
View file @
14cb2b01
define
([
'angular'
,
'lodash'
,
'config'
,
'kbn'
,
'moment'
,
'./queryBuilder'
,
'./indexPattern'
,
'./queryCtrl'
,
'./directives'
],
function
(
angular
,
_
,
config
,
kbn
,
moment
,
ElasticQueryBuilder
)
{
function
(
angular
,
_
,
moment
,
ElasticQueryBuilder
,
IndexPattern
)
{
'use strict'
;
var
module
=
angular
.
module
(
'grafana.services'
);
...
...
@@ -21,10 +20,7 @@ function (angular, _, config, kbn, moment, ElasticQueryBuilder) {
this
.
url
=
datasource
.
url
;
this
.
name
=
datasource
.
name
;
this
.
index
=
datasource
.
index
;
this
.
searchMaxResults
=
config
.
search
.
max_results
||
20
;
this
.
saveTemp
=
_
.
isUndefined
(
datasource
.
save_temp
)
?
true
:
datasource
.
save_temp
;
this
.
saveTempTTL
=
_
.
isUndefined
(
datasource
.
save_temp_ttl
)
?
'30d'
:
datasource
.
save_temp_ttl
;
this
.
indexPattern
=
new
IndexPattern
(
datasource
.
index
,
datasource
.
jsonData
.
interval
)
}
ElasticDatasource
.
prototype
.
_request
=
function
(
method
,
url
,
index
,
data
)
{
...
...
@@ -45,7 +41,7 @@ function (angular, _, config, kbn, moment, ElasticQueryBuilder) {
};
ElasticDatasource
.
prototype
.
_get
=
function
(
url
)
{
return
this
.
_request
(
'GET'
,
url
,
this
.
index
)
return
this
.
_request
(
'GET'
,
url
,
this
.
index
Pattern
.
getIndexForToday
()
)
.
then
(
function
(
results
)
{
return
results
.
data
;
});
...
...
@@ -128,9 +124,14 @@ function (angular, _, config, kbn, moment, ElasticQueryBuilder) {
};
ElasticDatasource
.
prototype
.
testDatasource
=
function
()
{
var
query
=
JSON
.
stringify
();
return
this
.
_post
(
'/_search?search_type=count'
,
query
).
then
(
function
()
{
return
this
.
_get
(
'/_stats'
).
then
(
function
()
{
return
{
status
:
"success"
,
message
:
"Data source is working"
,
title
:
"Success"
};
},
function
(
err
)
{
if
(
err
.
data
&&
err
.
data
.
error
)
{
return
{
status
:
"error"
,
message
:
err
.
data
.
error
,
title
:
"Error"
};
}
else
{
return
{
status
:
"error"
,
message
:
err
.
status
,
title
:
"Error"
};
}
});
};
...
...
public/app/plugins/datasource/elasticsearch/indexPattern.js
0 → 100644
View file @
14cb2b01
define
([
'lodash'
,
'moment'
,
],
function
(
_
,
moment
)
{
'use strict'
;
function
IndexPattern
(
pattern
,
interval
)
{
this
.
pattern
=
pattern
;
this
.
interval
=
interval
;
};
IndexPattern
.
prototype
.
getIndexForToday
=
function
()
{
if
(
this
.
interval
)
{
return
moment
().
format
(
this
.
pattern
);
}
else
{
return
this
.
pattern
;
}
};
IndexPattern
.
prototype
.
getIndexList
=
function
(
from
,
to
)
{
};
return
IndexPattern
;
})
public/app/plugins/datasource/elasticsearch/partials/config.html
View file @
14cb2b01
<div
ng-include=
"httpConfigPartialSrc"
></div>
<br>
<h5>
Elastic search details
</h5>
<div
class=
"tight-form
last
"
>
<div
class=
"tight-form"
>
<ul
class=
"tight-form-list"
>
<li
class=
"tight-form-item"
style=
"width:
80
px"
>
<li
class=
"tight-form-item"
style=
"width:
144
px"
>
Index name
</li>
<li>
<input
type=
"text"
class=
"tight-form-input input-xlarge"
ng-model=
'current.database'
placeholder=
""
required
></input>
</li>
<li
class=
"tight-form-item"
>
Pattern
</li>
<li>
<select
class=
"input-medium tight-form-input"
ng-model=
"current.jsonData.interval"
ng-options=
"f.value as f.name for f in [{name: 'No pattern', value: undefined}, {name: 'Hourly', value: 'hourly'}, {name: 'Daily', value: 'daily'}]"
></select>
</li>
</ul>
<div
class=
"clearfix"
></div>
</div>
<div
class=
"tight-form last"
>
<ul
class=
"tight-form-list"
>
<li
class=
"tight-form-item"
style=
"width: 144px"
>
Time field name
</li>
<li>
<input
type=
"text"
class=
"tight-form-input input-xlarge"
ng-model=
'current.jsonData.timeField'
placeholder=
""
required
ng-init=
"current.jsonData.timeField = current.jsonData.timeField || '@timestamp'"
></input>
</li>
</ul>
<div
class=
"clearfix"
></div>
</div>
public/app/plugins/datasource/elasticsearch/queryCtrl.js
View file @
14cb2b01
...
...
@@ -16,7 +16,7 @@ function (angular, _, ElasticQueryBuilder) {
target
.
timeField
=
target
.
timeField
||
'@timestamp'
;
target
.
metrics
=
target
.
metrics
||
[{
type
:
'count'
,
id
:
'1'
}];
target
.
bucketAggs
=
target
.
bucketAggs
||
[{
type
:
'date_histogram'
,
field
:
'@timest
ma
p'
,
id
:
'2'
}];
target
.
bucketAggs
=
target
.
bucketAggs
||
[{
type
:
'date_histogram'
,
field
:
'@timest
am
p'
,
id
:
'2'
}];
$scope
.
queryBuilder
=
new
ElasticQueryBuilder
(
target
);
$scope
.
rawQueryOld
=
angular
.
toJson
(
$scope
.
queryBuilder
.
build
(
$scope
.
target
),
true
);
...
...
public/test/specs/elasticsearch-indexPattern-specs.js
0 → 100644
View file @
14cb2b01
define
([
'moment'
,
'plugins/datasource/elasticsearch/indexPattern'
],
function
(
moment
,
IndexPattern
)
{
'use strict'
;
describe
(
'IndexPattern'
,
function
()
{
describe
(
'when getting index for today'
,
function
()
{
it
(
'should return correct index name'
,
function
()
{
var
pattern
=
new
IndexPattern
(
'[asd-]YYYY.MM.DD'
,
'daily'
);
var
expected
=
'asd-'
+
moment
().
format
(
'YYYY.MM.DD'
);
expect
(
pattern
.
getIndexForToday
()).
to
.
be
(
expected
);
});
});
describe
(
'when getting index list for time range'
,
function
()
{
describe
(
'daily'
,
function
()
{
it
(
'should return correct index list'
,
function
()
{
var
pattern
=
new
IndexPattern
(
'[asd-]YYYY.MM.DD'
,
'daily'
);
var
from
=
new
Date
(
2015
,
4
,
29
);
var
to
=
new
Date
(
2015
,
5
,
1
);
expect
(
pattern
.
getIndexList
(
from
,
to
)).
to
.
be
([
'asd'
,
'asd2'
]);
});
})
});
});
});
public/test/specs/elasticsearch-specs.js
View file @
14cb2b01
define
([
'helpers'
,
'moment'
,
'plugins/datasource/elasticsearch/datasource'
,
'aws-sdk'
,
],
function
(
helpers
)
{
],
function
(
helpers
,
moment
)
{
'use strict'
;
describe
(
'ElasticDatasource'
,
function
()
{
var
ctx
=
new
helpers
.
ServiceTestContext
();
beforeEach
(
module
(
'grafana.services'
));
beforeEach
(
ctx
.
providePhase
([
'templateSrv'
]));
beforeEach
(
ctx
.
providePhase
([
'templateSrv'
,
'backendSrv'
]));
beforeEach
(
ctx
.
createService
(
'ElasticDatasource'
));
beforeEach
(
function
()
{
ctx
.
ds
=
new
ctx
.
service
({});
ctx
.
ds
=
new
ctx
.
service
({
jsonData
:
{}});
});
describe
(
'When testing datasource with index pattern'
,
function
()
{
beforeEach
(
function
(){
ctx
.
ds
=
new
ctx
.
service
({
url
:
'http://es.com'
,
index
:
'[asd-]YYYY.MM.DD'
,
jsonData
:
{
interval
:
'daily'
}
});
})
it
(
'should translate index pattern to current day'
,
function
()
{
var
requestOptions
;
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({});
};
ctx
.
ds
.
testDatasource
();
ctx
.
$rootScope
.
$apply
();
var
today
=
moment
().
format
(
"YYYY.MM.DD"
);
expect
(
requestOptions
.
url
).
to
.
be
(
"http://es.com/asd-"
+
today
+
'/_stats'
);
});
});
describe
(
'When processing es response'
,
function
()
{
...
...
public/test/test-main.js
View file @
14cb2b01
...
...
@@ -155,6 +155,7 @@ require([
'specs/elasticsearch-specs'
,
'specs/elasticsearch-querybuilder-specs'
,
'specs/elasticsearch-queryctrl-specs'
,
'specs/elasticsearch-indexPattern-specs'
,
];
var
pluginSpecs
=
(
config
.
plugins
.
specs
||
[]).
map
(
function
(
spec
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment