Skip to content
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

[Metricbeat] Add billing metricset into googlecloud module #20812

Merged
merged 18 commits into from
Sep 2, 2020
Merged

[Metricbeat] Add billing metricset into googlecloud module #20812

merged 18 commits into from
Sep 2, 2020

Conversation

kaiyan-sheng
Copy link
Contributor

@kaiyan-sheng kaiyan-sheng commented Aug 26, 2020

What does this PR do?

This PR is to add billing metricset into googlecloud module. For GCP, there is no direct billing API like AWS Cost Explorer to query for billing information. In order to get the billing date, users need to export billing reports into GCP BigQuery database and then this billing metricset can make some queries to get the actual billing data out.

Why is it important?

This will make GCP users' life a lot easier when tracking billing data 😄

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

It took me a while to get permissions for GCP billing account. Not sure how this will be tested in a short period of time. The config I used for billing metricset is:

- module: googlecloud
  metricsets:
    - billing
  project_id: "elastic-bi"
  credentials_file_path: "/Users/kaiyansheng/Desktop/elastic-bi-gcp.json"
  dataset_id: "master_gcp"
  table_pattern: "gcp_billing_export_v1"
  cost_type: "regular"
  period: 24h

Related issues

Screenshots

Screen Shot 2020-09-01 at 1 53 06 PM (2)

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Aug 26, 2020
@kaiyan-sheng kaiyan-sheng self-assigned this Aug 26, 2020
@kaiyan-sheng kaiyan-sheng added in progress Pull request is currently in progress. needs_backport PR is waiting to be backported to other branches. review Team:Platforms Label for the Integrations - Platforms team test-plan Add this PR to be manual test plan labels Aug 26, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations-platforms (Team:Platforms)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Aug 26, 2020
@elasticmachine
Copy link
Collaborator

elasticmachine commented Aug 26, 2020

💔 Tests Failed

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Pull request #20812 updated]

  • Start Time: 2020-09-02T04:29:37.249+0000

  • Duration: 123 min 2 sec

Test stats 🧪

Test Results
Failed 1
Passed 19132
Skipped 1814
Total 20947

Test errors

Expand to view the tests failures

  • Name: Build and Test / Filebeat oss / test_default_settings – filebeat.tests.system.test_autodiscover.TestAutodiscover

    • Age: 1
    • Duration: 90.003
    • Error Details: Failed: Timeout >90.0s

Steps errors

Expand to view the steps failures

  • Name: Mage build test

    • Description: mage build test

    • Duration: 27 min 36 sec

    • Start Time: 2020-09-02T04:54:11.160+0000

    • log

  • Name: Error signal

    • Description:

    • Duration: 0 min 0 sec

    • Start Time: 2020-09-02T06:32:36.745+0000

    • log

  • Name: Cleanup

    • Description: rm source.tgz

    • Duration: 0 min 0 sec

    • Start Time: 2020-09-02T06:32:36.793+0000

    • log

Log output

Expand to view the last 100 lines of log output

