parse the duration string specified in an event file config into a time.Duration (#1446)
This commit is contained in:
3 files changed
+24
-7
No files matched your search
@@ -473,6 +473,15 @@ func parseEventing(eventObj *ast.ObjectItem) (*event.EventerConfig, error) {
|
||||
s.StderrConfig = new(event.StderrSinkTypeConfig)
|
||||
}
|
||||
|
||||
// parse the duration string specified in a file config into a time.Duration
|
||||
if s.FileConfig != nil && s.FileConfig.RotateDurationHCL != "" {
|
||||
var err error
|
||||
s.FileConfig.RotateDuration, err = time.ParseDuration(s.FileConfig.RotateDurationHCL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't parse rotation duration %s", s.FileConfig.RotateDurationHCL)
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/observability/event"
|
||||
"github.com/hashicorp/go-secure-stdlib/configutil"
|
||||
@@ -394,6 +395,7 @@ func TestController_EventingConfig(t *testing.T) {
|
||||
event_types = [ "audit", "observation" ]
|
||||
file {
|
||||
file_name = "file-name"
|
||||
rotate_duration = "2m"
|
||||
}
|
||||
}
|
||||
sink {
|
||||
@@ -412,6 +414,7 @@ func TestController_EventingConfig(t *testing.T) {
|
||||
event_types = [ "audit", "observation" ]
|
||||
file {
|
||||
file_name = "file-name"
|
||||
rotate_duration = "2m"
|
||||
}
|
||||
}
|
||||
sink "stderr" {
|
||||
@@ -429,6 +432,7 @@ func TestController_EventingConfig(t *testing.T) {
|
||||
event_types = [ "audit", "observation" ]
|
||||
file {
|
||||
file_name = "file-name"
|
||||
rotate_duration = "2m"
|
||||
}
|
||||
}
|
||||
sink {
|
||||
@@ -449,7 +453,8 @@ func TestController_EventingConfig(t *testing.T) {
|
||||
"name": "configured-sink",
|
||||
"event_types": ["audit", "observation"],
|
||||
"file": {
|
||||
"file_name": "file-name"
|
||||
"file_name": "file-name",
|
||||
"rotate_duration": "2m"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -472,7 +477,9 @@ func TestController_EventingConfig(t *testing.T) {
|
||||
Format: "cloudevents-json",
|
||||
EventTypes: []event.Type{"audit", "observation"},
|
||||
FileConfig: &event.FileSinkTypeConfig{
|
||||
FileName: "file-name",
|
||||
FileName: "file-name",
|
||||
RotateDurationHCL: "2m",
|
||||
RotateDuration: 2 * time.Minute,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -75,11 +75,12 @@ type StderrSinkTypeConfig struct{}
|
||||
|
||||
// FileSinkTypeConfig contains configuration structures for file sink types
|
||||
type FileSinkTypeConfig struct {
|
||||
Path string `hcl:"path" mapstructure:"path"` // Path defines the file path for the sink
|
||||
FileName string `hcl:"file_name" mapstructure:"file_name"` // FileName defines the file name for the sink
|
||||
RotateBytes int `hcl:"rotate_bytes" mapstructure:"rotate_bytes"` // RotateByes defines the number of bytes that should trigger rotation of a FileSink
|
||||
RotateDuration time.Duration `hcl:"rotate_duration" mapstructure:"rotate_duration"` // RotateDuration defines how often a FileSink should be rotated
|
||||
RotateMaxFiles int `hcl:"rotate_max_files" mapstructure:"rotate_max_files"` // RotateMaxFiles defines how may historical rotated files should be kept for a FileSink
|
||||
Path string `hcl:"path" mapstructure:"path"` // Path defines the file path for the sink
|
||||
FileName string `hcl:"file_name" mapstructure:"file_name"` // FileName defines the file name for the sink
|
||||
RotateBytes int `hcl:"rotate_bytes" mapstructure:"rotate_bytes"` // RotateBytes defines the number of bytes that should trigger rotation of a FileSink
|
||||
RotateDuration time.Duration `mapstructure:"rotate_duration"` // RotateDuration defines how often a FileSink should be rotated
|
||||
RotateDurationHCL string `hcl:"rotate_duration" json:"-"` // RotateDurationHCL defines hcl string version of RotateDuration
|
||||
RotateMaxFiles int `hcl:"rotate_max_files" mapstructure:"rotate_max_files"` // RotateMaxFiles defines how may historical rotated files should be kept for a FileSink
|
||||
}
|
||||
|
||||
// FilterType defines a type for filters (allow or deny)
|
||||
|
||||
Reference in new issue
Block a user