Skip to content

Commit 954aa50

Browse files
committed
Fix $namespase and $metric variables
1 parent ddd035b commit 954aa50

File tree

7 files changed

+69
-46
lines changed

7 files changed

+69
-46
lines changed

build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ fi
3535

3636
echo "building go binary"
3737
GOOS=$GOOS go build -o ./dist/oci-plugin$POST
38+
39+
# GOOS=linux go build -o ./dist/oci-plugin_linux_amd64
40+
# GOOS=windows GOARCH=amd64 go build -o ./dist/oci-plugin_windows_amd64.exe
41+
# tar cvf plugin.tar ./dist
42+
-59.8 KB
Loading

docs/linux.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ To [install the data source](https://grafana.com/plugins/oci-datasource/installa
3737
grafana-cli plugins install oci-datasource
3838
```
3939

40-
The plugin will be installed into your Grafana plugins directory, which by default is located at /var/lib/grafana/plugins. [Here is more information on the CLI tool](http://docs.grafana.org/plugins/installation/). Alternatively, you can manually download the .zip file and unpack it into your /grafana/plugins directory. To do so, change to the Grafana plugins directory: `cd /usr/local/var/lib/grafana/plugins`. Download the OCI Grafana Plugin: wget `https://grafana.com/api/plugins/oci-datasource/versions/1.0.0/download`. Create a directory and install the plugin: `mkdir oci && tar -C oci -xvf plugin.tar` and then remove the tarball: `rm plugin.tar`.
40+
**NOTE** Today the latest version of the plugin is available only with the manual installation
41+
42+
The plugin will be installed into your Grafana plugins directory, which by default is located at /var/lib/grafana/plugins. [Here is more information on the CLI tool](http://docs.grafana.org/plugins/installation/).
43+
44+
### Manually installation
45+
Alternatively, you can manually download the .tar file and unpack it into your /grafana/plugins directory. To do so, change to the Grafana plugins directory: `cd /usr/local/var/lib/grafana/plugins`. Download the OCI Grafana Plugin: wget `https://github.com/oracle/oci-grafana-plugin/releases/download/V1.0.4/plugin.tar`. Create a directory and install the plugin: `mkdir oci && tar -C oci -xvf plugin.tar` and then remove the tarball: `rm plugin.tar`.
4146

4247
To start the Grafana server, run: `sudo systemctl start grafana-server`.
4348

docs/linuxoci.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ To [install the data source](https://grafana.com/plugins/oci-datasource/installa
3030
```
3131
grafana-cli plugins install oci-datasource
3232
```
33+
**NOTE** Today the latest version of the plugin is available only with the manual installation
3334

34-
The plugin will be installed into your Grafana plugins directory, which by default is located at /var/lib/grafana/plugins. [Here is more information on the CLI tool](http://docs.grafana.org/plugins/installation/). Alternatively, you can manually download the .zip file and unpack it into your /grafana/plugins directory. To do so, change to the Grafana plugins directory: `cd /usr/local/var/lib/grafana/plugins`. Download the OCI Grafana Plugin: wget `https://grafana.com/api/plugins/oci-datasource/versions/1.0.0/download`. Create a directory and install the plugin: `mkdir oci && tar -C oci -xvf plugin.tar` and then remove the tarball: `rm plugin.tar`.
35+
The plugin will be installed into your Grafana plugins directory, which by default is located at /var/lib/grafana/plugins. [Here is more information on the CLI tool](http://docs.grafana.org/plugins/installation/).
36+
37+
### Manually installation
38+
Alternatively, you can manually download the .tar file and unpack it into your /grafana/plugins directory. To do so, change to the Grafana plugins directory: `cd /usr/local/var/lib/grafana/plugins`. Download the OCI Grafana Plugin: wget `https://github.com/oracle/oci-grafana-plugin/releases/download/V1.0.4/plugin.tar`. Create a directory and install the plugin: `mkdir oci && tar -C oci -xvf plugin.tar` and then remove the tarball: `rm plugin.tar`.
3539

3640
To start the Grafana server, run: `sudo systemctl start grafana-server`.
3741

docs/macos.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ To [install the data source](https://grafana.com/plugins/oci-datasource/installa
3535
```
3636
grafana-cli plugins install oci-datasource
3737
```
38+
**NOTE** Today the latest version of the plugin is available only with the manual installation
3839

39-
The plugin will be installed into your Grafana plugins directory, which by default is located at /var/lib/grafana/plugins. [Here is more information on the CLI tool](http://docs.grafana.org/plugins/installation/). Alternatively, you can manually download the .zip file and unpack it into your /grafana/plugins directory. To do so, change to the Grafana plugins directory: `cd /usr/local/var/lib/grafana/plugins`. Download the OCI Grafana Plugin: wget `https://grafana.com/api/plugins/oci-datasource/versions/1.0.0/download`. Create a directory and install the plugin: `mkdir oci && tar -C oci -xvf plugin.tar` and then remove the tarball: `rm plugin.tar`
40+
The plugin will be installed into your Grafana plugins directory, which by default is located at /var/lib/grafana/plugins. [Here is more information on the CLI tool](http://docs.grafana.org/plugins/installation/).
41+
42+
### Manually installation
43+
Alternatively, you can manually download the .tar file and unpack it into your /grafana/plugins directory. To do so, change to the Grafana plugins directory: `cd /usr/local/var/lib/grafana/plugins`. Download the OCI Grafana Plugin: wget `https://github.com/oracle/oci-grafana-plugin/releases/download/V1.0.4/plugin.tar`. Create a directory and install the plugin: `mkdir oci && tar -C oci -xvf plugin.tar` and then remove the tarball: `rm plugin.tar`
4044

4145
To start the Grafana server, run: `brew services start grafana`
4246

docs/using.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ The page will load a preview of valuables available for that variable. Scroll do
4444

4545
Repeat the process for the following OCI variables:
4646

47-
| Name | Query |
48-
| ----------- | ---------------------------------- |
49-
| region | `regions()` |
50-
| compartment | `compartments()` |
51-
| namespace | `namespaces()` |
52-
| metric | `metrics($namespace,$compartment)` |
47+
| Name | Query |
48+
| ----------- | ------------------------------------------ |
49+
| region | `regions()` |
50+
| compartment | `compartments()` |
51+
| namespace | `namespaces($region,$compartment)` |
52+
| metric | `metrics($region,$compartment,$namespace)` |
5353

5454
The final list of variables should look like this:
5555

src/datasource.js

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { aggregations, namespaces } from './constants'
77
import retryOrThrow from './util/retry'
88

99
export default class OCIDatasource {
10-
constructor (instanceSettings, $q, backendSrv, templateSrv, timeSrv) {
10+
constructor(instanceSettings, $q, backendSrv, templateSrv, timeSrv) {
1111
this.type = instanceSettings.type
1212
this.url = instanceSettings.url
1313
this.name = instanceSettings.name
@@ -21,7 +21,7 @@ export default class OCIDatasource {
2121
this.timeSrv = timeSrv
2222
}
2323

24-
query (options) {
24+
query(options) {
2525
var query = this.buildQueryParameters(options)
2626
query.targets = query.targets.filter(t => !t.hide)
2727
if (query.targets.length <= 0) {
@@ -47,7 +47,7 @@ export default class OCIDatasource {
4747
})
4848
}
4949

50-
buildQueryParameters (options) {
50+
buildQueryParameters(options) {
5151
// remove placeholder targets
5252
options.targets = _.filter(options.targets, target => {
5353
return target.metric !== 'select metric'
@@ -94,7 +94,7 @@ export default class OCIDatasource {
9494
return options
9595
}
9696

97-
testDatasource () {
97+
testDatasource() {
9898
return this.doRequest({
9999
targets: [{
100100
queryType: 'test',
@@ -115,7 +115,7 @@ export default class OCIDatasource {
115115
}
116116

117117
// helps match the regex's from creating template variables in grafana
118-
templateMeticSearch (varString) {
118+
templateMeticSearch(varString) {
119119
let compartmentQuery = varString.match(/^compartments\(\)/)
120120
if (compartmentQuery) {
121121
return this.getCompartments().catch(err => { throw new Error('Unable to make request ' + err) })
@@ -126,21 +126,24 @@ export default class OCIDatasource {
126126
return this.getRegions().catch(err => { throw new Error('Unable to make request ' + err) })
127127
}
128128

129-
let metricQuery = varString.match(/metrics\((\$?\w+)(,\s*\$\w+)*\)/)
129+
let metricQuery = varString.match(/metrics\((\s*\$?\w+)(\s*,\s*\$\w+)(\s*,\s*\$\w+\s*)*\)/)
130130
if (metricQuery) {
131131
let target = {
132-
namespace: this.templateSrv.replace(metricQuery[1]),
133-
compartment: this.templateSrv.replace(metricQuery[2]).replace(',', '').trim()
132+
region: this.templateSrv.replace(metricQuery[1].trim()),
133+
compartment: this.templateSrv.replace(metricQuery[2].replace(',', '').trim()),
134+
namespace: this.templateSrv.replace(metricQuery[3].replace(',', '').trim())
134135
}
135136
return this.metricFindQuery(target).catch(err => { throw new Error('Unable to make request ' + err) })
136137
}
137138

138-
let namespaceQuery = varString.match(/namespaces\(\)/)
139+
let namespaceQuery = varString.match(/namespaces\((\$?\w+)(,\s*\$\w+)*\)/)
139140
if (namespaceQuery) {
140-
let names = namespaces.map((reg) => {
141-
return { row: reg, value: reg }
142-
})
143-
return this.q.when(names)
141+
142+
let target = {
143+
region: this.templateSrv.replace(namespaceQuery[1]),
144+
compartment: this.templateSrv.replace(namespaceQuery[2]).replace(',', '').trim()
145+
}
146+
return this.getNamespaces(target).catch(err => { throw new Error('Unable to make request(get namespaces) ' + err) })
144147
}
145148
throw new Error('Unable to parse templating string')
146149
}
@@ -149,7 +152,7 @@ export default class OCIDatasource {
149152
// and is the entrypoint for templating according to grafana -- since this wasn't docuemnted
150153
// in grafana I was lead to believe that it did the former
151154
// TODO: break the metric finding for the query editor out into a different function
152-
metricFindQuery (target) {
155+
metricFindQuery(target) {
153156
if (typeof (target) === 'string') {
154157
return this.templateMeticSearch(target)
155158
}
@@ -184,7 +187,7 @@ export default class OCIDatasource {
184187
})
185188
}
186189

187-
mapToTextValue (result, searchField) {
190+
mapToTextValue(result, searchField) {
188191
var table = result.data.results[searchField].tables[0]
189192
if (!table) {
190193
return []
@@ -201,7 +204,7 @@ export default class OCIDatasource {
201204
return m
202205
}
203206

204-
getCompartments () {
207+
getCompartments() {
205208
var range = this.timeSrv.timeRange()
206209
var targets = [{
207210
environment: this.environment,
@@ -217,7 +220,7 @@ export default class OCIDatasource {
217220
return this.doRequest(options).then((res) => { return this.mapToTextValue(res, 'compartment') })
218221
}
219222

220-
getDimensions (target) {
223+
getDimensions(target) {
221224
var range = this.timeSrv.timeRange()
222225
let region = target.region
223226
if (target.namespace === 'select namespace') {
@@ -252,41 +255,43 @@ export default class OCIDatasource {
252255
return this.doRequest(options).then((res) => { return this.mapToTextValue(res, 'dimensions') })
253256
}
254257

255-
getNamespaces (target) {
258+
getNamespaces(target) {
256259
let region = target.region
257260
if (region === 'select region') {
258261
region = this.defaultRegion
259262
}
260-
return this.doRequest({ targets: [{
261-
// commonRequestParameters
262-
compartment: this.templateSrv.replace(target.compartment),
263-
environment: this.environment,
264-
queryType: 'namespaces',
265-
region: this.templateSrv.replace(region),
266-
tenancyOCID: this.tenancyOCID,
263+
return this.doRequest({
264+
targets: [{
265+
// commonRequestParameters
266+
compartment: this.templateSrv.replace(target.compartment),
267+
environment: this.environment,
268+
queryType: 'namespaces',
269+
region: this.templateSrv.replace(region),
270+
tenancyOCID: this.tenancyOCID,
267271

268-
datasourceId: this.id
269-
}],
270-
range: this.timeSrv.timeRange()
272+
datasourceId: this.id
273+
}],
274+
range: this.timeSrv.timeRange()
271275
}).then((namespaces) => { return this.mapToTextValue(namespaces, 'namespaces') })
272276
}
273277

274-
getRegions () {
275-
return this.doRequest({ targets: [{
276-
environment: this.environment,
277-
queryType: 'regions',
278-
datasourceId: this.id
279-
}],
280-
range: this.timeSrv.timeRange()
278+
getRegions() {
279+
return this.doRequest({
280+
targets: [{
281+
environment: this.environment,
282+
queryType: 'regions',
283+
datasourceId: this.id
284+
}],
285+
range: this.timeSrv.timeRange()
281286
}).then((regions) => { return this.mapToTextValue(regions, 'regions') })
282287
}
283288

284-
getAggregations () {
289+
getAggregations() {
285290
return this.q.when(aggregations)
286291
}
287292

288293
// retries all request to the backend grafana 10 times before failure
289-
doRequest (options) {
294+
doRequest(options) {
290295
let _this = this
291296
return retryOrThrow(() => {
292297
return _this.backendSrv.datasourceRequest({

0 commit comments

Comments
 (0)