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] GCP cloudsql metadata #33066

Merged
merged 13 commits into from
Nov 15, 2022
Merged

Conversation

gpop63
Copy link
Contributor

@gpop63 gpop63 commented Sep 13, 2022

What does this PR do?

While working on the GCP CloudSQL integration elastic/integrations#4126 I discovered that there is no way to know which database type (PostgreSQL, MySQL or SQLServer) generated an event.

Adds cloudsql metadata.

An event would look like this with the added cloudsql labels.

 "gcp": {
    "labels": {
      "resource": {
        "region": "us-central",
        "database_id": "elastic-observability:postgres"
      },
      "cloudsql": {
        "version": "14",
        "name": "postgres"
      },
      "metrics": {
        "state": "SUSPENDED"
      }
    },
    "metrics": {
      "database": {
        "instance_state": {
          "value": false
        }
      }
    }
  },

@kaiyan-sheng suggested adding the cloudsql metadata under gcp not under labels but the stackdriver metadata only allows access to ECS and Labels.

Why is it important?

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.

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Sep 13, 2022
@mergify mergify bot assigned gpop63 Sep 13, 2022
@mergify
Copy link
Contributor

mergify bot commented Sep 13, 2022

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @gpop63? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

@gpop63 gpop63 added the Team:Cloud-Monitoring Label for the Cloud Monitoring team label Sep 13, 2022
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Sep 13, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Sep 13, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-11-15T16:45:41.478+0000

  • Duration: 54 min 41 sec

Test stats 🧪

Test Results
Failed 0
Passed 1392
Skipped 87
Total 1479

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@gpop63 gpop63 marked this pull request as ready for review September 13, 2022 14:37
@gpop63 gpop63 requested a review from a team as a code owner September 13, 2022 14:37
@endorama
Copy link
Member

@tommyers-elastic May you have a look at this comment:

@kaiyan-sheng suggested adding the cloudsql metadata under gcp not under labels but the stackdriver metadata only allows access to ECS and Labels.

and provide your opinion here? We can either try to fix this here, leave it like this for consistency or try to refactor (we would need an exploration phase to understand how this would play out)

@kaiyan-sheng
Copy link
Contributor

Sorry I missed the comment here. I'm fine with leaving the fields under labels for consistency. I mentioned gcp because that's what the metadata are stored for AWS as an example, not a suggestion. But I'd rather have the consistency and no breaking change here.

@endorama
Copy link
Member

@gpop63 I was reviewing this contribution, there is only one thing that we need to double check: this code uses the same caching logic as instance metadata. We discovered a bug in the caching logic there, and we decided to remove the cache as it wasn't been used properly.

Can you please remove the caching logic from this module? It will be reintroduced if the need arise in future updates.

@gpop63
Copy link
Contributor Author

gpop63 commented Nov 15, 2022

I have a question regarding cloud.id and cloud.name fields. CloudSQL seems to not have unique ints as instance ids, the id of an instance is a concatenation of the project name and the instance name {project}:{instance_name}. Is this ok?

"cloud": {
  "instance": {
    "id": "elastic-observability:postgres",
    "name": "postgres"
  },

@endorama
Copy link
Member

@gpop63 If that is the GCP provided ID I would move forward with it. We need to make sure the mapping in the data stream is correct though, or there could be errors during ingestion.

Copy link
Member

@endorama endorama left a comment

Choose a reason for hiding this comment

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

Adding a small comment to clarify the role of instances.

Copy link
Contributor

@kaiyan-sheng kaiyan-sheng left a comment

Choose a reason for hiding this comment

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

looks good to me, could you add a changelog entry please? Thank you!

// cloudsqlMetadata is an object to store data in between the extraction and the writing in the destination (to uncouple
// reading and writing in the same method)
type cloudsqlMetadata struct {
// projectID string
Copy link
Contributor

Choose a reason for hiding this comment

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

should we remove the projectID, machineType and ts here?

@kaiyan-sheng
Copy link
Contributor

I have a question regarding cloud.id and cloud.name fields. CloudSQL seems to not have unique ints as instance ids, the id of an instance is a concatenation of the project name and the instance name {project}:{instance_name}. Is this ok?

"cloud": {
  "instance": {
    "id": "elastic-observability:postgres",
    "name": "postgres"
  },

Actually looking at this comment, I don't think we should use cloud.instance.id and cloud.instance.name for these fields. In ECS, cloud.instance.id is defined as Instance ID of the host machine.. I would probably just use gcp.cloudsql.id and gcp.cloudsqp.name instead here.

@gpop63 gpop63 merged commit 60f9721 into elastic:main Nov 15, 2022
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
* add cloudsql metadata

* add cloudsql metadata tests

* add cloudsql service constant

* add license headers

* mage update

* fix golangci-lint

* remove cache

* add instance name field

* add instances comment

* add import aliases

* add changelog entry

* remove cloud instance and unused metadata fields

Co-authored-by: kaiyan-sheng <kaiyan.sheng@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Cloud-Monitoring Label for the Cloud Monitoring team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants