Skip to content

Add cap billing walkthrough tutorial #4494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 17, 2020

Conversation

hujessica
Copy link
Contributor

@hujessica hujessica commented Aug 13, 2020

Description

Fixes #

Note: It's a good idea to open an issue first for discussion.

Checklist

@hujessica hujessica requested review from ace-n and a team as code owners August 13, 2020 19:03
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 13, 2020
Copy link

@ace-n ace-n left a comment

Choose a reason for hiding this comment

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

Some questions:
1a) Are we planning to implement this in other languages? If we're implementing it in both Node and Python, that implies (to me) that we should also support Java and Go.
1b) I'm not sure this sample is complex enough to justify implementing in four languages (unless someone other than my Serverless team is responsible for maintaining them). @grant WDYT? (@tod-hilton: is there customer feedback requesting this?)
2) Maybe this content would be better created as a codelab or Qwiklab than in GitHub, since that's typically where interactive walkthroughs/tutorials reside? (@tod-hilton thoughts?)

@@ -0,0 +1,154 @@
# Automating cost controls by capping billing
Copy link

Choose a reason for hiding this comment

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

Nit: can we name this file tutorial.md? (A one-word name is probably cleaner.)

Copy link

@HiltonTod HiltonTod Aug 14, 2020

Choose a reason for hiding this comment

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

Thanks for the questions, @ace-n.
1a) No, this will only be in Python.
1b) No, there aren't requests for multiple languages (at least now). If that changes when it goes public, we'll address it then.
2) I can see where that might seem reasonable, but we chose Neos and GitHub because @hujessica is interning with us this summer.

Regarding @grant's suggestion, I agree that it can live in a billing/ folder in this repo. We anticipate/hope to create more Neos-style tutorials in the future. And if we're using a billing/ folder, then I think the name should be something descriptive, like capbillingtutorial.md.

Copy link

Choose a reason for hiding this comment

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

Got it - thanks for the clarification!

