22 * @fileoverview Main entrypoint to execute probes for different cloud APIs.
33 */
44
5- const firestore_grpc =
6- require ( '../google/firestore/v1beta1/firestore_grpc_pb.js' ) ;
5+ const firestore_grpc = require ( '../google/firestore/v1beta1/firestore_grpc_pb.js' ) ;
76const spanner_grpc = require ( '../google/spanner/v1/spanner_grpc_pb.js' ) ;
87const { GoogleAuth} = require ( 'google-auth-library' ) ;
98const grpc = require ( 'grpc' ) ;
@@ -16,16 +15,15 @@ const _OAUTH_SCOPE = 'https://www.googleapis.com/auth/cloud-platform';
1615const _FIRESTORE_TARGET = 'firestore.googleapis.com:443' ;
1716const _SPANNER_TARGET = 'spanner.googleapis.com:443' ;
1817
19-
2018/**
2119 * Retrieves arguments before executing probes.
2220 * @return {Object } An object containing all the args parsed in.
2321 */
2422function getArgs ( ) {
25- var parser = new argparse . ArgumentParser ( {
23+ const parser = new argparse . ArgumentParser ( {
2624 version : '0.0.1' ,
2725 addHelp : true ,
28- description : 'Argument parser for grpc gcp prober.'
26+ description : 'Argument parser for grpc gcp prober.' ,
2927 } ) ;
3028 parser . addArgument ( '--api' , { help : 'foo bar' } ) ;
3129 return parser . parseArgs ( ) ;
@@ -36,57 +34,63 @@ function getArgs() {
3634 * @param {string } api The name of the api provider, e.g. "spanner", "firestore".
3735 */
3836function executeProbes ( api ) {
39- var authFactory = new GoogleAuth ( ) ;
40- var util = new stackdriver_util . StackdriverUtil ( api ) ;
37+ const authFactory = new GoogleAuth ( ) ;
38+ const util = new stackdriver_util . StackdriverUtil ( api ) ;
4139
4240 authFactory . getApplicationDefault ( ( err , auth ) => {
4341 if ( err ) {
4442 console . log ( 'Authentication failed because of ' , err ) ;
4543 return ;
4644 }
4745 if ( auth . createScopedRequired && auth . createScopedRequired ( ) ) {
48- var scopes = [ _OAUTH_SCOPE ] ;
46+ const scopes = [ _OAUTH_SCOPE ] ;
4947 auth = auth . createScoped ( scopes ) ;
5048 }
51- var sslCreds = grpc . credentials . createSsl ( ) ;
52- var callCreds = grpc . credentials . createFromGoogleCredential ( auth ) ;
53- var channelCreds =
54- grpc . credentials . combineChannelCredentials ( sslCreds , callCreds ) ;
49+ const sslCreds = grpc . credentials . createSsl ( ) ;
50+ const callCreds = grpc . credentials . createFromGoogleCredential ( auth ) ;
51+ const channelCreds = grpc . credentials . combineChannelCredentials (
52+ sslCreds ,
53+ callCreds
54+ ) ;
5555 if ( api === 'firestore' ) {
56- var client =
57- new firestore_grpc . FirestoreClient ( _FIRESTORE_TARGET , channelCreds ) ;
56+ var client = new firestore_grpc . FirestoreClient (
57+ _FIRESTORE_TARGET ,
58+ channelCreds
59+ ) ;
5860 var probeFunctions = firestore_probes . probeFunctions ;
5961 } else if ( api === 'spanner' ) {
60- var client =
61- new spanner_grpc . SpannerClient ( _SPANNER_TARGET , channelCreds ) ;
62+ var client = new spanner_grpc . SpannerClient (
63+ _SPANNER_TARGET ,
64+ channelCreds
65+ ) ;
6266 var probeFunctions = spanner_probes . probeFunctions ;
6367 } else {
6468 throw new Error ( 'gRPC prober is not implemented for ' + api + ' !' ) ;
6569 }
6670
67- var metrics = { } ;
68- var probeNames = Object . keys ( probeFunctions ) ;
69- var promises = probeNames . map ( ( probeName ) => {
71+ const metrics = { } ;
72+ const probeNames = Object . keys ( probeFunctions ) ;
73+ const promises = probeNames . map ( probeName => {
7074 probe_function = probeFunctions [ probeName ] ;
7175 return probe_function ( client , metrics ) ;
7276 } ) ;
7377
7478 Promise . all ( promises )
75- . then ( ( ) => {
76- util . setSuccess ( true ) ;
77- } )
78- . catch ( ( err ) => {
79- util . setSuccess ( false ) ;
80- util . reportError ( err ) ;
81- } )
82- . then ( ( ) => {
83- util . addMetrics ( metrics ) ;
84- util . outputMetrics ( ) ;
85- } ) ;
79+ . then ( ( ) => {
80+ util . setSuccess ( true ) ;
81+ } )
82+ . catch ( err => {
83+ util . setSuccess ( false ) ;
84+ util . reportError ( err ) ;
85+ } )
86+ . then ( ( ) => {
87+ util . addMetrics ( metrics ) ;
88+ util . outputMetrics ( ) ;
89+ } ) ;
8690
8791 // TODO: if fail, exit probe.
8892 } ) ;
8993}
9094
91- var args = getArgs ( ) ;
95+ const args = getArgs ( ) ;
9296executeProbes ( args . api ) ;
0 commit comments