use a prefix for files generated on s3
This commit is contained in:
parent
9ed761edc6
commit
6f8ff3f11d
2 changed files with 18 additions and 3 deletions
|
|
@ -18,13 +18,18 @@ import (
|
||||||
// dash. This struct requires the configuration of an S3 bucket and endpoint.
|
// dash. This struct requires the configuration of an S3 bucket and endpoint.
|
||||||
type S3Emitter struct {
|
type S3Emitter struct {
|
||||||
S3Bucket string
|
S3Bucket string
|
||||||
|
S3Prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
// S3FileName generates a file name based on the First and Last sequence numbers from the buffer. The current
|
// S3FileName generates a file name based on the First and Last sequence numbers from the buffer. The current
|
||||||
// UTC date (YYYY-MM-DD) is base of the path to logically group days of batches.
|
// UTC date (YYYY-MM-DD) is base of the path to logically group days of batches.
|
||||||
func (e S3Emitter) S3FileName(firstSeq string, lastSeq string) string {
|
func (e S3Emitter) S3FileName(firstSeq string, lastSeq string) string {
|
||||||
date := time.Now().UTC().Format("2006/01/02")
|
date := time.Now().UTC().Format("2006/01/02")
|
||||||
|
if e.S3Prefix == "" {
|
||||||
return fmt.Sprintf("%v/%v-%v", date, firstSeq, lastSeq)
|
return fmt.Sprintf("%v/%v-%v", date, firstSeq, lastSeq)
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("%v/%v/%v-%v", e.S3Prefix, date, firstSeq, lastSeq)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit is invoked when the buffer is full. This method emits the set of filtered records.
|
// Emit is invoked when the buffer is full. This method emits the set of filtered records.
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,22 @@ import (
|
||||||
|
|
||||||
func TestS3FileName(t *testing.T) {
|
func TestS3FileName(t *testing.T) {
|
||||||
d := time.Now().UTC().Format("2006/01/02")
|
d := time.Now().UTC().Format("2006/01/02")
|
||||||
e := S3Emitter{}
|
e := S3Emitter{S3Bucket: "bucket", S3Prefix: "prefix"}
|
||||||
|
|
||||||
expected := fmt.Sprintf("%v/a-b", d)
|
expected := fmt.Sprintf("prefix/%v/a-b", d)
|
||||||
result := e.S3FileName("a", "b")
|
result := e.S3FileName("a", "b")
|
||||||
|
|
||||||
if result != expected {
|
if result != expected {
|
||||||
t.Errorf("S3FileName() = %v want %v", result, expected)
|
t.Errorf("S3FileName() = %v want %v", result, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.S3Prefix = ""
|
||||||
|
|
||||||
|
expected = fmt.Sprintf("%v/a-b", d)
|
||||||
|
result = e.S3FileName("a", "b")
|
||||||
|
|
||||||
|
if result != expected {
|
||||||
|
t.Errorf("S3FileName() = %v want %v", result, expected)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue