forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
137 lines (116 loc) · 3.92 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT.
package fileexporter
import "encoding/json"
import "fmt"
import "reflect"
import "time"
// Config defines configuration for file exporter.
type Config struct {
// Compression Codec used to export telemetry data. Supported compression
// algorithms: `zstd`.
Compression *ConfigCompression `json:"compression,omitempty" yaml:"compression,omitempty" mapstructure:"compression,omitempty"`
// FlushInterval corresponds to the JSON schema field "flush_interval".
FlushInterval *time.Duration `json:"flush_interval,omitempty" yaml:"flush_interval,omitempty" mapstructure:"flush_interval,omitempty"`
// Format defines the data format of encoded telemetry data
// Options:
// - json [default]: OTLP json bytes.
// - proto: OTLP binary protobuf bytes.
Format ConfigFormat `json:"format,omitempty" yaml:"format,omitempty" mapstructure:"format,omitempty"`
// Path of the file to write to. Path is relative to the current directory.
Path string `json:"path" yaml:"path" mapstructure:"path"`
// Rotation corresponds to the JSON schema field "rotation".
Rotation *ConfigRotation `json:"rotation,omitempty" yaml:"rotation,omitempty" mapstructure:"rotation,omitempty"`
}
type ConfigCompression string
const ConfigCompressionBlank ConfigCompression = ""
const ConfigCompressionZstd ConfigCompression = "zstd"
type ConfigFormat string
const ConfigFormatJson ConfigFormat = "json"
const ConfigFormatProto ConfigFormat = "proto"
// UnmarshalJSON implements json.Unmarshaler.
func (j *ConfigFormat) UnmarshalJSON(b []byte) error {
var v string
if err := json.Unmarshal(b, &v); err != nil {
return err
}
var ok bool
for _, expected := range enumValues_ConfigFormat {
if reflect.DeepEqual(v, expected) {
ok = true
break
}
}
if !ok {
return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_ConfigFormat, v)
}
*j = ConfigFormat(v)
return nil
}
var enumValues_ConfigFormat = []interface{}{
"json",
"proto",
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *ConfigCompression) UnmarshalJSON(b []byte) error {
var v string
if err := json.Unmarshal(b, &v); err != nil {
return err
}
var ok bool
for _, expected := range enumValues_ConfigCompression {
if reflect.DeepEqual(v, expected) {
ok = true
break
}
}
if !ok {
return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_ConfigCompression, v)
}
*j = ConfigCompression(v)
return nil
}
type ConfigRotation struct {
// Localtime corresponds to the JSON schema field "localtime".
Localtime *bool `json:"localtime,omitempty" yaml:"localtime,omitempty" mapstructure:"localtime,omitempty"`
// MaxBackups corresponds to the JSON schema field "max_backups".
MaxBackups *int `json:"max_backups,omitempty" yaml:"max_backups,omitempty" mapstructure:"max_backups,omitempty"`
// MaxDays corresponds to the JSON schema field "max_days".
MaxDays *int `json:"max_days,omitempty" yaml:"max_days,omitempty" mapstructure:"max_days,omitempty"`
// MaxMegabytes corresponds to the JSON schema field "max_megabytes".
MaxMegabytes *int `json:"max_megabytes,omitempty" yaml:"max_megabytes,omitempty" mapstructure:"max_megabytes,omitempty"`
}
var enumValues_ConfigCompression = []interface{}{
"",
"zstd",
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *Config) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["path"]; !ok || v == nil {
return fmt.Errorf("field path in Config: required")
}
type Plain Config
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
if v, ok := raw["format"]; !ok || v == nil {
plain.Format = "json"
}
*j = Config(plain)
return nil
}
func (cfg *Config)ValidateHelper() error {
b, err := json.Marshal(cfg)
if err != nil {
return err
}
var config Config
if err := json.Unmarshal(b, &config); err != nil {
return err
}
return nil
}