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

aws_cloudwatch_log_group key column is not globally unique #1975

Closed
bryanburke opened this issue Nov 17, 2023 · 2 comments · Fixed by #1976
Closed

aws_cloudwatch_log_group key column is not globally unique #1975

bryanburke opened this issue Nov 17, 2023 · 2 comments · Fixed by #1976
Assignees
Labels
bug Something isn't working

Comments

@bryanburke
Copy link

bryanburke commented Nov 17, 2023

Describe the bug

The key column for the aws_cloudwatch_log_group table is name: https://github.com/turbot/steampipe-plugin-aws/blob/v0.123.0/aws/table_aws_cloudwatch_log_group.go#L23

However, Amazon CloudWatch Logs log group names are only unique within a specific AWS account and region. Thus, queries that filter on exact log group name fail when the same log group name exists in multiple account-region pairs.

I believe the solution is to make the globally unique resource ARN the key column for the table.

Other CloudWatch Logs resource tables may be affected as well, though I have not tested them. For example: https://github.com/turbot/steampipe-plugin-aws/blob/v0.123.0/aws/table_aws_cloudwatch_log_stream.go#L29

Steampipe version (steampipe -v)

v0.21.0

Plugin version (steampipe plugin list)

v0.123.0

To reproduce

  1. Create a CloudWatch Logs log group named "steampipe-test" in us-east-1.

  2. Create another log group named "steampipe-test" in us-east-2 in the same AWS account.

  3. Query log groups across both regions with a filter on that exact name:

    steampipe query  "SELECT account_id, region, name FROM aws_cloudwatch_log_group WHERE name = 'steampipe-test' ORDER BY account_id ASC, region ASC;"
  4. Observe the following error: Error: get call returned 2 results - the key column is not globally unique (SQLSTATE HV000)

Expected behavior

The query above no longer results in an error.

Additional context

Until this issue is fixed, using LIKE instead of exact equality seems to be a workaround:

steampipe query  "SELECT account_id, region, name FROM aws_cloudwatch_log_group WHERE name LIKE 'steampipe-test' ORDER BY account_id ASC, region ASC;"

However, in terms of execution plan, I imagine LIKE is less efficient than exact string matching.

Thanks for all your hard work making and supporting this wonderful tool!

@bryanburke bryanburke added the bug Something isn't working label Nov 17, 2023
@ParthaI
Copy link
Contributor

ParthaI commented Nov 17, 2023

@bryanburke, I'm sorry to hear that you're experiencing issues.

  • Upon initial inspection, it appears that our plugin code uses the DescribeLogGroups API to filter results by name.

  • The name value provided in the query parameter serves as the input for the DescribeLogGroups API, with the value being passed as [LogGroupNamePrefix](https://github.com/turbot/steampipe-plugin-aws/blob/main/aws/table_aws_cloudwatch_log_group.go#L193).

  • Since AWS CloudWatch Log Groups are regional resources, the API is designed to be called once for each region configured in the aws.spc file.

  • We have configured this API call in the GetConfig section of this table.

  • From a Steampipe design perspective, the GetConfig function should ideally return a single row and not more than one, which is causing the issue.

We will take a look at the issue.

Thanks!

Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the stale No recent activity has been detected on this issue/PR and it will be closed label Jan 16, 2024
@ParthaI ParthaI removed the stale No recent activity has been detected on this issue/PR and it will be closed label Jan 17, 2024
bigdatasourav pushed a commit that referenced this issue Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants