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
1d290271
Commit
1d290271
authored
Jan 18, 2019
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: progress on adding query types
parent
a69f79ca
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
15 deletions
+29
-15
public/app/plugins/datasource/loki/datasource.test.ts
+11
-3
public/app/plugins/datasource/loki/datasource.ts
+5
-5
public/app/plugins/datasource/loki/language_provider.ts
+11
-5
public/app/types/explore.ts
+2
-2
No files found.
public/app/plugins/datasource/loki/datasource.test.ts
View file @
1d290271
import
moment
from
'moment'
;
import
LokiDatasource
from
'./datasource'
;
import
LokiDatasource
from
'./datasource'
;
describe
(
'LokiDatasource'
,
()
=>
{
describe
(
'LokiDatasource'
,
()
=>
{
...
@@ -13,12 +14,19 @@ describe('LokiDatasource', () => {
...
@@ -13,12 +14,19 @@ describe('LokiDatasource', () => {
replace
:
a
=>
a
,
replace
:
a
=>
a
,
};
};
const
range
=
{
from
:
'now-6h'
,
to
:
'now'
};
const
range
=
{
from
:
moment
(),
to
:
moment
(),
raw
:
{
from
:
'now-6h'
,
to
:
'now'
}
};
test
(
'should use default max lines when no limit given'
,
()
=>
{
test
(
'should use default max lines when no limit given'
,
()
=>
{
const
ds
=
new
LokiDatasource
(
instanceSettings
,
backendSrvMock
,
templateSrvMock
);
const
ds
=
new
LokiDatasource
(
instanceSettings
,
backendSrvMock
,
templateSrvMock
);
backendSrvMock
.
datasourceRequest
=
jest
.
fn
();
backendSrvMock
.
datasourceRequest
=
jest
.
fn
();
ds
.
query
({
range
,
targets
:
[{
expr
:
'foo'
}]
});
ds
.
query
({
range
,
targets
:
[{
expr
:
'foo'
,
refId
:
'B'
}]
});
expect
(
backendSrvMock
.
datasourceRequest
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
backendSrvMock
.
datasourceRequest
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
backendSrvMock
.
datasourceRequest
.
mock
.
calls
[
0
][
0
].
url
).
toContain
(
'limit=1000'
);
expect
(
backendSrvMock
.
datasourceRequest
.
mock
.
calls
[
0
][
0
].
url
).
toContain
(
'limit=1000'
);
});
});
...
@@ -28,7 +36,7 @@ describe('LokiDatasource', () => {
...
@@ -28,7 +36,7 @@ describe('LokiDatasource', () => {
const
customSettings
=
{
...
instanceSettings
,
jsonData
:
customData
};
const
customSettings
=
{
...
instanceSettings
,
jsonData
:
customData
};
const
ds
=
new
LokiDatasource
(
customSettings
,
backendSrvMock
,
templateSrvMock
);
const
ds
=
new
LokiDatasource
(
customSettings
,
backendSrvMock
,
templateSrvMock
);
backendSrvMock
.
datasourceRequest
=
jest
.
fn
();
backendSrvMock
.
datasourceRequest
=
jest
.
fn
();
ds
.
query
({
range
,
targets
:
[{
expr
:
'foo'
}]
});
ds
.
query
({
range
,
targets
:
[{
expr
:
'foo'
,
refId
:
'A'
}]
});
expect
(
backendSrvMock
.
datasourceRequest
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
backendSrvMock
.
datasourceRequest
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
backendSrvMock
.
datasourceRequest
.
mock
.
calls
[
0
][
0
].
url
).
toContain
(
'limit=20'
);
expect
(
backendSrvMock
.
datasourceRequest
.
mock
.
calls
[
0
][
0
].
url
).
toContain
(
'limit=20'
);
});
});
...
...
public/app/plugins/datasource/loki/datasource.ts
View file @
1d290271
...
@@ -11,7 +11,7 @@ import { makeSeriesForLogs } from 'app/core/logs_model';
...
@@ -11,7 +11,7 @@ import { makeSeriesForLogs } from 'app/core/logs_model';
// Types
// Types
import
{
LogsStream
,
LogsModel
}
from
'app/core/logs_model'
;
import
{
LogsStream
,
LogsModel
}
from
'app/core/logs_model'
;
import
{
PluginMeta
,
DataQueryOptions
,
DataSourceApi
}
from
'@grafana/ui/src/types'
;
import
{
PluginMeta
,
DataQueryOptions
}
from
'@grafana/ui/src/types'
;
import
{
LokiQuery
}
from
'./types'
;
import
{
LokiQuery
}
from
'./types'
;
export
const
DEFAULT_MAX_LINES
=
1000
;
export
const
DEFAULT_MAX_LINES
=
1000
;
...
@@ -32,7 +32,7 @@ function serializeParams(data: any) {
...
@@ -32,7 +32,7 @@ function serializeParams(data: any) {
.
join
(
'&'
);
.
join
(
'&'
);
}
}
export
default
class
LokiDatasource
implements
DataSourceApi
<
LokiQuery
>
{
export
default
class
LokiDatasource
{
languageProvider
:
LanguageProvider
;
languageProvider
:
LanguageProvider
;
maxLines
:
number
;
maxLines
:
number
;
...
@@ -101,7 +101,7 @@ export default class LokiDatasource implements DataSourceApi<LokiQuery> {
...
@@ -101,7 +101,7 @@ export default class LokiDatasource implements DataSourceApi<LokiQuery> {
});
});
}
}
async
importQueries
(
queries
:
DataQuery
[],
originMeta
:
PluginMeta
):
Promise
<
Data
Query
[]
>
{
async
importQueries
(
queries
:
LokiQuery
[],
originMeta
:
PluginMeta
):
Promise
<
Loki
Query
[]
>
{
return
this
.
languageProvider
.
importQueries
(
queries
,
originMeta
.
id
);
return
this
.
languageProvider
.
importQueries
(
queries
,
originMeta
.
id
);
}
}
...
@@ -114,7 +114,7 @@ export default class LokiDatasource implements DataSourceApi<LokiQuery> {
...
@@ -114,7 +114,7 @@ export default class LokiDatasource implements DataSourceApi<LokiQuery> {
});
});
}
}
modifyQuery
(
query
:
DataQuery
,
action
:
any
):
Data
Query
{
modifyQuery
(
query
:
LokiQuery
,
action
:
any
):
Loki
Query
{
const
parsed
=
parseQuery
(
query
.
expr
||
''
);
const
parsed
=
parseQuery
(
query
.
expr
||
''
);
let
selector
=
parsed
.
query
;
let
selector
=
parsed
.
query
;
switch
(
action
.
type
)
{
switch
(
action
.
type
)
{
...
@@ -129,7 +129,7 @@ export default class LokiDatasource implements DataSourceApi<LokiQuery> {
...
@@ -129,7 +129,7 @@ export default class LokiDatasource implements DataSourceApi<LokiQuery> {
return
{
...
query
,
expr
:
expression
};
return
{
...
query
,
expr
:
expression
};
}
}
getHighlighterExpression
(
query
:
Data
Query
):
string
{
getHighlighterExpression
(
query
:
Loki
Query
):
string
{
return
parseQuery
(
query
.
expr
).
regexp
;
return
parseQuery
(
query
.
expr
).
regexp
;
}
}
...
...
public/app/plugins/datasource/loki/language_provider.ts
View file @
1d290271
// Libraries
import
_
from
'lodash'
;
import
_
from
'lodash'
;
import
moment
from
'moment'
;
import
moment
from
'moment'
;
// Services & Utils
import
{
parseSelector
,
labelRegexp
,
selectorRegexp
}
from
'app/plugins/datasource/prometheus/language_utils'
;
import
syntax
from
'./syntax'
;
// Types
import
{
import
{
CompletionItem
,
CompletionItem
,
CompletionItemGroup
,
CompletionItemGroup
,
...
@@ -9,9 +15,7 @@ import {
...
@@ -9,9 +15,7 @@ import {
TypeaheadOutput
,
TypeaheadOutput
,
HistoryItem
,
HistoryItem
,
}
from
'app/types/explore'
;
}
from
'app/types/explore'
;
import
{
parseSelector
,
labelRegexp
,
selectorRegexp
}
from
'app/plugins/datasource/prometheus/language_utils'
;
import
{
LokiQuery
}
from
'./types'
;
import
syntax
from
'./syntax'
;
import
{
DataQuery
}
from
'@grafana/ui/src/types'
;
const
DEFAULT_KEYS
=
[
'job'
,
'namespace'
];
const
DEFAULT_KEYS
=
[
'job'
,
'namespace'
];
const
EMPTY_SELECTOR
=
'{}'
;
const
EMPTY_SELECTOR
=
'{}'
;
...
@@ -20,7 +24,9 @@ const HISTORY_COUNT_CUTOFF = 1000 * 60 * 60 * 24; // 24h
...
@@ -20,7 +24,9 @@ const HISTORY_COUNT_CUTOFF = 1000 * 60 * 60 * 24; // 24h
const
wrapLabel
=
(
label
:
string
)
=>
({
label
});
const
wrapLabel
=
(
label
:
string
)
=>
({
label
});
export
function
addHistoryMetadata
(
item
:
CompletionItem
,
history
:
HistoryItem
[]):
CompletionItem
{
type
LokiHistoryItem
=
HistoryItem
<
LokiQuery
>
;
export
function
addHistoryMetadata
(
item
:
CompletionItem
,
history
:
LokiHistoryItem
[]):
CompletionItem
{
const
cutoffTs
=
Date
.
now
()
-
HISTORY_COUNT_CUTOFF
;
const
cutoffTs
=
Date
.
now
()
-
HISTORY_COUNT_CUTOFF
;
const
historyForItem
=
history
.
filter
(
h
=>
h
.
ts
>
cutoffTs
&&
(
h
.
query
.
expr
as
string
)
===
item
.
label
);
const
historyForItem
=
history
.
filter
(
h
=>
h
.
ts
>
cutoffTs
&&
(
h
.
query
.
expr
as
string
)
===
item
.
label
);
const
count
=
historyForItem
.
length
;
const
count
=
historyForItem
.
length
;
...
@@ -155,7 +161,7 @@ export default class LokiLanguageProvider extends LanguageProvider {
...
@@ -155,7 +161,7 @@ export default class LokiLanguageProvider extends LanguageProvider {
return
{
context
,
refresher
,
suggestions
};
return
{
context
,
refresher
,
suggestions
};
}
}
async
importQueries
(
queries
:
DataQuery
[],
datasourceType
:
string
):
Promise
<
Data
Query
[]
>
{
async
importQueries
(
queries
:
LokiQuery
[],
datasourceType
:
string
):
Promise
<
Loki
Query
[]
>
{
if
(
datasourceType
===
'prometheus'
)
{
if
(
datasourceType
===
'prometheus'
)
{
return
Promise
.
all
(
return
Promise
.
all
(
queries
.
map
(
async
query
=>
{
queries
.
map
(
async
query
=>
{
...
...
public/app/types/explore.ts
View file @
1d290271
...
@@ -243,9 +243,9 @@ export interface ExploreUrlState {
...
@@ -243,9 +243,9 @@ export interface ExploreUrlState {
range
:
RawTimeRange
;
range
:
RawTimeRange
;
}
}
export
interface
HistoryItem
{
export
interface
HistoryItem
<
TQuery
extends
DataQuery
=
DataQuery
>
{
ts
:
number
;
ts
:
number
;
query
:
Data
Query
;
query
:
T
Query
;
}
}
export
abstract
class
LanguageProvider
{
export
abstract
class
LanguageProvider
{
...
...
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