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
e05b8637
Commit
e05b8637
authored
Sep 18, 2018
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: remove hardcoding of test project name
parent
7b8ea5fc
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
20 additions
and
21 deletions
+20
-21
pkg/tsdb/stackdriver/stackdriver.go
+2
-11
public/app/plugins/datasource/stackdriver/datasource.ts
+3
-1
public/app/plugins/datasource/stackdriver/query_ctrl.ts
+1
-1
public/app/plugins/datasource/stackdriver/specs/datasource.test.ts
+11
-6
public/app/plugins/datasource/stackdriver/specs/query_ctrl.test.ts
+1
-0
public/app/plugins/datasource/stackdriver/specs/testData.ts
+2
-2
No files found.
pkg/tsdb/stackdriver/stackdriver.go
View file @
e05b8637
...
@@ -138,7 +138,6 @@ func (e *StackdriverExecutor) buildQueries(tsdbQuery *tsdb.TsdbQuery) ([]*Stackd
...
@@ -138,7 +138,6 @@ func (e *StackdriverExecutor) buildQueries(tsdbQuery *tsdb.TsdbQuery) ([]*Stackd
func
setAggParams
(
params
*
url
.
Values
,
query
*
tsdb
.
Query
)
{
func
setAggParams
(
params
*
url
.
Values
,
query
*
tsdb
.
Query
)
{
primaryAggregation
:=
query
.
Model
.
Get
(
"primaryAggregation"
)
.
MustString
()
primaryAggregation
:=
query
.
Model
.
Get
(
"primaryAggregation"
)
.
MustString
()
secondaryAggregation
:=
query
.
Model
.
Get
(
"secondaryAggregation"
)
.
MustString
()
perSeriesAligner
:=
query
.
Model
.
Get
(
"perSeriesAligner"
)
.
MustString
()
perSeriesAligner
:=
query
.
Model
.
Get
(
"perSeriesAligner"
)
.
MustString
()
alignmentPeriod
:=
query
.
Model
.
Get
(
"alignmentPeriod"
)
.
MustString
()
alignmentPeriod
:=
query
.
Model
.
Get
(
"alignmentPeriod"
)
.
MustString
()
...
@@ -146,18 +145,10 @@ func setAggParams(params *url.Values, query *tsdb.Query) {
...
@@ -146,18 +145,10 @@ func setAggParams(params *url.Values, query *tsdb.Query) {
primaryAggregation
=
"REDUCE_NONE"
primaryAggregation
=
"REDUCE_NONE"
}
}
if
secondaryAggregation
==
""
{
secondaryAggregation
=
"REDUCE_NONE"
}
if
perSeriesAligner
==
""
{
if
perSeriesAligner
==
""
{
perSeriesAligner
=
"ALIGN_MEAN"
perSeriesAligner
=
"ALIGN_MEAN"
}
}
if
secondaryAggregation
==
""
{
secondaryAggregation
=
"REDUCE_NONE"
}
if
alignmentPeriod
==
"auto"
||
alignmentPeriod
==
""
{
if
alignmentPeriod
==
"auto"
||
alignmentPeriod
==
""
{
alignmentPeriodValue
:=
int
(
math
.
Max
(
float64
(
query
.
IntervalMs
),
60.0
))
alignmentPeriodValue
:=
int
(
math
.
Max
(
float64
(
query
.
IntervalMs
),
60.0
))
alignmentPeriod
=
"+"
+
strconv
.
Itoa
(
alignmentPeriodValue
)
+
"s"
alignmentPeriod
=
"+"
+
strconv
.
Itoa
(
alignmentPeriodValue
)
+
"s"
...
@@ -172,7 +163,6 @@ func setAggParams(params *url.Values, query *tsdb.Query) {
...
@@ -172,7 +163,6 @@ func setAggParams(params *url.Values, query *tsdb.Query) {
params
.
Add
(
"aggregation.crossSeriesReducer"
,
primaryAggregation
)
params
.
Add
(
"aggregation.crossSeriesReducer"
,
primaryAggregation
)
params
.
Add
(
"aggregation.perSeriesAligner"
,
perSeriesAligner
)
params
.
Add
(
"aggregation.perSeriesAligner"
,
perSeriesAligner
)
params
.
Add
(
"aggregation.alignmentPeriod"
,
alignmentPeriod
)
params
.
Add
(
"aggregation.alignmentPeriod"
,
alignmentPeriod
)
// params.Add("aggregation.secondaryAggregation.crossSeriesReducer", secondaryAggregation)
groupBys
:=
query
.
Model
.
Get
(
"groupBys"
)
.
MustArray
()
groupBys
:=
query
.
Model
.
Get
(
"groupBys"
)
.
MustArray
()
if
len
(
groupBys
)
>
0
{
if
len
(
groupBys
)
>
0
{
...
@@ -317,7 +307,8 @@ func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models.
...
@@ -317,7 +307,8 @@ func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models.
if
!
ok
{
if
!
ok
{
return
nil
,
errors
.
New
(
"Unable to find datasource plugin Stackdriver"
)
return
nil
,
errors
.
New
(
"Unable to find datasource plugin Stackdriver"
)
}
}
proxyPass
:=
fmt
.
Sprintf
(
"stackdriver%s"
,
"v3/projects/raintank-production/timeSeries"
)
projectName
:=
dsInfo
.
JsonData
.
Get
(
"defaultProject"
)
.
MustString
()
proxyPass
:=
fmt
.
Sprintf
(
"stackdriver%s"
,
"v3/projects/"
+
projectName
+
"/timeSeries"
)
var
stackdriverRoute
*
plugins
.
AppPluginRoute
var
stackdriverRoute
*
plugins
.
AppPluginRoute
for
_
,
route
:=
range
plugin
.
Routes
{
for
_
,
route
:=
range
plugin
.
Routes
{
...
...
public/app/plugins/datasource/stackdriver/datasource.ts
View file @
e05b8637
...
@@ -3,12 +3,14 @@ export default class StackdriverDatasource {
...
@@ -3,12 +3,14 @@ export default class StackdriverDatasource {
id
:
number
;
id
:
number
;
url
:
string
;
url
:
string
;
baseUrl
:
string
;
baseUrl
:
string
;
projectName
:
string
;
constructor
(
instanceSettings
,
private
backendSrv
)
{
constructor
(
instanceSettings
,
private
backendSrv
)
{
this
.
baseUrl
=
`/stackdriver/`
;
this
.
baseUrl
=
`/stackdriver/`
;
this
.
url
=
instanceSettings
.
url
;
this
.
url
=
instanceSettings
.
url
;
this
.
doRequest
=
this
.
doRequest
;
this
.
doRequest
=
this
.
doRequest
;
this
.
id
=
instanceSettings
.
id
;
this
.
id
=
instanceSettings
.
id
;
this
.
projectName
=
instanceSettings
.
jsonData
.
defaultProject
||
''
;
}
}
async
getTimeSeries
(
options
)
{
async
getTimeSeries
(
options
)
{
...
@@ -73,7 +75,7 @@ export default class StackdriverDatasource {
...
@@ -73,7 +75,7 @@ export default class StackdriverDatasource {
}
}
testDatasource
()
{
testDatasource
()
{
const
path
=
`v3/projects/
raintank-production
/metricDescriptors`
;
const
path
=
`v3/projects/
${
this
.
projectName
}
/metricDescriptors`
;
return
this
.
doRequest
(
`
${
this
.
baseUrl
}${
path
}
`
)
return
this
.
doRequest
(
`
${
this
.
baseUrl
}${
path
}
`
)
.
then
(
response
=>
{
.
then
(
response
=>
{
if
(
response
.
status
===
200
)
{
if
(
response
.
status
===
200
)
{
...
...
public/app/plugins/datasource/stackdriver/query_ctrl.ts
View file @
e05b8637
...
@@ -134,7 +134,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
...
@@ -134,7 +134,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
}
}
async
getMetricTypes
()
{
async
getMetricTypes
()
{
//projects/
raintank-production
/metricDescriptors/agent.googleapis.com/agent/api_request_count
//projects/
your-project-name
/metricDescriptors/agent.googleapis.com/agent/api_request_count
if
(
this
.
target
.
project
.
id
!==
'default'
)
{
if
(
this
.
target
.
project
.
id
!==
'default'
)
{
const
metricTypes
=
await
this
.
datasource
.
getMetricTypes
(
this
.
target
.
project
.
id
);
const
metricTypes
=
await
this
.
datasource
.
getMetricTypes
(
this
.
target
.
project
.
id
);
if
(
this
.
target
.
metricType
===
this
.
defaultDropdownValue
&&
metricTypes
.
length
>
0
)
{
if
(
this
.
target
.
metricType
===
this
.
defaultDropdownValue
&&
metricTypes
.
length
>
0
)
{
...
...
public/app/plugins/datasource/stackdriver/specs/datasource.test.ts
View file @
e05b8637
...
@@ -3,6 +3,11 @@ import { metricDescriptors } from './testData';
...
@@ -3,6 +3,11 @@ import { metricDescriptors } from './testData';
import
moment
from
'moment'
;
import
moment
from
'moment'
;
describe
(
'StackdriverDataSource'
,
()
=>
{
describe
(
'StackdriverDataSource'
,
()
=>
{
const
instanceSettings
=
{
jsonData
:
{
projectName
:
'testproject'
,
},
};
describe
(
'when performing testDataSource'
,
()
=>
{
describe
(
'when performing testDataSource'
,
()
=>
{
describe
(
'and call to stackdriver api succeeds'
,
()
=>
{
describe
(
'and call to stackdriver api succeeds'
,
()
=>
{
let
ds
;
let
ds
;
...
@@ -13,7 +18,7 @@ describe('StackdriverDataSource', () => {
...
@@ -13,7 +18,7 @@ describe('StackdriverDataSource', () => {
return
Promise
.
resolve
({
status
:
200
});
return
Promise
.
resolve
({
status
:
200
});
},
},
};
};
ds
=
new
StackdriverDataSource
(
{}
,
backendSrv
);
ds
=
new
StackdriverDataSource
(
instanceSettings
,
backendSrv
);
result
=
await
ds
.
testDatasource
();
result
=
await
ds
.
testDatasource
();
});
});
it
(
'should return successfully'
,
()
=>
{
it
(
'should return successfully'
,
()
=>
{
...
@@ -28,7 +33,7 @@ describe('StackdriverDataSource', () => {
...
@@ -28,7 +33,7 @@ describe('StackdriverDataSource', () => {
const
backendSrv
=
{
const
backendSrv
=
{
datasourceRequest
:
async
()
=>
Promise
.
resolve
({
status
:
200
,
data
:
metricDescriptors
}),
datasourceRequest
:
async
()
=>
Promise
.
resolve
({
status
:
200
,
data
:
metricDescriptors
}),
};
};
ds
=
new
StackdriverDataSource
(
{}
,
backendSrv
);
ds
=
new
StackdriverDataSource
(
instanceSettings
,
backendSrv
);
result
=
await
ds
.
testDatasource
();
result
=
await
ds
.
testDatasource
();
});
});
it
(
'should return status success'
,
()
=>
{
it
(
'should return status success'
,
()
=>
{
...
@@ -47,7 +52,7 @@ describe('StackdriverDataSource', () => {
...
@@ -47,7 +52,7 @@ describe('StackdriverDataSource', () => {
data
:
{
error
:
{
code
:
400
,
message
:
'Field interval.endTime had an invalid value'
}
},
data
:
{
error
:
{
code
:
400
,
message
:
'Field interval.endTime had an invalid value'
}
},
}),
}),
};
};
ds
=
new
StackdriverDataSource
(
{}
,
backendSrv
);
ds
=
new
StackdriverDataSource
(
instanceSettings
,
backendSrv
);
result
=
await
ds
.
testDatasource
();
result
=
await
ds
.
testDatasource
();
});
});
...
@@ -83,7 +88,7 @@ describe('StackdriverDataSource', () => {
...
@@ -83,7 +88,7 @@ describe('StackdriverDataSource', () => {
return
Promise
.
resolve
({
status
:
200
,
data
:
response
});
return
Promise
.
resolve
({
status
:
200
,
data
:
response
});
},
},
};
};
ds
=
new
StackdriverDataSource
(
{}
,
backendSrv
);
ds
=
new
StackdriverDataSource
(
instanceSettings
,
backendSrv
);
result
=
await
ds
.
getProjects
();
result
=
await
ds
.
getProjects
();
});
});
...
@@ -132,7 +137,7 @@ describe('StackdriverDataSource', () => {
...
@@ -132,7 +137,7 @@ describe('StackdriverDataSource', () => {
const
backendSrv
=
{
const
backendSrv
=
{
datasourceRequest
:
async
()
=>
Promise
.
resolve
({
status
:
200
,
data
:
response
}),
datasourceRequest
:
async
()
=>
Promise
.
resolve
({
status
:
200
,
data
:
response
}),
};
};
ds
=
new
StackdriverDataSource
(
{}
,
backendSrv
);
ds
=
new
StackdriverDataSource
(
instanceSettings
,
backendSrv
);
});
});
it
(
'should return a list of datapoints'
,
()
=>
{
it
(
'should return a list of datapoints'
,
()
=>
{
...
@@ -166,7 +171,7 @@ describe('StackdriverDataSource', () => {
...
@@ -166,7 +171,7 @@ describe('StackdriverDataSource', () => {
});
});
},
},
};
};
ds
=
new
StackdriverDataSource
(
{}
,
backendSrv
);
ds
=
new
StackdriverDataSource
(
instanceSettings
,
backendSrv
);
result
=
await
ds
.
getMetricTypes
();
result
=
await
ds
.
getMetricTypes
();
});
});
it
(
'should return successfully'
,
()
=>
{
it
(
'should return successfully'
,
()
=>
{
...
...
public/app/plugins/datasource/stackdriver/specs/query_ctrl.test.ts
View file @
e05b8637
...
@@ -401,6 +401,7 @@ function createTarget(existingFilters?: string[]) {
...
@@ -401,6 +401,7 @@ function createTarget(existingFilters?: string[]) {
refId
:
'A'
,
refId
:
'A'
,
aggregation
:
{
aggregation
:
{
crossSeriesReducer
:
''
,
crossSeriesReducer
:
''
,
secondaryCrossSeriesReducer
:
''
,
alignmentPeriod
:
''
,
alignmentPeriod
:
''
,
perSeriesAligner
:
''
,
perSeriesAligner
:
''
,
groupBys
:
[],
groupBys
:
[],
...
...
public/app/plugins/datasource/stackdriver/specs/testData.ts
View file @
e05b8637
export
const
metricDescriptors
=
[
export
const
metricDescriptors
=
[
{
{
name
:
'projects/
raintank-production
/metricDescriptors/agent.googleapis.com/agent/api_request_count'
,
name
:
'projects/
grafana-prod
/metricDescriptors/agent.googleapis.com/agent/api_request_count'
,
labels
:
[
labels
:
[
{
{
key
:
'state'
,
key
:
'state'
,
...
@@ -20,7 +20,7 @@ export const metricDescriptors = [
...
@@ -20,7 +20,7 @@ export const metricDescriptors = [
},
},
},
},
{
{
name
:
'projects/
raintank-production
/metricDescriptors/agent.googleapis.com/agent/log_entry_count'
,
name
:
'projects/
grafana-prod
/metricDescriptors/agent.googleapis.com/agent/log_entry_count'
,
labels
:
[
labels
:
[
{
{
key
:
'response_code'
,
key
:
'response_code'
,
...
...
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