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
331d419d
Commit
331d419d
authored
Nov 21, 2018
by
David Kaltschmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Combine query functions
parent
22987ee7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
65 deletions
+32
-65
public/app/features/explore/Explore.tsx
+30
-63
public/app/plugins/datasource/prometheus/components/PromQueryField.tsx
+2
-2
No files found.
public/app/features/explore/Explore.tsx
View file @
331d419d
...
@@ -257,12 +257,9 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
...
@@ -257,12 +257,9 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
};
};
onChangeQuery
=
(
value
:
DataQuery
,
index
:
number
,
override
?:
boolean
)
=>
{
onChangeQuery
=
(
value
:
DataQuery
,
index
:
number
,
override
?:
boolean
)
=>
{
// Keep current value in local cache
this
.
modifiedQueries
[
index
]
=
value
;
if
(
override
)
{
if
(
override
)
{
this
.
setState
(
state
=>
{
this
.
setState
(
state
=>
{
// Replace query row
// Replace query row
by injecting new key
const
{
initialQueries
,
queryTransactions
}
=
state
;
const
{
initialQueries
,
queryTransactions
}
=
state
;
const
query
:
DataQuery
=
{
const
query
:
DataQuery
=
{
...
value
,
...
value
,
...
@@ -270,6 +267,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
...
@@ -270,6 +267,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
};
};
const
nextQueries
=
[...
initialQueries
];
const
nextQueries
=
[...
initialQueries
];
nextQueries
[
index
]
=
query
;
nextQueries
[
index
]
=
query
;
this
.
modifiedQueries
=
[...
nextQueries
];
// Discard ongoing transaction related to row query
// Discard ongoing transaction related to row query
const
nextQueryTransactions
=
queryTransactions
.
filter
(
qt
=>
qt
.
rowIndex
!==
index
);
const
nextQueryTransactions
=
queryTransactions
.
filter
(
qt
=>
qt
.
rowIndex
!==
index
);
...
@@ -279,6 +277,9 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
...
@@ -279,6 +277,9 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
queryTransactions
:
nextQueryTransactions
,
queryTransactions
:
nextQueryTransactions
,
};
};
},
this
.
onSubmit
);
},
this
.
onSubmit
);
}
else
if
(
value
)
{
// Keep current value in local cache
this
.
modifiedQueries
[
index
]
=
value
;
}
}
};
};
...
@@ -463,14 +464,30 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
...
@@ -463,14 +464,30 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
onSubmit
=
()
=>
{
onSubmit
=
()
=>
{
const
{
showingLogs
,
showingGraph
,
showingTable
,
supportsGraph
,
supportsLogs
,
supportsTable
}
=
this
.
state
;
const
{
showingLogs
,
showingGraph
,
showingTable
,
supportsGraph
,
supportsLogs
,
supportsTable
}
=
this
.
state
;
// Keep table queries first since they need to return quickly
if
(
showingTable
&&
supportsTable
)
{
if
(
showingTable
&&
supportsTable
)
{
this
.
runTableQuery
();
this
.
runQueries
(
'Table'
,
{
format
:
'table'
,
instant
:
true
,
valueWithRefId
:
true
,
},
data
=>
data
[
0
]
);
}
}
if
(
showingGraph
&&
supportsGraph
)
{
if
(
showingGraph
&&
supportsGraph
)
{
this
.
runGraphQueries
();
this
.
runQueries
(
'Graph'
,
{
format
:
'time_series'
,
instant
:
false
,
},
makeTimeSeriesList
);
}
}
if
(
showingLogs
&&
supportsLogs
)
{
if
(
showingLogs
&&
supportsLogs
)
{
this
.
run
LogsQuery
(
);
this
.
run
Queries
(
'Logs'
,
{
format
:
'logs'
}
);
}
}
this
.
saveState
();
this
.
saveState
();
};
};
...
@@ -478,7 +495,8 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
...
@@ -478,7 +495,8 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
buildQueryOptions
(
query
:
DataQuery
,
queryOptions
:
{
format
:
string
;
hinting
?:
boolean
;
instant
?:
boolean
})
{
buildQueryOptions
(
query
:
DataQuery
,
queryOptions
:
{
format
:
string
;
hinting
?:
boolean
;
instant
?:
boolean
})
{
const
{
datasource
,
range
}
=
this
.
state
;
const
{
datasource
,
range
}
=
this
.
state
;
const
{
interval
,
intervalMs
}
=
getIntervals
(
range
,
datasource
,
this
.
el
.
offsetWidth
);
const
{
interval
,
intervalMs
}
=
getIntervals
(
range
,
datasource
,
this
.
el
.
offsetWidth
);
const
queries
=
[
const
configuredQueries
=
[
{
{
...
queryOptions
,
...
queryOptions
,
...
query
,
...
query
,
...
@@ -496,7 +514,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
...
@@ -496,7 +514,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
interval
,
interval
,
intervalMs
,
intervalMs
,
panelId
,
panelId
,
queries
,
targets
:
configuredQueries
,
// Datasources rely on DataQueries being passed under the targets key.
range
:
queryRange
,
range
:
queryRange
,
};
};
}
}
...
@@ -637,7 +655,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
...
@@ -637,7 +655,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
});
});
}
}
async
run
GraphQueries
(
)
{
async
run
Queries
(
resultType
:
ResultType
,
queryOptions
:
any
,
resultGetter
?:
any
)
{
const
queries
=
[...
this
.
modifiedQueries
];
const
queries
=
[...
this
.
modifiedQueries
];
if
(
!
hasNonEmptyQuery
(
queries
))
{
if
(
!
hasNonEmptyQuery
(
queries
))
{
return
;
return
;
...
@@ -646,15 +664,12 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
...
@@ -646,15 +664,12 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
const
datasourceId
=
datasource
.
meta
.
id
;
const
datasourceId
=
datasource
.
meta
.
id
;
// Run all queries concurrently
// Run all queries concurrently
queries
.
forEach
(
async
(
query
,
rowIndex
)
=>
{
queries
.
forEach
(
async
(
query
,
rowIndex
)
=>
{
const
transaction
=
this
.
startQueryTransaction
(
query
,
rowIndex
,
'Graph'
,
{
const
transaction
=
this
.
startQueryTransaction
(
query
,
rowIndex
,
resultType
,
queryOptions
);
format
:
'time_series'
,
instant
:
false
,
});
try
{
try
{
const
now
=
Date
.
now
();
const
now
=
Date
.
now
();
const
res
=
await
datasource
.
query
(
transaction
.
options
);
const
res
=
await
datasource
.
query
(
transaction
.
options
);
const
latency
=
Date
.
now
()
-
now
;
const
latency
=
Date
.
now
()
-
now
;
const
results
=
makeTimeSeriesList
(
res
.
data
)
;
const
results
=
resultGetter
?
resultGetter
(
res
.
data
)
:
res
.
data
;
this
.
completeQueryTransaction
(
transaction
.
id
,
results
,
latency
,
queries
,
datasourceId
);
this
.
completeQueryTransaction
(
transaction
.
id
,
results
,
latency
,
queries
,
datasourceId
);
this
.
setState
({
graphRange
:
transaction
.
options
.
range
});
this
.
setState
({
graphRange
:
transaction
.
options
.
range
});
}
catch
(
response
)
{
}
catch
(
response
)
{
...
@@ -663,54 +678,6 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
...
@@ -663,54 +678,6 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
});
});
}
}
async
runTableQuery
()
{
const
queries
=
[...
this
.
modifiedQueries
];
if
(
!
hasNonEmptyQuery
(
queries
))
{
return
;
}
const
{
datasource
}
=
this
.
state
;
const
datasourceId
=
datasource
.
meta
.
id
;
// Run all queries concurrently
queries
.
forEach
(
async
(
query
,
rowIndex
)
=>
{
const
transaction
=
this
.
startQueryTransaction
(
query
,
rowIndex
,
'Table'
,
{
format
:
'table'
,
instant
:
true
,
valueWithRefId
:
true
,
});
try
{
const
now
=
Date
.
now
();
const
res
=
await
datasource
.
query
(
transaction
.
options
);
const
latency
=
Date
.
now
()
-
now
;
const
results
=
res
.
data
[
0
];
this
.
completeQueryTransaction
(
transaction
.
id
,
results
,
latency
,
queries
,
datasourceId
);
}
catch
(
response
)
{
this
.
failQueryTransaction
(
transaction
.
id
,
response
,
datasourceId
);
}
});
}
async
runLogsQuery
()
{
const
queries
=
[...
this
.
modifiedQueries
];
if
(
!
hasNonEmptyQuery
(
queries
))
{
return
;
}
const
{
datasource
}
=
this
.
state
;
const
datasourceId
=
datasource
.
meta
.
id
;
// Run all queries concurrently
queries
.
forEach
(
async
(
query
,
rowIndex
)
=>
{
const
transaction
=
this
.
startQueryTransaction
(
query
,
rowIndex
,
'Logs'
,
{
format
:
'logs'
});
try
{
const
now
=
Date
.
now
();
const
res
=
await
datasource
.
query
(
transaction
.
options
);
const
latency
=
Date
.
now
()
-
now
;
const
results
=
res
.
data
;
this
.
completeQueryTransaction
(
transaction
.
id
,
results
,
latency
,
queries
,
datasourceId
);
}
catch
(
response
)
{
this
.
failQueryTransaction
(
transaction
.
id
,
response
,
datasourceId
);
}
});
}
cloneState
():
ExploreState
{
cloneState
():
ExploreState
{
// Copy state, but copy queries including modifications
// Copy state, but copy queries including modifications
return
{
return
{
...
...
public/app/plugins/datasource/prometheus/components/PromQueryField.tsx
View file @
331d419d
...
@@ -85,7 +85,7 @@ interface CascaderOption {
...
@@ -85,7 +85,7 @@ interface CascaderOption {
disabled
?:
boolean
;
disabled
?:
boolean
;
}
}
type
PromQueryFieldProps
=
{
interface
PromQueryFieldProps
{
datasource
:
any
;
datasource
:
any
;
error
?:
string
|
JSX
.
Element
;
error
?:
string
|
JSX
.
Element
;
initialQuery
:
DataQuery
;
initialQuery
:
DataQuery
;
...
@@ -95,7 +95,7 @@ type PromQueryFieldProps = {
...
@@ -95,7 +95,7 @@ type PromQueryFieldProps = {
onClickHintFix
?:
(
action
:
any
)
=>
void
;
onClickHintFix
?:
(
action
:
any
)
=>
void
;
onPressEnter
?:
()
=>
void
;
onPressEnter
?:
()
=>
void
;
onQueryChange
?:
(
value
:
DataQuery
,
override
?:
boolean
)
=>
void
;
onQueryChange
?:
(
value
:
DataQuery
,
override
?:
boolean
)
=>
void
;
}
;
}
interface
PromQueryFieldState
{
interface
PromQueryFieldState
{
metricsOptions
:
any
[];
metricsOptions
:
any
[];
...
...
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