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

Add condition and processors settings to SQL Input #6358

Merged
merged 2 commits into from
Sep 20, 2023

Conversation

BenB196
Copy link
Contributor

@BenB196 BenB196 commented May 29, 2023

Enhancement

What does this PR do?

This PR adds two (2) new field settings to the SQL Input integration.

  1. Adds the ability to set condition.
    • The ability to set this value allows for having multiple SQL Input integrations in the same Agent policy while only having them run on specific hosts. (Most likely to be used with the host metadata; ex; host.name or host.platform.
  2. Adds the ability to set processors.
    • The ability to set processors to manipulate collected data before sending to Elasticsearch.

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.

Author's Checklist

  • I added both condition and processors as "advanced" fields.
Before Upgrade
inputs:
  - id: sql/metrics-sql-12f9198a-ae28-48f4-aae6-63b23781e064
    name: sql-1
    revision: 1
    type: sql/metrics
    use_output: default
    meta:
      package:
        name: sql
        version: 0.1.0
    data_stream:
      namespace: default
    package_policy_id: 12f9198a-ae28-48f4-aae6-63b23781e064
    streams:
      - id: sql/metrics-sql.sql-12f9198a-ae28-48f4-aae6-63b23781e064
        data_stream:
          dataset: test
        metricsets:
          - query
        hosts:
          - 'root:test@tcp(127.0.0.1:3306)/'
        driver: mysql
        sql_queries:
          - query: SHOW GLOBAL STATUS LIKE 'Innodb_system%'
            response_format: variables
        raw_data.enabled: true
        period: 10s
After Upgrade (with Settings)
inputs:
  - id: sql/metrics-sql-12f9198a-ae28-48f4-aae6-63b23781e064
    name: sql-1
    revision: 3
    type: sql/metrics
    use_output: default
    meta:
      package:
        name: sql
        version: 0.2.0
    data_stream:
      namespace: default
    package_policy_id: 12f9198a-ae28-48f4-aae6-63b23781e064
    streams:
      - id: sql/metrics-sql.sql-12f9198a-ae28-48f4-aae6-63b23781e064
        data_stream:
          dataset: test
        condition: '${host.name} == "mydb-server"'
        period: 10s
        raw_data.enabled: true
        driver: mysql
        sql_queries:
          - response_format: variables
            query: SHOW GLOBAL STATUS LIKE 'Innodb_system%'
        hosts:
          - 'root:test@tcp(127.0.0.1:3306)/'
        metricsets:
          - query
        processors:
          - drop_fields:
              fields:
                - agent

How to test this PR locally

  1. Install current integration version
  2. Upgrade integration to this PR
  3. Add/Remove condition values.

Related issues

  • N/A

Screenshots

  • New fields from Kibana UI
    image

@BenB196 BenB196 requested a review from a team as a code owner May 29, 2023 18:42
@BenB196 BenB196 changed the title Add condition and processors settings to sql input Add condition and processors settings to SQL Input May 29, 2023
@elasticmachine
Copy link

elasticmachine commented May 29, 2023

💚 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: 2023-09-05T21:40:32.221+0000

  • Duration: 17 min 47 sec

Test stats 🧪

Test Results
Failed 0
Passed 4
Skipped 0
Total 4

🤖 GitHub comments

Expand to view the GitHub comments

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

  • /test : Re-trigger the build.

@botelastic
Copy link

botelastic bot commented Jun 29, 2023

Hi! We just realized that we haven't looked into this PR in a while. We're sorry! We're labeling this issue as Stale to make it hit our filters and make sure we get back to it as soon as possible. In the meantime, it'd be extremely helpful if you could take a look at it as well and confirm its relevance. A simple comment with a nice emoji will be enough :+1. Thank you for your contribution!

@botelastic botelastic bot added the Stalled label Jun 29, 2023
@ishleenk17 ishleenk17 added Team:Service-Integrations Label for the Service Integrations team and removed Stalled labels Jun 29, 2023
@lalit-satapathy
Copy link
Collaborator

@ishleenk17, Can you check this PR in sql input?

@BenB196
Copy link
Contributor Author

BenB196 commented Aug 13, 2023

FYI, this PR was a bit out of date, I've rebased and fixed the merge conflicts

@aliabbas-elastic
Copy link
Contributor

/test

@ishleenk17
Copy link
Contributor

@BenB196 : Could you please elaborate on the need for conditions?
If you add multiple SQL Input Integrations, they will be corresponding to their own data streams. How would conditions help here?

@BenB196
Copy link
Contributor Author

BenB196 commented Aug 14, 2023

Hi @ishleenk17 regarding the need for condition, suppose I have 2 SQL databases I want to query on 2 different servers, but they differ in some way that makes them require their own unique definition of the sql_input. Without the condition field, I need to create 2 entire Elastic Agent policies, just to support these 2 databases. However, with the condition field, I can use something like ${host.name} == 'db1' on one of the integration definitions and ${host.name} == 'db2' on the other integration definition and keep them in the same Elastic Agent policy.

@ishleenk17
Copy link
Contributor

@BenB196 : This is a SQL Input Integration, where the user can enter the dataset names as input as seen in below screenshot:
Screenshot 2023-08-14 at 4 18 05 PM

In this case, 2 SQL Input Integrations will point to 2 different hosts (databases) and due to 2 different datasets, the data will be mapped to the index created by a specific dataset (hence distinguishing between db1 and db2).

For generic integrations (I see you have raised this for IIS etc), the conditions would make sense as dataset names are not taken as input from user. They are fixed.

@BenB196
Copy link
Contributor Author

BenB196 commented Aug 14, 2023

Hi @ishleenk17 I think there might be some confusion here, the issue this PR tries to solve isn't related to the dataset value. It is more related to being able to use different hosts (username, password, url)/drivers/queries across multiple integration definitions within the same Elastic Agent policy, but the integration definitions are scoped to specific conditions, so that specific integration definitions only run on specific hosts/circumstances.

@devamanv devamanv added the enhancement New feature or request label Aug 29, 2023
Copy link
Contributor

@ishleenk17 ishleenk17 left a comment

Choose a reason for hiding this comment

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

Please take care of updating the processor link as mentioned in the comment.
Rest looks good!

packages/sql_input/manifest.yml Outdated Show resolved Hide resolved
@BenB196
Copy link
Contributor Author

BenB196 commented Sep 15, 2023

Hi @ishleenk17, wanted to check to see if there was anything else blocking the PR?

@ishleenk17 ishleenk17 merged commit 80579aa into elastic:main Sep 20, 2023
3 checks passed
@ishleenk17
Copy link
Contributor

Hi @ishleenk17, wanted to check to see if there was anything else blocking the PR?

Thanks for the contribution. The PR is merged now.

@elasticmachine
Copy link

Package sql - 0.4.0 containing this change is available at https://epr.elastic.co/search?package=sql

@BenB196 BenB196 deleted the add-sql-condition branch November 29, 2023 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Team:Service-Integrations Label for the Service Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants