Skip to content

Commit

Permalink
[receiver/awss3receiver] Add support RFC3399 format for starttime and…
Browse files Browse the repository at this point in the history
… endtime
  • Loading branch information
sters committed Dec 11, 2024
1 parent 28ede1d commit dbf8d26
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion receiver/awss3receiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion receiver/awss3receiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 14 additions & 1 deletion receiver/awss3receiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion receiver/awss3receiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit dbf8d26

Please sign in to comment.