damccorm commented on code in PR #23158:
URL: https://github.com/apache/beam/pull/23158#discussion_r971248793


##########
.github/gh-actions-self-hosted-runners/helper-functions/cloud-functions/generateToken/index.js:
##########
@@ -0,0 +1,77 @@
+//  Licensed to the Apache Software Foundation (ASF) under one
+//  or more contributor license agreements.  See the NOTICE file
+//  distributed with this work for additional information
+//  regarding copyright ownership.  The ASF licenses this file
+//  to you under the Apache License, Version 2.0 (the
+//  "License"); you may not use this file except in compliance
+//  with the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing,
+//  software distributed under the License is distributed on an
+//  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//  KIND, either express or implied.  See the License for the
+//  specific language governing permissions and limitations
+//  under the License.
+
+//This function provides registration tokens for windows and linux self-hosted
+//runners, a service account with the appropriated permissions should be used 
to
+// invoke the Cloud Function.
+
+import functions from '@google-cloud/functions-framework';
+import { Octokit } from "octokit";
+import { createAppAuth } from "@octokit/auth-app";
+
+const 
REQUIRED_ENV_VARS=["APP_ID","PEM_KEY","CLIENT_ID","CLIENT_SECRET","APP_INSTALLATION_ID","ORG"]
+
+

Review Comment:
   ```suggestion
   const 
REQUIRED_ENV_VARS=["APP_ID","PEM_KEY","CLIENT_ID","CLIENT_SECRET","APP_INSTALLATION_ID","ORG"]
   
   ```
   
   Nit: remove extra space here and elsewhere



##########
.github/gh-actions-self-hosted-runners/helper-functions/cloud-functions/monitorRunnersStatus/index.js:
##########
@@ -0,0 +1,98 @@
+//  Licensed to the Apache Software Foundation (ASF) under one
+//  or more contributor license agreements.  See the NOTICE file
+//  distributed with this work for additional information
+//  regarding copyright ownership.  The ASF licenses this file
+//  to you under the Apache License, Version 2.0 (the
+//  "License"); you may not use this file except in compliance
+//  with the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing,
+//  software distributed under the License is distributed on an
+//  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//  KIND, either express or implied.  See the License for the
+//  specific language governing permissions and limitations
+//  under the License.
+
+//This function will return the number of online and offline runners for
+// each OS (Windows, linux), an additional Github actions workflow will run
+// to request this Cloud Function and send alerts based on the status.
+
+import functions from '@google-cloud/functions-framework';
+import { Octokit } from "octokit";
+import { createAppAuth } from "@octokit/auth-app";
+
+
+const 
REQUIRED_ENV_VARS=["APP_ID","PEM_KEY","CLIENT_ID","CLIENT_SECRET","APP_INSTALLATION_ID","ORG"]
+
+
+function validateEnvSet(envVars) {
+    envVars.forEach(envVar => {
+        if (!process.env[envVar]) {
+            throw new Error(`${envVar} environment variable not set.`)
+        }
+    });
+}
+
+async function monitorRunnerStatus() {
+    try {
+        //Set your GH App values as environment variables
+        let authOptions = {
+            appId: process.env.APP_ID,
+            privateKey: process.env.PEM_KEY,
+            clientId: process.env.CLIENT_ID,
+            clientSecret: process.env.CLIENT_SECRET,
+            installationId: process.env.APP_INSTALLATION_ID
+        }
+        const octokit = new Octokit({
+            authStrategy: createAppAuth,
+            auth: authOptions
+        });
+        let pageCounter=1
+        let runners=[]
+        let pageRunners=[]
+        do{
+            pageRunners= await octokit.request(`GET 
/orgs/${process.env.ORG}/actions/runners`, {
+                org: process.env.ORG,
+                per_page: 50,
+                page:pageCounter
+            });
+            runners=runners.concat(pageRunners.data.runners)
+            pageCounter++
+        } while(pageRunners.data.runners.length!=0)
+        

Review Comment:
   ```suggestion
           const runners = await octokit.paginate("GET 
/orgs/${process.env.ORG}/actions/runners", {
               org: process.env.ORG,
           }) 
   ```
   
   Could we simplify this with octokit's built in pagination?



##########
.github/gh-actions-self-hosted-runners/helper-functions/cloud-functions/generateToken/index.js:
##########
@@ -0,0 +1,77 @@
+//  Licensed to the Apache Software Foundation (ASF) under one
+//  or more contributor license agreements.  See the NOTICE file
+//  distributed with this work for additional information
+//  regarding copyright ownership.  The ASF licenses this file
+//  to you under the Apache License, Version 2.0 (the
+//  "License"); you may not use this file except in compliance
+//  with the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing,
+//  software distributed under the License is distributed on an
+//  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//  KIND, either express or implied.  See the License for the
+//  specific language governing permissions and limitations
+//  under the License.
+
+//This function provides registration tokens for windows and linux self-hosted
+//runners, a service account with the appropriated permissions should be used 
to
+// invoke the Cloud Function.
+
+import functions from '@google-cloud/functions-framework';
+import { Octokit } from "octokit";
+import { createAppAuth } from "@octokit/auth-app";
+
+const 
REQUIRED_ENV_VARS=["APP_ID","PEM_KEY","CLIENT_ID","CLIENT_SECRET","APP_INSTALLATION_ID","ORG"]

Review Comment:
   This is the same env set across files, right? Could we refactor it to a 
constant that we can just import?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to