@@ -51,6 +51,7 @@ export default class OCIDatasource {
5151
5252 var targets = _ . map ( options . targets , target => {
5353 let region = target . region
54+ // check to see if we have tags (dimensions) in the query and turn those into a string for MQL
5455 let t = [ ]
5556 if ( target . hasOwnProperty ( 'tags' ) ) {
5657 for ( let i = 0 ; i < target . tags . length ; i ++ ) {
@@ -64,6 +65,7 @@ export default class OCIDatasource {
6465 if ( target . region === 'select region' ) {
6566 region = this . defaultRegion
6667 }
68+ // If there's nothing there return a blank string otherwise return the dimensions encapsuled by these {}
6769 let dimension = ( t . length === 0 ) ? '' : `{${ t } }`
6870
6971 return {
@@ -78,6 +80,7 @@ export default class OCIDatasource {
7880 hide : target . hide ,
7981 type : target . type || 'timeserie' ,
8082 datasourceId : this . id ,
83+ // pass the MQL string we built here
8184 query : `${ this . templateSrv . replace ( target . metric , options . scopedVars || { } ) } [${ target . window } ]${ dimension } .${ target . aggregation } `
8285 }
8386 } )
@@ -107,15 +110,16 @@ export default class OCIDatasource {
107110 } )
108111 }
109112
113+ // helps match the regex's from creating template variables in grafana
110114 templateMeticSearch ( varString ) {
111115 let compartmentQuery = varString . match ( / ^ c o m p a r t m e n t s \( \) / )
112116 if ( compartmentQuery ) {
113- return this . getCompartments ( )
117+ return this . getCompartments ( ) . catch ( err => { throw new Error ( 'Unable to make request ' + err ) } )
114118 }
115119
116120 let regionQuery = varString . match ( / ^ r e g i o n s \( \) / )
117121 if ( regionQuery ) {
118- return this . getRegions ( )
122+ return this . getRegions ( ) . catch ( err => { throw new Error ( 'Unable to make request ' + err ) } )
119123 }
120124
121125 let metricQuery = varString . match ( / m e t r i c s \( ( \$ ? \w + ) ( , \s * \$ \w + ) * \) / )
@@ -124,7 +128,7 @@ export default class OCIDatasource {
124128 namespace : this . templateSrv . replace ( metricQuery [ 1 ] ) ,
125129 compartment : this . templateSrv . replace ( metricQuery [ 2 ] ) . replace ( ',' , '' ) . trim ( )
126130 }
127- return this . metricFindQuery ( target )
131+ return this . metricFindQuery ( target ) . catch ( err => { throw new Error ( 'Unable to make request ' + err ) } )
128132 }
129133
130134 let namespaceQuery = varString . match ( / n a m e s p a c e s \( \) / )
@@ -137,6 +141,10 @@ export default class OCIDatasource {
137141 throw new Error ( 'Unable to parse templating string' )
138142 }
139143
144+ // this function does 2 things - its the entrypoint for finding the metrics from the query editor
145+ // and is the entrypoint for templating according to grafana -- since this wasn't docuemnted
146+ // in grafana I was lead to believe that it did the former
147+ // TODO: break the metric finding for the query editor out into a different function
140148 metricFindQuery ( target ) {
141149 if ( typeof ( target ) === 'string' ) {
142150 return this . templateMeticSearch ( target )
@@ -273,6 +281,7 @@ export default class OCIDatasource {
273281 return this . q . when ( aggregations )
274282 }
275283
284+ // retries all request to the backend grafana 10 times before failure
276285 doRequest ( options ) {
277286 let _this = this
278287 return retryOrThrow ( ( ) => {
0 commit comments