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
412a1f6d
Commit
412a1f6d
authored
Oct 09, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: wip - return metric descriptors in the format of tablew
parent
ff5f2815
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
37 deletions
+113
-37
pkg/tsdb/stackdriver/metric_descriptors_query.go
+47
-7
pkg/tsdb/stackdriver/types.go
+21
-0
public/app/plugins/datasource/stackdriver/datasource.ts
+45
-30
No files found.
pkg/tsdb/stackdriver/metric_descriptors_query.go
View file @
412a1f6d
...
@@ -2,8 +2,11 @@ package stackdriver
...
@@ -2,8 +2,11 @@ package stackdriver
import
(
import
(
"context"
"context"
"encoding/json"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"net/http"
"strings"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/components/simplejson"
...
@@ -29,19 +32,56 @@ func (e *StackdriverExecutor) executeMetricDescriptors(ctx context.Context, tsdb
...
@@ -29,19 +32,56 @@ func (e *StackdriverExecutor) executeMetricDescriptors(ctx context.Context, tsdb
logger
.
Info
(
"error2"
,
err
)
logger
.
Info
(
"error2"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
body
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
data
,
err
:=
e
.
unmarshalMetricDescriptors
(
res
)
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Info
(
"error3"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
parts
:=
strings
.
Split
(
req
.
URL
.
Path
,
"/"
)
defaultProject
:=
parts
[
3
]
table
:=
transformMetricDescriptorResponseToTable
(
data
)
queryResult
.
Tables
=
append
(
queryResult
.
Tables
,
table
)
result
.
Results
[
tsdbQuery
.
Queries
[
0
]
.
RefId
]
=
queryResult
result
.
Results
[
tsdbQuery
.
Queries
[
0
]
.
RefId
]
.
Meta
.
Set
(
"defaultProject"
,
defaultProject
)
return
result
,
nil
}
func
transformMetricDescriptorResponseToTable
(
data
MetricDescriptorsResponse
)
*
tsdb
.
Table
{
table
:=
&
tsdb
.
Table
{
Columns
:
make
([]
tsdb
.
TableColumn
,
1
),
Rows
:
make
([]
tsdb
.
RowValues
,
0
),
}
table
.
Columns
[
0
]
.
Text
=
"metricDescriptor"
for
_
,
r
:=
range
data
.
MetricDescriptors
{
values
:=
make
([]
interface
{},
1
)
values
[
0
]
=
r
table
.
Rows
=
append
(
table
.
Rows
,
values
)
}
return
table
}
func
(
e
*
StackdriverExecutor
)
unmarshalMetricDescriptors
(
res
*
http
.
Response
)
(
MetricDescriptorsResponse
,
error
)
{
body
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
defer
res
.
Body
.
Close
()
defer
res
.
Body
.
Close
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
MetricDescriptorsResponse
{}
,
err
}
}
queryResult
.
Meta
.
Set
(
"test"
,
string
(
body
))
if
res
.
StatusCode
/
100
!=
2
{
logger
.
Info
(
"string(body)"
,
"string(body)"
,
string
(
body
))
slog
.
Error
(
"Request failed"
,
"status"
,
res
.
Status
,
"body"
,
string
(
body
))
result
.
Results
[
tsdbQuery
.
Queries
[
0
]
.
RefId
]
=
queryResult
return
MetricDescriptorsResponse
{},
fmt
.
Errorf
(
string
(
body
))
}
return
result
,
nil
var
data
MetricDescriptorsResponse
err
=
json
.
Unmarshal
(
body
,
&
data
)
if
err
!=
nil
{
slog
.
Error
(
"Failed to unmarshal MetricDescriptorResponse"
,
"error"
,
err
,
"status"
,
res
.
Status
,
"body"
,
string
(
body
))
return
MetricDescriptorsResponse
{},
err
}
return
data
,
nil
}
}
pkg/tsdb/stackdriver/types.go
View file @
412a1f6d
...
@@ -73,3 +73,24 @@ type StackdriverResponse struct {
...
@@ -73,3 +73,24 @@ type StackdriverResponse struct {
}
`json:"points"`
}
`json:"points"`
}
`json:"timeSeries"`
}
`json:"timeSeries"`
}
}
type
MetricDescriptorsResponse
struct
{
MetricDescriptors
[]
struct
{
Name
string
`json:"name"`
Labels
[]
struct
{
Key
string
`json:"key"`
Description
string
`json:"description"`
}
`json:"labels,omitempty"`
MetricKind
string
`json:"metricKind"`
ValueType
string
`json:"valueType"`
Unit
string
`json:"unit,omitempty"`
Description
string
`json:"description"`
DisplayName
string
`json:"displayName"`
Type
string
`json:"type"`
Metadata
struct
{
LaunchStage
string
`json:"launchStage"`
SamplePeriod
string
`json:"samplePeriod"`
IngestDelay
string
`json:"ingestDelay"`
}
`json:"metadata"`
}
`json:"metricDescriptors"`
}
public/app/plugins/datasource/stackdriver/datasource.ts
View file @
412a1f6d
...
@@ -173,38 +173,53 @@ export default class StackdriverDatasource {
...
@@ -173,38 +173,53 @@ export default class StackdriverDatasource {
throw
new
Error
(
'Template variables support is not yet imlemented'
);
throw
new
Error
(
'Template variables support is not yet imlemented'
);
}
}
testDatasource
()
{
async
testDatasource
()
{
const
path
=
`v3/projects/
${
this
.
projectName
}
/metricDescriptors`
;
const
{
data
}
=
await
this
.
backendSrv
.
datasourceRequest
({
return
this
.
doRequest
(
`
${
this
.
baseUrl
}${
path
}
`
)
url
:
'/api/tsdb/query'
,
.
then
(
response
=>
{
method
:
'POST'
,
if
(
response
.
status
===
200
)
{
data
:
{
return
{
queries
:
[
status
:
'success'
,
{
message
:
'Successfully queried the Stackdriver API.'
,
refId
:
'metricDescriptors'
,
title
:
'Success'
,
datasourceId
:
this
.
id
,
};
type
:
'metricDescriptors'
,
}
},
],
},
});
console
.
log
(
data
);
return
data
;
// const path = `v3/projects/${this.projectName}/metricDescriptors`;
// return this.doRequest(`${this.baseUrl}${path}`)
// .then(response => {
// if (response.status === 200) {
// return {
// status: 'success',
// message: 'Successfully queried the Stackdriver API.',
// title: 'Success',
// };
// }
return
{
//
return {
status
:
'error'
,
//
status: 'error',
message
:
'Returned http status code '
+
response
.
status
,
//
message: 'Returned http status code ' + response.status,
};
//
};
})
//
})
.
catch
(
error
=>
{
//
.catch(error => {
let
message
=
'Stackdriver: '
;
//
let message = 'Stackdriver: ';
message
+=
error
.
statusText
?
error
.
statusText
+
': '
:
''
;
//
message += error.statusText ? error.statusText + ': ' : '';
if
(
error
.
data
&&
error
.
data
.
error
&&
error
.
data
.
error
.
code
)
{
//
if (error.data && error.data.error && error.data.error.code) {
// 400, 401
//
// 400, 401
message
+=
error
.
data
.
error
.
code
+
'. '
+
error
.
data
.
error
.
message
;
//
message += error.data.error.code + '. ' + error.data.error.message;
}
else
{
//
} else {
message
+=
'Cannot connect to Stackdriver API'
;
//
message += 'Cannot connect to Stackdriver API';
}
//
}
return
{
//
return {
status
:
'error'
,
//
status: 'error',
message
:
message
,
//
message: message,
};
//
};
});
//
});
}
}
async
getProjects
()
{
async
getProjects
()
{
...
...
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