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
c3a19c6d
Unverified
Commit
c3a19c6d
authored
Jan 27, 2020
by
Andrej Ocenas
Committed by
GitHub
Jan 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Influxdb: Fix issues with request creation and parsing (#21743)
parent
7569a860
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
50 deletions
+61
-50
public/app/core/services/backend_srv.ts
+35
-35
public/app/core/specs/backend_srv.test.ts
+0
-0
public/app/plugins/datasource/influxdb/components/InfluxLogsQueryField.tsx
+1
-0
public/app/plugins/datasource/influxdb/datasource.ts
+6
-2
public/app/plugins/datasource/influxdb/specs/datasource.test.ts
+19
-13
No files found.
public/app/core/services/backend_srv.ts
View file @
c3a19c6d
...
...
@@ -454,42 +454,9 @@ export class BackendSrv implements BackendService {
return
options
;
};
private
parseUrlFromOptions
=
(
options
:
BackendSrvRequest
):
string
=>
{
const
cleanParams
=
omitBy
(
options
.
params
,
v
=>
v
===
undefined
||
(
v
&&
v
.
length
===
0
));
const
serializedParams
=
serializeParams
(
cleanParams
);
return
options
.
params
&&
serializedParams
.
length
?
`
${
options
.
url
}
?
${
serializedParams
}
`
:
options
.
url
;
};
private
parseInitFromOptions
=
(
options
:
BackendSrvRequest
):
RequestInit
=>
{
const
method
=
options
.
method
;
const
headers
=
{
'Content-Type'
:
'application/json'
,
Accept
:
'application/json, text/plain, */*'
,
...
options
.
headers
,
};
const
body
=
this
.
parseBody
({
...
options
,
headers
});
return
{
method
,
headers
,
body
,
};
};
private
parseBody
=
(
options
:
BackendSrvRequest
)
=>
{
if
(
!
options
.
data
||
typeof
options
.
data
===
'string'
)
{
return
options
.
data
;
}
if
(
options
.
headers
[
'Content-Type'
]
===
'application/json'
)
{
return
JSON
.
stringify
(
options
.
data
);
}
return
new
URLSearchParams
(
options
.
data
);
};
private
getFromFetchStream
=
(
options
:
BackendSrvRequest
)
=>
{
const
url
=
this
.
parseUrlFromOptions
(
options
);
const
init
=
this
.
parseInitFromOptions
(
options
);
const
url
=
parseUrlFromOptions
(
options
);
const
init
=
parseInitFromOptions
(
options
);
return
this
.
dependencies
.
fromFetch
(
url
,
init
).
pipe
(
mergeMap
(
async
response
=>
{
const
{
status
,
statusText
,
ok
,
headers
,
url
,
type
,
redirected
}
=
response
;
...
...
@@ -545,3 +512,36 @@ coreModule.factory('backendSrv', () => backendSrv);
// Used for testing and things that really need BackendSrv
export
const
backendSrv
=
new
BackendSrv
();
export
const
getBackendSrv
=
():
BackendSrv
=>
backendSrv
;
export
const
parseUrlFromOptions
=
(
options
:
BackendSrvRequest
):
string
=>
{
const
cleanParams
=
omitBy
(
options
.
params
,
v
=>
v
===
undefined
||
(
v
&&
v
.
length
===
0
));
const
serializedParams
=
serializeParams
(
cleanParams
);
return
options
.
params
&&
serializedParams
.
length
?
`
${
options
.
url
}
?
${
serializedParams
}
`
:
options
.
url
;
};
export
const
parseInitFromOptions
=
(
options
:
BackendSrvRequest
):
RequestInit
=>
{
const
method
=
options
.
method
;
const
headers
=
{
'Content-Type'
:
'application/json'
,
Accept
:
'application/json, text/plain, */*'
,
...
options
.
headers
,
};
const
body
=
parseBody
({
...
options
,
headers
});
return
{
method
,
headers
,
body
,
};
};
const
parseBody
=
(
options
:
BackendSrvRequest
)
=>
{
if
(
!
options
.
data
||
typeof
options
.
data
===
'string'
)
{
return
options
.
data
;
}
if
(
options
.
headers
[
'Content-Type'
]
===
'application/json'
)
{
return
JSON
.
stringify
(
options
.
data
);
}
return
new
URLSearchParams
(
options
.
data
);
};
public/app/core/specs/backend_srv.test.ts
View file @
c3a19c6d
This diff is collapsed.
Click to expand it.
public/app/plugins/datasource/influxdb/components/InfluxLogsQueryField.tsx
View file @
c3a19c6d
...
...
@@ -81,6 +81,7 @@ export class InfluxLogsQueryField extends React.PureComponent<Props, State> {
this
.
setState
({
measurements
});
}
catch
(
error
)
{
const
message
=
error
&&
error
.
message
?
error
.
message
:
error
;
console
.
error
(
error
);
this
.
setState
({
error
:
message
});
}
}
...
...
public/app/plugins/datasource/influxdb/datasource.ts
View file @
c3a19c6d
...
...
@@ -204,7 +204,9 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
metricFindQuery
(
query
:
string
,
options
?:
any
)
{
const
interpolated
=
this
.
templateSrv
.
replace
(
query
,
null
,
'regex'
);
return
this
.
_seriesQuery
(
interpolated
,
options
).
then
(()
=>
this
.
responseParser
.
parse
(
query
));
return
this
.
_seriesQuery
(
interpolated
,
options
).
then
(
resp
=>
{
return
this
.
responseParser
.
parse
(
query
,
resp
);
});
}
getTagKeys
(
options
:
any
=
{})
{
...
...
@@ -323,7 +325,7 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
return
result
.
data
;
},
(
err
:
any
)
=>
{
if
(
err
.
status
!==
0
||
err
.
status
>=
300
)
{
if
(
(
Number
.
isInteger
(
err
.
status
)
&&
err
.
status
!==
0
)
||
err
.
status
>=
300
)
{
if
(
err
.
data
&&
err
.
data
.
error
)
{
throw
{
message
:
'InfluxDB Error: '
+
err
.
data
.
error
,
...
...
@@ -337,6 +339,8 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
config
:
err
.
config
,
};
}
}
else
{
throw
err
;
}
}
);
...
...
public/app/plugins/datasource/influxdb/specs/datasource.test.ts
View file @
c3a19c6d
...
...
@@ -31,7 +31,7 @@ describe('InfluxDataSource', () => {
to
:
'2018-01-02T00:00:00Z'
,
},
};
let
requestQuery
:
any
,
requestMethod
:
any
,
requestData
:
any
;
let
requestQuery
:
any
,
requestMethod
:
any
,
requestData
:
any
,
response
:
any
;
beforeEach
(
async
()
=>
{
datasourceRequestMock
.
mockImplementation
((
req
:
any
)
=>
{
...
...
@@ -39,21 +39,23 @@ describe('InfluxDataSource', () => {
requestQuery
=
req
.
params
.
q
;
requestData
=
req
.
data
;
return
Promise
.
resolve
({
results
:
[
{
series
:
[
{
name
:
'measurement'
,
columns
:
[
'max'
],
values
:
[[
1
]],
},
],
},
],
data
:
{
results
:
[
{
series
:
[
{
name
:
'measurement'
,
columns
:
[
'name'
],
values
:
[[
'cpu'
]],
},
],
},
],
},
});
});
await
ctx
.
ds
.
metricFindQuery
(
query
,
queryOptions
).
then
(()
=>
{}
);
response
=
await
ctx
.
ds
.
metricFindQuery
(
query
,
queryOptions
);
});
it
(
'should replace $timefilter'
,
()
=>
{
...
...
@@ -67,6 +69,10 @@ describe('InfluxDataSource', () => {
it
(
'should not have any data in request body'
,
()
=>
{
expect
(
requestData
).
toBeNull
();
});
it
(
'parse response correctly'
,
()
=>
{
expect
(
response
).
toEqual
([{
text
:
'cpu'
}]);
});
});
describe
(
'InfluxDataSource in POST query mode'
,
()
=>
{
...
...
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