A few further questions:

  1. I'm fine with longer names, but can we break them up a bit (e.g. hyphenate them)?
  2. Is this repo the best place to put Neos tutorials? (i.e. would it be better to create a separate GitHub repo dedicated to them, assuming they're supposed to live on a public GitHub a la our community tutorials site?)
  3. I like @grant's suggestion of using a billing folder. If we merge these samples into this repo, we should identify an owner and document that in the repo-root CODEOWNERS file.

(Note to self: if we move this to a separate folder, we'll have to do the same for Node.)

Copy link

@ace-n ace-n Aug 14, 2020

Choose a reason for hiding this comment

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

Also - N.B: the Node implementation is here.

(I presume the reason for not reusing that code is that external developers are more familiar with Python.)

@grant
Copy link
Contributor

grant commented Aug 13, 2020

Thanks for the PR @hujessica. Looks like a useful same for the Cloud Billing API.

Is there a GitHub issue for this sample? Or a Google Doc planning it?

I would recommend that this sample lives in a new billing/ folder for this repo. This sample shouldn't be in the functions/ folder.

@HiltonTod
Copy link

HiltonTod commented Aug 14, 2020

Is there a GitHub issue for this sample? Or a Google Doc planning it?

@grant - Jessica created a doc plan (go/pban-doc-plan) and tutorial draft (go/pban-tut-draft).

Copy link
Contributor

@grant grant left a comment

Choose a reason for hiding this comment

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

Thanks Tod! Personally excited to see this API sample.

Looking at the design doc, this looks like primary sample shows the Cloud Billing API. It uses Pub/Sub as the event channel and Functions Pub/Sub trigger (Could be Cloud Run, or a different Pub/Sub sink).

Let's move the code to a billing folder.

I'd imagine the code would be in a billing/tutorial/ folder.

  • billing/tutorial/README.md
  • billing/tutorial/main.py
  • walkthroughtutorial.md - put in README.md
    • The tutorial is short enough where we can put the instructions in the main README, which is the default markdown file for the folder (it renders nicely on GitHub).

Comment on lines 11 to 19
## Contributing

Contributions to this library are always welcome and highly encouraged.

See [CONTRIBUTING](CONTRIBUTING) for more information on how to get started.

## License

Apache 2.0 - See [LICENSE](LICENSE) for more information.
Copy link
Contributor

@grant grant Aug 14, 2020

Choose a reason for hiding this comment

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

We can leave this out.
We have common contributing and license files in this repo already.

@HiltonTod
Copy link

HiltonTod commented Aug 14, 2020

Thanks for the help and feedback, @ace-n and @grant!

To make sure I'm clear on your suggestions, here's what we should do:

  1. Move the existing file to billing/tutorial within this repo, python-doc-samples.
  2. I'm on the fence about creating a new repo for billing. I see the benefit organizationally, but since we're still not sure how much content would be there it might be overthinking it at this point. With that in mind, I lean towards going with # 1 for expediency.
  3. Yes, this is supposed to be publicly available.
  4. Instead of putting the tutorial into the default README.md, I think we should rename the existing file to cap-billing-walkthrough.md in the new directory and reference it in the README.md. This allows us extensibility for future tutorials (fingers crossed). That sound ok?
  5. The CODEOWNERS for the billing/ dir should include myself (@tod-hilton) and Nimish Chandiramani (@NimishC).

How's that all sound? Any other thoughts, @NimishC?

@grant
Copy link
Contributor

grant commented Aug 14, 2020

Those 5 things all sound good 👍

@NimishC
Copy link

NimishC commented Aug 14, 2020

All that sounds good to me too 👍

@ace-n
Copy link

ace-n commented Aug 14, 2020

LGTM to me too. 🙂

Thanks for putting this together @hujessica!

@HiltonTod
Copy link

Great, thanks all! @hujessica has made all of the changes and it's ready for review.

Copy link

@HiltonTod HiltonTod left a comment

Choose a reason for hiding this comment

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

LGTM

@hujessica
Copy link
Contributor Author

Thanks for all your help, @grant and @ace-n! :)

Copy link
Contributor

@grant grant left a comment

Choose a reason for hiding this comment

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

To be clear, this sample should live in a new folder, billing/:

https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/billing

@hujessica
Copy link
Contributor Author

@grant Got it! Created a new folder called billing, let me know how it looks now.

Copy link
Contributor

@grant grant left a comment

Choose a reason for hiding this comment

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

Folder structure looks good 👍 I didn't review the PR contents in detail.

This function will remove the billing account associated with the project if the cost amount is higher than the budget amount.
```sh
gcloud functions deploy ${FUNCTION_NAME} \
--runtime=python37 --source=./sample_code \
Copy link
Contributor

Choose a reason for hiding this comment

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

split up the flags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, just fixed that.

@HiltonTod
Copy link

HiltonTod commented Aug 14, 2020

Thanks, @grant and @ace-n!

@busunkim96 - I see this PR is assigned to you. Please take a look at your earliest convenience. Thanks!

Copy link
Contributor

@busunkim96 busunkim96 left a comment

Choose a reason for hiding this comment

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

Hiya!

(1) I don't see region tags in the file. Is this going to be used as snippets in cloud.google.com? Never mind. I didn't see the explanation above. :)
(2) Please add tests. You can reference the other directories for examples.

@@ -0,0 +1,5 @@
# These owners will be the default owners for everything in
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think GitHub will look at CODEOWNERS in other directories (see docs). Could you edit this file instead?

import base64
import json
import os
from googleapiclient import discovery
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the GAPIC libraries be used instead? https://github.com/googleapis/python-billing and https://github.com/googleapis/python-billingbudgets? (not sure which is applicable here).

Choose a reason for hiding this comment

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

I'm not familiar with the GAPIC libraries. What is the benefit or reason for using them versus the one currently being used?

Copy link

Choose a reason for hiding this comment

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

Among other things, they're generally cleaner/easier to use from a syntactical perspective.

Copy link
Contributor

Choose a reason for hiding this comment

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

This page explains the main differences. (GAPIC == Google Cloud Client Library)

<walkthrough-project-setup></walkthrough-project-setup>

```sh
export GCP_PROJECT={{project_id}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use GOOGLE_CLOUD_PROJECT - this is the env var that's used by the auth library https://googleapis.dev/python/google-auth/latest/reference/google.auth.environment_vars.html?highlight=google_cloud_project It's also automatically populated in our test setup.

@HiltonTod
Copy link

Thanks for the review, @busunkim96!

I'm not familiar with which tests we would use for this scenario. The previous tutorial our team implemented didn't have any tests associated with it: https://github.com/GoogleCloudPlatform/deploymentmanager-samples/pull/493/files. Can you direct us to specific examples we should implement, assuming we do need to before merging?

@busunkim96 busunkim96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 17, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 17, 2020
@busunkim96 busunkim96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 17, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 17, 2020
@HiltonTod
Copy link

@ace-n - I see that you enabled automerge, but the PR doesn't seem to have been merged yet. Can you help? Thanks!

~tod

@busunkim96 busunkim96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 17, 2020
@HiltonTod
Copy link

@busunkim96 - Thanks for looking at this this morning! Is there anything we need to do to help you and @ace-n merge this?

@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 17, 2020
@google-cla
Copy link

google-cla bot commented Aug 17, 2020

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Aug 17, 2020
@busunkim96 busunkim96 added cla: yes This human has signed the Contributor License Agreement. kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Aug 17, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 17, 2020
@busunkim96
Copy link
Contributor

@tod-hilton Nothing in particular! I'm just trying to get the branch up to date with master before merging. 😁

@googlebot Overriding CLA as the author was an intern with a valid CLA at the time this PR was created.

@google-cla
Copy link

google-cla bot commented Aug 17, 2020

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Aug 17, 2020

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Aug 17, 2020
@busunkim96 busunkim96 added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Aug 17, 2020
@google-cla
Copy link

google-cla bot commented Aug 17, 2020

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Aug 17, 2020
@busunkim96 busunkim96 added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Aug 17, 2020
@busunkim96 busunkim96 merged commit cd906e5 into GoogleCloudPlatform:master Aug 17, 2020
@HiltonTod
Copy link

@busunkim96, @ace-n, & @grant - Thanks for all of your help getting this merged!!! @NimishC and I will start on the remaining action items soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge the pull request once unit tests and other checks pass. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants