Skip to content

Conversation

@DiegoManzanarezx
Copy link

@DiegoManzanarezx DiegoManzanarezx commented Jul 19, 2022

The purpose of this draft PR is to add a Github actions workflow that will be executed every time there is a push to this repository or when manually triggering it through Github UI.
The workflow will run a Javascript Google Cloud Client library file that will create and send a task to a Google Cloud Tasks Queue and will then forward it to a Google Cloud Workflow that will execute the test runner.

This draft PR consists on adding 3 new files:

  1. A Github actions yaml file to install all the dependencies needed to successfully run a Javascript file that implements Google Cloud Tasks Queue Client library.
  2. A Javascript file that create and send a task to a Queue, using Google Cloud Tasks Queue Client library.
  3. A package.json file that stores all the dependencies needed for the JS file.

*To verify the reliability of the workflow we have first built and tested a fully functional prototype that works as expected.

Considerations:
a) In order to execute the workflow we need credentials and other information (i.e. the name of our project in Google Cloud Platform) that we will provide, but must remain confidential, therefore, those should be stored as Github Actions secrets and are the following:
GOOGLE_APPLICATION_CREDENTIALS -> This is a JSON file that will authenticate our GCP account at every execution.
LOCATION -> Location where the Queue is running.
PROJECT_ID -> The name of the GCP project where the Queue is stored.
QUEUE_ID -> The name of the Queue where the task will be sent.
SERVICE_ACCOUNT_ROLE -> The GCP account that contains the permissions and roles to manage the Queue.
WORKFLOW_URL -> The endpoint to which the Queue will send an http request to forward the task to a GCP Workflow.

b) The purpose of triggering manually the workflow is to run personalized tests, so 3 inputs will we requested:
- Commit hash. (required)
- Classes to test. (optional)
- Pull request number. (optional)
*If the optional fields are left empty, all tests will be executed on that specific commit.
We will comment a link to the tests results on this pull request.

c) Since we are still working on the test runner this draft PR is intended just for code reviews purposes. We plan on landing the PR once the project is on a working state, probably about four weeks time.

Copy link
Contributor

@chriswr95 chriswr95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a detailed description to the PR. What is this code? What purpose does it serve? How did we test it? We also want to communicate that we're raising the PR now so we can code review it, but don't plan on landing the PR until later in the project. Until then, we're hoping it can hang out as a draft. Probably about four weeks time.

description: 'Classes to test'
required: false
PULL_REQUEST_NUMBER_INPUT:
description: 'Pull request number'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you the usage of each of these parameters to the description? for example if this is specified, we will comment a link to the tests results on this pull request.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it to the description.

#Actions secrets (keys)
PROJECT_ID: ${{ secrets.PROJECT_ID }}
QUEUE_ID: ${{ secrets.QUEUE_ID }}
LOCATION: ${{ secrets.LOCATION }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this?

QUEUE_ID: ${{ secrets.QUEUE_ID }}
LOCATION: ${{ secrets.LOCATION }}
WORKFLOW_URL: ${{ secrets.WORKFLOW_URL }}
SERVICE_ACCOUNT_EMAIL: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already updated the description of the draft PR to explain why we need each of those variables.

- run: npm i yenv
- run: npm i uuid

- id: 'auth'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very cool

const serviceAccountEmail = parsedDocument.SERVICE_ACCOUNT_EMAIL;

// Construct payload
const payloadStructure = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please format this like

const payloadStructure =  {
  val1: var1,
  val2: var2,
  ...
};

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

console.log(`Created task ${name}`);
console.log(`Your job id is: ${jobId}`);
}
createHttpTaskWithToken(); No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's chat in person about refactoring this script just a bit, overall it looks pretty good.

with:
node-version: '14'
- run: npm install
- run: npm i yenv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you add yenv to your package.json, can you skip this extra step, as it will be installed during npm install?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I added it to the package.json instead.

package.json Outdated
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.0.0",
"uuid": "^8.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is uuid only a dev dependency? I think it should be a regular dependency. Similarly, do you need mocha and chai? I we don't have any tests for this code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have already updated this file. We don't need mocha an chai.

Copy link
Member

@andimarek andimarek Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really comfortable with having this in the root folder. Can we move this file into the .github/workflow directory?
The reason is security and maintenance: this is not s JS project and we don't depend on JS libraries for the actual lib we publish. This should be clearly only used for the github workflow

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that Andi! I moved it into workflows folder.

@@ -0,0 +1,63 @@
const {CloudTasksClient} = require('@google-cloud/tasks');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably shouldn't live at the root level, maybe instead at .github/workflow-scripts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I added it inside .github/workflow

const yenv = require('yenv')
const { v4: uuidv4 } = require('uuid');
const fs = require('fs')
const os = require('os');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used anywhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I have already fixed it in the new commit.

const yenv = require('yenv')
const { v4: uuidv4 } = require('uuid');

const parsedDocument = yenv('.github/workflows/gql-perf-arch-github_workflow.yml')
Copy link

@adarsh-jaiswal adarsh-jaiswal Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use process.env.COMMIT_HASH and likewise for all other env variables? we might not need yenv dependency.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you were right. The change is done.

Copy link
Contributor

@chriswr95 chriswr95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks much tighter.

NIT: For your PR description, you are now a little bit too verbose. Aim for clear and succinct language. You should spend 20 minutes writing the description so that a reviewer can read it in one minute. Using Markdown also helps to structure longer messages. No need to change anything, just leaving this for the future :)

Approved pending a final nit comment.

}

async function createHttpTaskWithToken() {
const payloadStructure = constructPayload();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can wrap lines 58 - 61 into yet another helper function createRequest() which returns the request.

description: 'Pull request number'
required: false
env:
#Actions secrets (keys)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this comment.

package.json Outdated
"dependencies": {
"@google-cloud/tasks": "^3.0.0",
"body-parser": "^1.18.3",
"express": "^4.16.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need express here? I don't think we are running any server, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, we don't need express. Already removed it.

package.json Outdated
"name": "appengine-cloudtasks",
"description": "Google App Engine Cloud Tasks example.",
"license": "Apache-2.0",
"author": "Google Inc.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right. We could just remove author, license, descp etc as we don;t plan to publish this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I removed those fields.

@andimarek andimarek merged commit 74189e0 into graphql-java:master Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants