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
5f4b5dfe
Unverified
Commit
5f4b5dfe
authored
Aug 01, 2019
by
Ryan McKinley
Committed by
GitHub
Aug 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor: use data rather than series in stream callback(#18126)
parent
85da4a16
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
48 additions
and
48 deletions
+48
-48
packages/grafana-ui/src/types/datasource.ts
+2
-2
public/app/features/dashboard/dashgrid/PanelChrome.tsx
+2
-2
public/app/features/dashboard/state/PanelQueryRunner.test.ts
+1
-1
public/app/features/dashboard/state/PanelQueryRunner.ts
+4
-4
public/app/features/dashboard/state/PanelQueryState.test.ts
+10
-10
public/app/features/dashboard/state/PanelQueryState.ts
+11
-11
public/app/features/explore/state/epics/runQueriesBatchEpic.test.ts
+1
-1
public/app/features/explore/state/epics/runQueriesBatchEpic.ts
+2
-2
public/app/features/explore/utils/ResultProcessor.ts
+2
-2
public/app/features/panel/metrics_panel_ctrl.ts
+2
-2
public/app/plugins/datasource/testdata/StreamHandler.ts
+4
-4
public/app/plugins/panel/graph/module.ts
+5
-5
public/app/plugins/panel/graph/specs/data_processor.test.ts
+2
-2
No files found.
packages/grafana-ui/src/types/datasource.ts
View file @
5f4b5dfe
...
...
@@ -309,9 +309,9 @@ export interface DataStreamState {
request
:
DataQueryRequest
;
/**
*
Series d
ata may not be known yet
*
D
ata may not be known yet
*/
series
?:
DataFrame
[];
data
?:
DataFrame
[];
/**
* Error in stream (but may still be running)
...
...
public/app/features/dashboard/dashgrid/PanelChrome.tsx
View file @
5f4b5dfe
...
...
@@ -11,7 +11,7 @@ import ErrorBoundary from 'app/core/components/ErrorBoundary/ErrorBoundary';
import
{
getTimeSrv
,
TimeSrv
}
from
'../services/TimeSrv'
;
import
{
applyPanelTimeOverrides
,
calculateInnerPanelHeight
}
from
'app/features/dashboard/utils/panel'
;
import
{
profiler
}
from
'app/core/profiler'
;
import
{
getProcessedDataFrame
}
from
'../state/PanelQueryState'
;
import
{
getProcessedDataFrame
s
}
from
'../state/PanelQueryState'
;
import
templateSrv
from
'app/features/templating/template_srv'
;
import
config
from
'app/core/config'
;
...
...
@@ -71,7 +71,7 @@ export class PanelChrome extends PureComponent<Props, State> {
this
.
setState
({
data
:
{
state
:
LoadingState
.
Done
,
series
:
getProcessedDataFrame
(
panel
.
snapshotData
),
series
:
getProcessedDataFrame
s
(
panel
.
snapshotData
),
},
isFirstLoad
:
false
,
});
...
...
public/app/features/dashboard/state/PanelQueryRunner.test.ts
View file @
5f4b5dfe
...
...
@@ -168,7 +168,7 @@ describe('PanelQueryRunner', () => {
streamState
=
{
state
:
LoadingState
.
Streaming
,
key
:
'test-stream-1'
,
series
:
[
data
:
[
{
rows
:
[],
fields
:
[],
...
...
public/app/features/dashboard/state/PanelQueryRunner.ts
View file @
5f4b5dfe
...
...
@@ -34,7 +34,7 @@ export interface QueryRunnerOptions<
}
export
enum
PanelQueryRunnerFormat
{
series
=
'seri
es'
,
frames
=
'fram
es'
,
legacy
=
'legacy'
,
both
=
'both'
,
}
...
...
@@ -57,7 +57,7 @@ export class PanelQueryRunner {
* Listen for updates to the PanelData. If a query has already run for this panel,
* the results will be immediatly passed to the observer
*/
subscribe
(
observer
:
PartialObserver
<
PanelData
>
,
format
=
PanelQueryRunnerFormat
.
seri
es
):
Unsubscribable
{
subscribe
(
observer
:
PartialObserver
<
PanelData
>
,
format
=
PanelQueryRunnerFormat
.
fram
es
):
Unsubscribable
{
if
(
!
this
.
subject
)
{
this
.
subject
=
new
Subject
();
// Delay creating a subject until someone is listening
}
...
...
@@ -65,10 +65,10 @@ export class PanelQueryRunner {
if
(
format
===
PanelQueryRunnerFormat
.
legacy
)
{
this
.
state
.
sendLegacy
=
true
;
}
else
if
(
format
===
PanelQueryRunnerFormat
.
both
)
{
this
.
state
.
send
Seri
es
=
true
;
this
.
state
.
send
Fram
es
=
true
;
this
.
state
.
sendLegacy
=
true
;
}
else
{
this
.
state
.
send
Seri
es
=
true
;
this
.
state
.
send
Fram
es
=
true
;
}
// Send the last result
...
...
public/app/features/dashboard/state/PanelQueryState.test.ts
View file @
5f4b5dfe
import
{
toDataQueryError
,
PanelQueryState
,
getProcessedDataFrame
}
from
'./PanelQueryState'
;
import
{
toDataQueryError
,
PanelQueryState
,
getProcessedDataFrame
s
}
from
'./PanelQueryState'
;
import
{
MockDataSourceApi
}
from
'test/mocks/datasource_srv'
;
import
{
LoadingState
}
from
'@grafana/data'
;
import
{
DataQueryResponse
}
from
'@grafana/ui'
;
...
...
@@ -65,7 +65,7 @@ describe('getProcessedDataFrame', () => {
target
:
''
,
datapoints
:
[[
100
,
1
],
[
200
,
2
]],
};
const
data
=
getProcessedDataFrame
([
null
,
input1
,
input2
,
null
,
null
]);
const
data
=
getProcessedDataFrame
s
([
null
,
input1
,
input2
,
null
,
null
]);
expect
(
data
.
length
).
toBe
(
2
);
expect
(
data
[
0
].
fields
[
0
].
name
).
toBe
(
input1
.
target
);
expect
(
data
[
0
].
rows
).
toBe
(
input1
.
datapoints
);
...
...
@@ -83,10 +83,10 @@ describe('getProcessedDataFrame', () => {
});
it
(
'supports null values from query OK'
,
()
=>
{
expect
(
getProcessedDataFrame
([
null
,
null
,
null
,
null
])).
toEqual
([]);
expect
(
getProcessedDataFrame
(
undefined
)).
toEqual
([]);
expect
(
getProcessedDataFrame
((
null
as
unknown
)
as
any
[])).
toEqual
([]);
expect
(
getProcessedDataFrame
([])).
toEqual
([]);
expect
(
getProcessedDataFrame
s
([
null
,
null
,
null
,
null
])).
toEqual
([]);
expect
(
getProcessedDataFrame
s
(
undefined
)).
toEqual
([]);
expect
(
getProcessedDataFrame
s
((
null
as
unknown
)
as
any
[])).
toEqual
([]);
expect
(
getProcessedDataFrame
s
([])).
toEqual
([]);
});
});
...
...
@@ -129,7 +129,7 @@ describe('stream handling', () => {
state
:
LoadingState
.
Loading
,
key
:
'C'
,
request
:
state
.
request
,
// From the same request
series
:
[
makeSeriesStub
(
'C'
)],
data
:
[
makeSeriesStub
(
'C'
)],
unsubscribe
:
()
=>
{},
});
expect
(
state
.
streams
.
length
).
toBe
(
1
);
...
...
@@ -146,7 +146,7 @@ describe('stream handling', () => {
state
:
LoadingState
.
Loading
,
key
:
'D'
,
request
:
state
.
request
,
// From the same request
series
:
[
makeSeriesStub
(
'D'
)],
data
:
[
makeSeriesStub
(
'D'
)],
unsubscribe
:
()
=>
{},
});
expect
(
state
.
streams
.
length
).
toBe
(
2
);
...
...
@@ -163,7 +163,7 @@ describe('stream handling', () => {
state
:
LoadingState
.
Loading
,
key
:
'C'
,
// The key to replace previous index 2
request
:
state
.
request
,
// From the same request
series
:
[
makeSeriesStub
(
'X'
)],
data
:
[
makeSeriesStub
(
'X'
)],
unsubscribe
:
()
=>
{},
});
expect
(
state
.
streams
.
length
).
toBe
(
2
);
...
...
@@ -181,7 +181,7 @@ describe('stream handling', () => {
...
state
.
request
,
requestId
:
'XXX'
,
// Different request and id
}
as
any
,
series
:
[
makeSeriesStub
(
'C'
)],
data
:
[
makeSeriesStub
(
'C'
)],
unsubscribe
:
()
=>
{},
});
...
...
public/app/features/dashboard/state/PanelQueryState.ts
View file @
5f4b5dfe
...
...
@@ -41,7 +41,7 @@ export class PanelQueryState {
// Active stream results
streams
:
DataStreamState
[]
=
[];
send
Seri
es
=
false
;
send
Fram
es
=
false
;
sendLegacy
=
false
;
// A promise for the running query
...
...
@@ -127,15 +127,15 @@ export class PanelQueryState {
this
.
executor
=
null
;
// Make sure we send something back -- called run() w/o subscribe!
if
(
!
(
this
.
send
Seri
es
||
this
.
sendLegacy
))
{
this
.
send
Seri
es
=
true
;
if
(
!
(
this
.
send
Fram
es
||
this
.
sendLegacy
))
{
this
.
send
Fram
es
=
true
;
}
// Save the result state
this
.
response
=
{
state
:
LoadingState
.
Done
,
request
:
this
.
request
,
series
:
this
.
send
Series
?
getProcessedDataFrame
(
resp
.
data
)
:
[],
series
:
this
.
send
Frames
?
getProcessedDataFrames
(
resp
.
data
)
:
[],
legacy
:
this
.
sendLegacy
?
translateToLegacyData
(
resp
.
data
)
:
undefined
,
};
resolve
(
this
.
validateStreamsAndGetPanelData
());
...
...
@@ -156,7 +156,7 @@ export class PanelQueryState {
// it will then delegate real changes to the PanelQueryRunner
dataStreamObserver
:
DataStreamObserver
=
(
stream
:
DataStreamState
)
=>
{
// Streams only work with the 'series' format
this
.
send
Seri
es
=
true
;
this
.
send
Fram
es
=
true
;
// Add the stream to our list
let
found
=
false
;
...
...
@@ -189,8 +189,8 @@ export class PanelQueryState {
const
series
:
DataFrame
[]
=
[];
for
(
const
stream
of
this
.
streams
)
{
if
(
stream
.
series
)
{
series
.
push
.
apply
(
series
,
stream
.
series
);
if
(
stream
.
data
)
{
series
.
push
.
apply
(
series
,
stream
.
data
);
}
try
{
...
...
@@ -243,7 +243,7 @@ export class PanelQueryState {
}
active
.
push
(
stream
);
series
.
push
.
apply
(
series
,
stream
.
series
);
series
.
push
.
apply
(
series
,
stream
.
data
);
if
(
!
this
.
isFinished
(
stream
.
state
))
{
done
=
false
;
...
...
@@ -277,11 +277,11 @@ export class PanelQueryState {
* Make sure all requested formats exist on the data
*/
getDataAfterCheckingFormats
():
PanelData
{
const
{
response
,
sendLegacy
,
send
Seri
es
}
=
this
;
const
{
response
,
sendLegacy
,
send
Fram
es
}
=
this
;
if
(
sendLegacy
&&
(
!
response
.
legacy
||
!
response
.
legacy
.
length
))
{
response
.
legacy
=
response
.
series
.
map
(
v
=>
toLegacyResponseData
(
v
));
}
if
(
send
Seri
es
&&
!
response
.
series
.
length
&&
response
.
legacy
)
{
if
(
send
Fram
es
&&
!
response
.
series
.
length
&&
response
.
legacy
)
{
response
.
series
=
response
.
legacy
.
map
(
v
=>
toDataFrame
(
v
));
}
return
this
.
validateStreamsAndGetPanelData
();
...
...
@@ -349,7 +349,7 @@ function translateToLegacyData(data: DataQueryResponseData) {
*
* This is also used by PanelChrome for snapshot support
*/
export
function
getProcessedDataFrame
(
results
?:
any
[]):
DataFrame
[]
{
export
function
getProcessedDataFrame
s
(
results
?:
any
[]):
DataFrame
[]
{
if
(
!
results
)
{
return
[];
}
...
...
public/app/features/explore/state/epics/runQueriesBatchEpic.test.ts
View file @
5f4b5dfe
...
...
@@ -189,7 +189,7 @@ describe('runQueriesBatchEpic', () => {
)
.
whenQueryObserverReceivesEvent
({
state
:
LoadingState
.
Done
,
series
:
null
,
data
:
null
,
delta
,
key
:
'some key'
,
request
:
{}
as
DataQueryRequest
,
...
...
public/app/features/explore/state/epics/runQueriesBatchEpic.ts
View file @
5f4b5dfe
...
...
@@ -104,8 +104,8 @@ export const runQueriesBatchEpic: Epic<ActionOf<any>, ActionOf<any>, StoreState>
// observer subscription, handles datasourceInstance.query observer events and pushes that forward
const
streamSubscription
=
streamHandler
.
subscribe
({
next
:
event
=>
{
const
{
state
,
error
,
series
,
delta
}
=
event
;
if
(
!
series
&&
!
delta
&&
!
error
)
{
const
{
state
,
error
,
data
,
delta
}
=
event
;
if
(
!
data
&&
!
delta
&&
!
error
)
{
return
;
}
...
...
public/app/features/explore/utils/ResultProcessor.ts
View file @
5f4b5dfe
...
...
@@ -3,7 +3,7 @@ import { DataQueryResponse, DataQueryResponseData } from '@grafana/ui';
import
{
TableData
,
isTableData
,
LogsModel
,
toDataFrame
,
guessFieldTypes
,
TimeSeries
}
from
'@grafana/data'
;
import
{
ExploreItemState
,
ExploreMode
}
from
'app/types/explore'
;
import
{
getProcessedDataFrame
}
from
'app/features/dashboard/state/PanelQueryState'
;
import
{
getProcessedDataFrame
s
}
from
'app/features/dashboard/state/PanelQueryState'
;
import
TableModel
,
{
mergeTablesIntoModel
}
from
'app/core/table_model'
;
import
{
sortLogsResult
}
from
'app/core/utils/explore'
;
import
{
dataFrameToLogsModel
}
from
'app/core/logs_model'
;
...
...
@@ -101,7 +101,7 @@ export class ResultProcessor {
};
private
makeTimeSeriesList
=
(
rawData
:
any
[])
=>
{
const
dataList
=
getProcessedDataFrame
(
rawData
);
const
dataList
=
getProcessedDataFrame
s
(
rawData
);
const
dataProcessor
=
new
DataProcessor
({
xaxis
:
{},
aliasColors
:
[]
});
// Hack before we use GraphSeriesXY instead
const
timeSeries
=
dataProcessor
.
getSeriesList
({
dataList
});
...
...
public/app/features/panel/metrics_panel_ctrl.ts
View file @
5f4b5dfe
...
...
@@ -158,7 +158,7 @@ class MetricsPanelCtrl extends PanelCtrl {
data
:
data
.
legacy
,
});
}
else
{
this
.
handleDataFrame
(
data
.
series
);
this
.
handleDataFrame
s
(
data
.
series
);
}
},
};
...
...
@@ -217,7 +217,7 @@ class MetricsPanelCtrl extends PanelCtrl {
});
}
handleDataFrame
(
data
:
DataFrame
[])
{
handleDataFrame
s
(
data
:
DataFrame
[])
{
if
(
this
.
dashboard
&&
this
.
dashboard
.
snapshot
)
{
this
.
panel
.
snapshotData
=
data
;
}
...
...
public/app/plugins/datasource/testdata/StreamHandler.ts
View file @
5f4b5dfe
...
...
@@ -113,7 +113,7 @@ export class StreamWorker {
const
maxRows
=
query
.
buffer
?
query
.
buffer
:
stream
.
request
.
maxDataPoints
;
// Edit the first series
const
series
=
stream
.
series
[
0
];
const
series
=
stream
.
data
[
0
];
let
rows
=
series
.
rows
.
concat
(
append
);
const
extra
=
maxRows
-
rows
.
length
;
if
(
extra
<
0
)
{
...
...
@@ -143,7 +143,7 @@ export class SignalWorker extends StreamWorker {
constructor
(
key
:
string
,
query
:
TestDataQuery
,
request
:
DataQueryRequest
,
observer
:
DataStreamObserver
)
{
super
(
key
,
query
,
request
,
observer
);
setTimeout
(()
=>
{
this
.
stream
.
series
=
[
this
.
initBuffer
(
query
.
refId
)];
this
.
stream
.
data
=
[
this
.
initBuffer
(
query
.
refId
)];
this
.
looper
();
},
10
);
...
...
@@ -253,7 +253,7 @@ export class FetchWorker extends StreamWorker {
onHeader
=
(
series
:
DataFrame
)
=>
{
series
.
refId
=
this
.
refId
;
this
.
stream
.
series
=
[
series
];
this
.
stream
.
data
=
[
series
];
};
onRow
=
(
row
:
any
[])
=>
{
...
...
@@ -269,7 +269,7 @@ export class LogsWorker extends StreamWorker {
super
(
key
,
query
,
request
,
observer
);
window
.
setTimeout
(()
=>
{
this
.
stream
.
series
=
[
this
.
initBuffer
(
query
.
refId
)];
this
.
stream
.
data
=
[
this
.
initBuffer
(
query
.
refId
)];
this
.
looper
();
},
10
);
}
...
...
public/app/plugins/panel/graph/module.ts
View file @
5f4b5dfe
...
...
@@ -13,7 +13,7 @@ import config from 'app/core/config';
import
TimeSeries
from
'app/core/time_series2'
;
import
{
DataFrame
,
DataLink
}
from
'@grafana/data'
;
import
{
getColorFromHexRgbOrName
,
LegacyResponseData
,
VariableSuggestion
}
from
'@grafana/ui'
;
import
{
getProcessedDataFrame
}
from
'app/features/dashboard/state/PanelQueryState'
;
import
{
getProcessedDataFrame
s
}
from
'app/features/dashboard/state/PanelQueryState'
;
import
{
PanelQueryRunnerFormat
}
from
'app/features/dashboard/state/PanelQueryRunner'
;
import
{
GraphContextMenuCtrl
}
from
'./GraphContextMenuCtrl'
;
import
{
getDataLinksVariableSuggestions
}
from
'app/features/panel/panellinks/link_srv'
;
...
...
@@ -143,7 +143,7 @@ class GraphCtrl extends MetricsPanelCtrl {
_
.
defaults
(
this
.
panel
.
xaxis
,
this
.
panelDefaults
.
xaxis
);
_
.
defaults
(
this
.
panel
.
options
,
this
.
panelDefaults
.
options
);
this
.
dataFormat
=
PanelQueryRunnerFormat
.
seri
es
;
this
.
dataFormat
=
PanelQueryRunnerFormat
.
fram
es
;
this
.
processor
=
new
DataProcessor
(
this
.
panel
);
this
.
contextMenuCtrl
=
new
GraphContextMenuCtrl
(
$scope
);
...
...
@@ -210,12 +210,12 @@ class GraphCtrl extends MetricsPanelCtrl {
// This should only be called from the snapshot callback
onDataReceived
(
dataList
:
LegacyResponseData
[])
{
this
.
handleDataFrame
(
getProcessedDataFrame
(
dataList
));
this
.
handleDataFrame
s
(
getProcessedDataFrames
(
dataList
));
}
// Directly support DataFrame skipping event callbacks
handleDataFrame
(
data
:
DataFrame
[])
{
super
.
handleDataFrame
(
data
);
handleDataFrame
s
(
data
:
DataFrame
[])
{
super
.
handleDataFrame
s
(
data
);
this
.
dataList
=
data
;
this
.
seriesList
=
this
.
processor
.
getSeriesList
({
...
...
public/app/plugins/panel/graph/specs/data_processor.test.ts
View file @
5f4b5dfe
import
{
DataProcessor
}
from
'../data_processor'
;
import
{
getProcessedDataFrame
}
from
'app/features/dashboard/state/PanelQueryState'
;
import
{
getProcessedDataFrame
s
}
from
'app/features/dashboard/state/PanelQueryState'
;
describe
(
'Graph DataProcessor'
,
()
=>
{
const
panel
:
any
=
{
...
...
@@ -11,7 +11,7 @@ describe('Graph DataProcessor', () => {
describe
(
'getTimeSeries from LegacyResponseData'
,
()
=>
{
// Try each type of data
const
dataList
=
getProcessedDataFrame
([
const
dataList
=
getProcessedDataFrame
s
([
{
alias
:
'First (time_series)'
,
datapoints
:
[[
1
,
1001
],
[
2
,
1002
],
[
3
,
1003
]],
...
...
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