Skip to content

Commit

Permalink
add an option to encode file name
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkpc138 committed Dec 12, 2024
1 parent b7e14b3 commit 38f58b1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/lobster/sink/exporter/bucket/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/http"
"net/url"
"path"
"strings"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -90,7 +91,13 @@ func (b BasicBucket) Dir(chunk model.Chunk, date time.Time) string {
}

func (b BasicBucket) FileName(start, end time.Time) string {
return fmt.Sprintf("%s_%s.log", start.Format(layoutFileName), end.Format(layoutFileName))
fileName := fmt.Sprintf("%s_%s.log", start.Format(layoutFileName), end.Format(layoutFileName))

if b.Order.LogExportRule.ShouldEncodeFileName {
return strings.ReplaceAll(fileName, "+", "%2B")
}

return fileName
}

func (b BasicBucket) Validate() error {
Expand Down
11 changes: 9 additions & 2 deletions pkg/lobster/sink/exporter/bucket/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"path"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -75,8 +76,14 @@ func (s S3Bucket) Dir(chunk model.Chunk, date time.Time) string {
dirPath)
}

func (s S3Bucket) FileName(start, end time.Time) string {
return fmt.Sprintf("%s_%s.log", start.Format(layoutFileName), end.Format(layoutFileName))
func (b S3Bucket) FileName(start, end time.Time) string {
fileName := fmt.Sprintf("%s_%s.log", start.Format(layoutFileName), end.Format(layoutFileName))

if b.Order.LogExportRule.ShouldEncodeFileName {
return strings.ReplaceAll(fileName, "+", "%2B")
}

return fileName
}

func (s S3Bucket) Validate() error {
Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/api/v1/logExportRule.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type LogExportRule struct {
Filter Filter `json:"filter,omitempty"`
// Interval to export logs
Interval metav1.Duration `json:"interval,omitempty" swaggertype:"string" example:"time duration(e.g. 1m)"`
// Provide an option to convert '+' to '%2B' to address issues in certain web environments where '+' is misinterpreted
ShouldEncodeFileName bool `json:"shouldEncodeFileName,omitempty"`
}

func (r LogExportRule) Validate() error {
Expand Down

0 comments on commit 38f58b1

Please sign in to comment.