Skip to content

Commit

Permalink
Merge pull request #23 from naver/add-filename_encoding
Browse files Browse the repository at this point in the history
add an option to encode file name
  • Loading branch information
sharkpc138 authored Dec 12, 2024
2 parents de0af31 + 7b981a1 commit 4fd1759
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 3 deletions.
4 changes: 4 additions & 0 deletions deploy/templates/operator/manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ spec:
time-based layout
type: string
type: object
shouldEncodeFileName:
description: Provide an option to convert '+' to '%2B' to address
issues in certain web environments where '+' is misinterpreted
type: boolean
type: object
type: array
logMetricRules:
Expand Down
4 changes: 4 additions & 0 deletions pkg/docs/operator/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ const docTemplate = `{
"$ref": "#/definitions/v1.S3Bucket"
}
]
},
"shouldEncodeFileName": {
"description": "Provide an option to convert '+' to '%2B' to address issues in certain web environments where '+' is misinterpreted",
"type": "boolean"
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/docs/operator/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@
"$ref": "#/definitions/v1.S3Bucket"
}
]
},
"shouldEncodeFileName": {
"description": "Provide an option to convert '+' to '%2B' to address issues in certain web environments where '+' is misinterpreted",
"type": "boolean"
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/docs/operator/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ definitions:
allOf:
- $ref: '#/definitions/v1.S3Bucket'
description: Settings required to export logs to S3 bucket
shouldEncodeFileName:
description: Provide an option to convert '+' to '%2B' to address issues in
certain web environments where '+' is misinterpreted
type: boolean
type: object
v1.LogMetricRule:
properties:
Expand Down
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
4 changes: 4 additions & 0 deletions web/static/docs/operator/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@
"$ref": "#/definitions/v1.S3Bucket"
}
]
},
"shouldEncodeFileName": {
"description": "Provide an option to convert '+' to '%2B' to address issues in certain web environments where '+' is misinterpreted",
"type": "boolean"
}
}
},
Expand Down

0 comments on commit 4fd1759

Please sign in to comment.