[2020-09-02T05:32:01.464Z] 		at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:80)
[2020-09-02T05:32:01.464Z] 		at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:67)
[2020-09-02T05:32:01.464Z] 		at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
[2020-09-02T05:32:01.464Z] 		at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[2020-09-02T05:32:01.464Z] 		at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2020-09-02T05:32:01.464Z] 		at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2020-09-02T05:32:01.464Z] 		at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2020-09-02T05:32:01.464Z] Caused: hudson.FilePath$TunneledInterruptedException
[2020-09-02T05:32:01.464Z] 	at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3114)
[2020-09-02T05:32:01.464Z] 	at hudson.remoting.UserRequest.perform(UserRequest.java:212)
[2020-09-02T05:32:01.464Z] 	at hudson.remoting.UserRequest.perform(UserRequest.java:54)
[2020-09-02T05:32:01.464Z] 	at hudson.remoting.Request$2.run(Request.java:369)
[2020-09-02T05:32:01.464Z] 	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
[2020-09-02T05:32:01.464Z] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2020-09-02T05:32:01.464Z] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2020-09-02T05:32:01.464Z] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2020-09-02T05:32:01.464Z] 	at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:93)
[2020-09-02T05:32:01.464Z] Caused: java.lang.InterruptedException: java.lang.InterruptedException: no matches found within 10000
[2020-09-02T05:32:01.464Z] 	at hudson.FilePath.act(FilePath.java:1072)
[2020-09-02T05:32:01.464Z] 	at hudson.FilePath.act(FilePath.java:1059)
[2020-09-02T05:32:01.464Z] 	at hudson.FilePath.validateAntFileMask(FilePath.java:2723)
[2020-09-02T05:32:01.464Z] 	at hudson.tasks.ArtifactArchiver.perform(ArtifactArchiver.java:270)
[2020-09-02T05:32:01.464Z] 	at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:91)
[2020-09-02T05:32:01.464Z] 	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:80)
[2020-09-02T05:32:01.465Z] 	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:67)
[2020-09-02T05:32:01.465Z] 	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
[2020-09-02T05:32:01.465Z] 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[2020-09-02T05:32:01.465Z] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2020-09-02T05:32:01.465Z] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2020-09-02T05:32:01.465Z] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2020-09-02T05:32:01.465Z] 	at java.lang.Thread.run(Thread.java:748)
[2020-09-02T05:32:01.465Z] No artifacts found that match the file pattern "**/build/TEST*.out". Configuration error?
[2020-09-02T05:32:01.820Z] + python .ci/scripts/search_system_tests.py
[2020-09-02T05:32:01.839Z] [INFO] system-tests='build/metricbeat/build/system-tests'. If no empty then let's create a tarball
[2020-09-02T05:32:02.180Z] + tar --version
[2020-09-02T05:32:02.506Z] + tar --exclude=metricbeat--system-tests-linux.tgz -czf metricbeat--system-tests-linux.tgz build/metricbeat/build/system-tests
[2020-09-02T05:32:09.125Z] Archiving artifacts
[2020-09-02T06:31:36.686Z] Cancelling nested steps due to timeout
[2020-09-02T06:31:36.757Z] Sending interrupt signal to process
[2020-09-02T06:31:37.119Z] Sending interrupt signal to process
[2020-09-02T06:31:44.689Z] failed to run compiled magefile: signal: terminated
[2020-09-02T06:31:44.689Z] go tool cover: signal: terminated
[2020-09-02T06:31:44.868Z] script returned exit code 255
[2020-09-02T06:31:46.011Z] Docker machine "default" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.
[2020-09-02T06:31:46.011Z] Docker machine "default" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.
[2020-09-02T06:31:46.181Z] Client: Docker Engine - Community
[2020-09-02T06:31:46.181Z]  Version:           19.03.1
[2020-09-02T06:31:46.181Z]  API version:       1.40
[2020-09-02T06:31:46.181Z]  Go version:        go1.12.5
[2020-09-02T06:31:46.181Z]  Git commit:        74b1e89
[2020-09-02T06:31:46.181Z]  Built:             Thu Jul 25 21:18:17 2019
[2020-09-02T06:31:46.181Z]  OS/Arch:           darwin/amd64
[2020-09-02T06:31:46.181Z]  Experimental:      false
[2020-09-02T06:31:46.181Z] Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[2020-09-02T06:31:46.181Z] It requires Docker daemon to be installed and running
[2020-09-02T06:31:46.976Z] + python .ci/scripts/pre_archive_test.py
[2020-09-02T06:31:47.456Z] Copy ./x-pack/elastic-agent/build into build/x-pack/elastic-agent/build
[2020-09-02T06:31:47.631Z] Running in /var/lib/jenkins/workspace/Beats_beats_PR-20812/src/github.com/elastic/beats/build
[2020-09-02T06:31:47.714Z] Recording test results
[2020-09-02T06:31:48.533Z] Stashed 1 file(s)
[2020-09-02T06:31:48.598Z] Archiving artifacts
[2020-09-02T06:31:49.569Z] + python .ci/scripts/search_system_tests.py
[2020-09-02T06:31:49.799Z] [INFO] system-tests=''. If no empty then let's create a tarball
[2020-09-02T06:31:51.865Z] Post stage
[2020-09-02T06:31:51.877Z] Running in /var/lib/jenkins/workspace/Beats_beats_PR-20812/src/github.com/elastic/beats
[2020-09-02T06:31:52.781Z] Starting "default"...
[2020-09-02T06:31:52.781Z] Machine "default" is already running.
[2020-09-02T06:31:54.364Z] Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.101:2376": dial tcp 192.168.99.101:2376: connect: connection refused
[2020-09-02T06:31:54.365Z] You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.
[2020-09-02T06:31:54.365Z] Be advised that this will trigger a Docker daemon restart which might stop running containers.
[2020-09-02T06:31:54.365Z] 
[2020-09-02T06:31:54.365Z] Client: Docker Engine - Community
[2020-09-02T06:31:54.365Z]  Version:           19.03.1
[2020-09-02T06:31:54.365Z]  API version:       1.40
[2020-09-02T06:31:54.365Z]  Go version:        go1.12.5
[2020-09-02T06:31:54.365Z]  Git commit:        74b1e89
[2020-09-02T06:31:54.365Z]  Built:             Thu Jul 25 21:18:17 2019
[2020-09-02T06:31:54.365Z]  OS/Arch:           darwin/amd64
[2020-09-02T06:31:54.365Z]  Experimental:      false
[2020-09-02T06:31:54.365Z] Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[2020-09-02T06:31:54.365Z] It requires Docker daemon to be installed and running
[2020-09-02T06:32:04.166Z] Failed in branch Elastic Agent Mac OS X
[2020-09-02T06:32:15.273Z] [INFO] unstashV2: JOB_GCS_BUCKET is set. bucket param got precedency instead.
[2020-09-02T06:32:15.297Z] [INFO] unstashV2: JOB_GCS_CREDENTIALS is set. credentialsId param got precedency instead.
[2020-09-02T06:32:15.467Z] [Google Cloud Storage Plugin] Found 1 files to download from pattern: gs://beats-ci-temp/Beats/beats/PR-20812-18/source/source.tgz
[2020-09-02T06:32:15.504Z] [Google Cloud Storage Plugin] Downloading: Beats/beats/PR-20812-18/source/source.tgz to local path: /var/lib/jenkins/workspace/Beats_beats_PR-20812/source.tgz
[2020-09-02T06:32:26.193Z] + tar --version
[2020-09-02T06:32:26.508Z] + tar -xpf source.tgz
[2020-09-02T06:32:36.687Z] Body did not finish within grace period; terminating with extreme prejudice
[2020-09-02T06:32:36.742Z] [INFO] source.tgz was not extracted : null
[2020-09-02T06:32:37.086Z] + rm source.tgz
[2020-09-02T06:32:37.097Z] ERROR: runbld post build action failed.
[2020-09-02T06:32:37.097Z] ERROR: untar: step failed with error null
[2020-09-02T06:32:37.942Z] Running on Jenkins in /var/lib/jenkins/workspace/Beats_beats_PR-20812
[2020-09-02T06:32:38.198Z] [INFO] getVaultSecret: Getting secrets
[2020-09-02T06:32:38.272Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2020-09-02T06:32:39.090Z] + chmod 755 generate-build-data.sh
[2020-09-02T06:32:39.090Z] + ./generate-build-data.sh https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-20812/ https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-20812/runs/18 FAILURE 7381575
[2020-09-02T06:32:39.090Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-20812/runs/18/steps/?limit=10000 -o steps-info.json
[2020-09-02T06:32:42.319Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-20812/runs/18/tests/?status=FAILED -o tests-errors.json

Copy link
Contributor

@exekias exekias left a comment

Choose a reason for hiding this comment

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

This will be a great addition! I left a few minor comments

"googlecloud": {
"billing": {
"cost_type": "regular",
"invoice_month": "202008",
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to convert this to a timestamp?

Copy link
Contributor Author

@kaiyan-sheng kaiyan-sheng Sep 1, 2020

Choose a reason for hiding this comment

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

Hmm I think we should keep it as a string/keyword to match invoice.month in billing table schema from BigQuery: https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables#data-schema

x-pack/metricbeat/module/googlecloud/billing/billing.go Outdated Show resolved Hide resolved
@kaiyan-sheng
Copy link
Contributor Author

CI failed with Build and Test / Filebeat oss / filebeat.tests.system.test_autodiscover.TestAutodiscover.test_default_settings, not related to this PR.

@kaiyan-sheng kaiyan-sheng merged commit ed6f101 into elastic:master Sep 2, 2020
@kaiyan-sheng kaiyan-sheng deleted the gcp_billing branch September 2, 2020 13:19
@kaiyan-sheng kaiyan-sheng added v7.10.0 and removed needs_backport PR is waiting to be backported to other branches. labels Sep 2, 2020
v1v added a commit to v1v/beats that referenced this pull request Sep 2, 2020
…ne-2.0

* upstream/master: (87 commits)
  [packaging] Normalise GCP bucket folder structure (elastic#20903)
  [Metricbeat] Add billing metricset into googlecloud module (elastic#20812)
  Include python docs in devguide index (elastic#20917)
  Avoid generating incomplete configurations in autodiscover (elastic#20898)
  Improve docs of leaderelection configuration (elastic#20601)
  Document how to set the ES host and Kibana URLs in Ingest Manager (elastic#20874)
  docs: Update beats for APM (elastic#20881)
  Adding cborbeat to community beats (elastic#20884)
  Bump kibana version to 7.9.0 in x-pack/metricbeat (elastic#20899)
  Kubernetes state_daemonset metricset for Metricbeat (elastic#20649)
  [Filebeat][zeek] Add new x509 fields to zeek (elastic#20867)
  [Filebeat][Gsuite] Add note about admin in gsuite docs (elastic#20855)
  Ensure kind cluster has RFC1123 compliant name (elastic#20627)
  Setup python paths in test runner configuration (elastic#20832)
  docs: Add  `processor.event` info to Logstash output (elastic#20721)
  docs: update cipher suites (elastic#20697)
  [ECS] Update ecs to 1.6.0 (elastic#20792)
  Fix path in hits docs (elastic#20447)
  Update filebeat azure module documentation (elastic#20815)
  Remove duplicate ListGroupsForUsers in aws/cloudtrail (elastic#20788)
  ...
kaiyan-sheng added a commit that referenced this pull request Sep 4, 2020
…20923)

* Add billing metricset to googlecloud module

(cherry picked from commit ed6f101)
@andresrc andresrc added the test-plan-added This PR has been added to the test plan label Oct 3, 2020
melchiormoulin pushed a commit to melchiormoulin/beats that referenced this pull request Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in progress Pull request is currently in progress. review Team:Platforms Label for the Integrations - Platforms team test-plan Add this PR to be manual test plan test-plan-added This PR has been added to the test plan v7.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GCP Billing Metricset
4 participants