From dbf8d2678d106709d10aacf4dc9ca660363fe4b5 Mon Sep 17 00:00:00 2001 From: sters Date: Thu, 12 Dec 2024 00:54:19 +0900 Subject: [PATCH] [receiver/awss3receiver] Add support RFC3399 format for starttime and endtime --- receiver/awss3receiver/README.md | 2 +- receiver/awss3receiver/config.go | 2 +- receiver/awss3receiver/config_test.go | 15 ++++++++++++++- receiver/awss3receiver/testdata/config.yaml | 6 +++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/receiver/awss3receiver/README.md b/receiver/awss3receiver/README.md index f912fcbf8216..f0efdf68fee3 100644 --- a/receiver/awss3receiver/README.md +++ b/receiver/awss3receiver/README.md @@ -38,7 +38,7 @@ The following exporter configuration parameters are supported. ### Time format for `starttime` and `endtime` The `starttime` and `endtime` fields are used to specify the time range for which to retrieve data. -The time format is either `YYYY-MM-DD HH:MM` or simply `YYYY-MM-DD`, in which case the time is assumed to be `00:00`. +The time format is either RFC3339,`YYYY-MM-DD HH:MM` or simply `YYYY-MM-DD`, in which case the time is assumed to be `00:00`. ### Encodings By default, the receiver understands the following encodings: diff --git a/receiver/awss3receiver/config.go b/receiver/awss3receiver/config.go index f50e05097bb3..62e1cc3188a8 100644 --- a/receiver/awss3receiver/config.go +++ b/receiver/awss3receiver/config.go @@ -85,7 +85,7 @@ func (c Config) Validate() error { } func parseTime(timeStr, configName string) (time.Time, error) { - layouts := []string{"2006-01-02 15:04", time.DateOnly} + layouts := []string{time.RFC3339, "2006-01-02 15:04", time.DateOnly} for _, layout := range layouts { if t, err := time.Parse(layout, timeStr); err == nil { diff --git a/receiver/awss3receiver/config_test.go b/receiver/awss3receiver/config_test.go index 0516760fdbb3..5c0883968213 100644 --- a/receiver/awss3receiver/config_test.go +++ b/receiver/awss3receiver/config_test.go @@ -53,7 +53,7 @@ func TestLoadConfig(t *testing.T) { }, { id: component.NewIDWithName(metadata.Type, "1"), - errorMessage: "s3_partition must be either 'hour' or 'minute'; unable to parse starttime (a date), accepted formats: 2006-01-02 15:04, 2006-01-02; unable to parse endtime (2024-02-03a), accepted formats: 2006-01-02 15:04, 2006-01-02", + errorMessage: "s3_partition must be either 'hour' or 'minute'; unable to parse starttime (a date), accepted formats: 2006-01-02T15:04:05Z07:00, 2006-01-02 15:04, 2006-01-02; unable to parse endtime (2024-02-03a), accepted formats: 2006-01-02T15:04:05Z07:00, 2006-01-02 15:04, 2006-01-02", }, { id: component.NewIDWithName(metadata.Type, "2"), @@ -94,6 +94,19 @@ func TestLoadConfig(t *testing.T) { }, }, }, + { + id: component.NewIDWithName(metadata.Type, "4"), + expected: &Config{ + S3Downloader: S3DownloaderConfig{ + Region: "us-east-1", + S3Bucket: "abucket", + S3Partition: "minute", + EndpointPartitionID: "aws", + }, + StartTime: "2024-01-31T15:00:00Z", + EndTime: "2024-02-03T00:00:00Z", + }, + }, } for _, tt := range tests { diff --git a/receiver/awss3receiver/testdata/config.yaml b/receiver/awss3receiver/testdata/config.yaml index b1e4823c6105..a8421b6efebd 100644 --- a/receiver/awss3receiver/testdata/config.yaml +++ b/receiver/awss3receiver/testdata/config.yaml @@ -22,4 +22,8 @@ awss3/3: suffix: "nop" notifications: opampextension: "opamp/bar" - +awss3/4: + s3downloader: + s3_bucket: abucket + starttime: "2024-01-31T15:00:00Z" + endtime: "2024-02-03T00:00:00Z"