Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

RetentionInDays not set when describing a cloudwatch log group via the LogGroupNamePrefix #608

Closed
sean-kuendig-copebit opened this issue Apr 18, 2023 · 5 comments
Assignees
Labels
bug Something isn't working cloudwatchlogs service-api This issue pertains to the AWS API

Comments

@sean-kuendig-copebit
Copy link

Describe the bug

The CloudWatchLogs client provides two options for retrieving a log group by its name: LogGroupNamePattern and LogGroupNamePrefix. When using the LogGroupNamePrefix parameter, the RetentionInDays field of the log group is set. However, if you use the LogGroupNamePattern parameter instead, the RetentionInDays field is not set.

Expected Behavior

The field RetentionInDays should be consistently set, regardless if the log group is being described by its name with the parameter LogGroupNamePattern or LogGroupNamePrefix.

Current Behavior

Only the log group that is described via LogGroupNamePrefix has the RetentionInDays set. If the log group is described by using LogGroupNamePattern the RetentionInDays is nil.

The output below happens when the code in the reproduction steps is run:

Prefix Group:
bslbgm
30
Pattern Group:
bslbgm
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x131adde]

Reproduction Steps

package main

import (
	"context"
	"fmt"
	"strings"
	"time"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
	"github.com/gruntwork-io/terratest/modules/random"
)

func main() {
	ctx := context.Background()
	cfg, _ := config.LoadDefaultConfig(ctx)
	cloudwatchlogsClient := cloudwatchlogs.NewFromConfig(cfg)

	logGroupNameSpace := strings.ToLower(random.UniqueId())

	// A new log group needs to be created so that the lambda is triggered
	cloudwatchlogsClient.CreateLogGroup(ctx, &cloudwatchlogs.CreateLogGroupInput{
		LogGroupName: &logGroupNameSpace,
	})

	time.Sleep(time.Second * time.Duration(10))

	cloudwatchlogsClient.PutRetentionPolicy(ctx, &cloudwatchlogs.PutRetentionPolicyInput{
		LogGroupName:    &logGroupNameSpace,
		RetentionInDays: aws.Int32(30),
	})

	time.Sleep(time.Second * time.Duration(10))

	prefix_output, _ := cloudwatchlogsClient.DescribeLogGroups(ctx, &cloudwatchlogs.DescribeLogGroupsInput{
		LogGroupNamePrefix: &logGroupNameSpace,
	})

	pattern_output, _ := cloudwatchlogsClient.DescribeLogGroups(ctx, &cloudwatchlogs.DescribeLogGroupsInput{
		LogGroupNamePattern: &logGroupNameSpace,
	})

	fmt.Println("Prefix Group:")
	for _, prefix_group := range prefix_output.LogGroups {
		fmt.Println(*prefix_group.LogGroupName)
		fmt.Println(*prefix_group.RetentionInDays)
	}

	fmt.Println("Pattern Group:")
	for _, pattern_group := range pattern_output.LogGroups {
		fmt.Println(*pattern_group.LogGroupName)
		// This is where it fails because the retention in days is not set
		fmt.Println(*pattern_group.RetentionInDays)
	}
}

Possible Solution

No response

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

github.com/aws/[email protected] github.com/aws/[email protected]
github.com/aws/[email protected] github.com/google/[email protected]
github.com/aws/[email protected] github.com/jmespath/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/aws-sdk-go-v2/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/aws-sdk-go-v2/feature/ec2/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/aws-sdk-go-v2/internal/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/aws-sdk-go-v2/service/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/aws-sdk-go-v2/service/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/aws-sdk-go-v2/service/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/google/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/aws-sdk-go-v2/feature/ec2/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/aws-sdk-go-v2/service/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/aws-sdk-go-v2/service/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/aws-sdk-go-v2/service/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/[email protected] github.com/google/[email protected]
github.com/aws/aws-sdk-go-v2/feature/ec2/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/feature/ec2/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/feature/ec2/[email protected] github.com/google/[email protected]
github.com/aws/aws-sdk-go-v2/internal/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/internal/endpoints/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/internal/endpoints/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/internal/endpoints/[email protected] github.com/google/[email protected]
github.com/aws/aws-sdk-go-v2/internal/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/aws-sdk-go-v2/internal/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/aws-sdk-go-v2/internal/endpoints/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/service/internal/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/service/internal/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/service/internal/[email protected] github.com/google/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/aws-sdk-go-v2/internal/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/aws-sdk-go-v2/internal/endpoints/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/aws-sdk-go-v2/internal/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/aws-sdk-go-v2/internal/endpoints/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/aws-sdk-go-v2/internal/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/aws-sdk-go-v2/internal/endpoints/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/aws-sdk-go-v2/service/internal/[email protected]
github.com/aws/aws-sdk-go-v2/service/[email protected] github.com/aws/[email protected]
github.com/aws/[email protected] github.com/google/[email protected]
github.com/aws/[email protected] github.com/jmespath/[email protected]

Compiler and Version used

go version go1.19.3 darwin/amd64

Operating System and version

MacOs Ventura 13.0.1

@sean-kuendig-copebit sean-kuendig-copebit added bug Something isn't working needs-triage labels Apr 18, 2023
@jmklix jmklix self-assigned this Apr 20, 2023
@jmklix
Copy link
Member

jmklix commented Apr 20, 2023

The default is indefinite retentions so it looks like this is just not being changed when you are trying to set it to 30. Looking into this.

@jmklix
Copy link
Member

jmklix commented Oct 4, 2023

Sorry for the delay. I was able to reproduce this and it seems to be that the problem is with the service not this sdk. The response for logGroupNamePattern is missing the retentionInDays

logGroupNamePrefix:

{"logGroups":[{"arn":"arn:aws:logs:us-west-2:xxxxxxxxxx:log-group:mfb2sj:*","creationTime":1696373299319,"logGroupName":"mfb2sj","metricFilterCount":0,"retentionInDays":30,"storedBytes":0}]}

logGroupNamePattern:

{"logGroups":[{"arn":"arn:aws:logs:us-west-2:xxxxxxxxxx:log-group:mfb2sj:*","creationTime":1696373299319,"logGroupName":"mfb2sj","metricFilterCount":0}],"nextToken":"nexttokenstring"}

Opening internal request to service team

@jmklix jmklix transferred this issue from aws/aws-sdk-go-v2 Oct 4, 2023
@jmklix jmklix added service-api This issue pertains to the AWS API cloudwatchlogs and removed needs-triage labels Oct 4, 2023
@jmklix jmklix self-assigned this Oct 4, 2023
@jmklix
Copy link
Member

jmklix commented Oct 4, 2023

P101732296

@jmklix
Copy link
Member

jmklix commented Oct 5, 2023

This behaving as expected. As noted in the docs here:

If you specify logGroupNamePattern in your request, then only arn, creationTime, and logGroupName are included in the response.

So with logGroupNamePattern you can't get the RetentionInDays. Please let me know if you have any other questions

@jmklix jmklix closed this as completed Oct 5, 2023
@github-actions
Copy link

github-actions bot commented Oct 5, 2023

This issue is now closed.

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working cloudwatchlogs service-api This issue pertains to the AWS API
Projects
None yet
Development

No branches or pull requests

3 participants