Skip to content

Commit 15d7fb3

Browse files
authored
Satisfy yaml Marshaler interface on structs with custom Unmarshalers (#4213)
* Satisfy yaml Marshaler interface on structs with custom Unmarshalers
1 parent c1a96fd commit 15d7fb3

16 files changed

Lines changed: 96 additions & 7 deletions

File tree

src/aggregator/client/queue.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ func (t DropType) String() string {
8080
return "unknown"
8181
}
8282

83+
// MarshalYAML marshals a DropType.
84+
func (t *DropType) MarshalYAML() (interface{}, error) {
85+
return t.String(), nil
86+
}
87+
8388
// UnmarshalYAML unmarshals a DropType into a valid type from string.
8489
func (t *DropType) UnmarshalYAML(unmarshal func(interface{}) error) error {
8590
var str string

src/cmd/services/m3dbnode/config/bootstrap.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ const (
9696
ExcludeCommitLogBootstrapMode
9797
)
9898

99+
// MarshalYAML marshals a BootstrapMode.
100+
func (m *BootstrapMode) MarshalYAML() (interface{}, error) {
101+
return m.String(), nil
102+
}
103+
99104
// UnmarshalYAML unmarshals an BootstrapMode into a valid type from string.
100105
func (m *BootstrapMode) UnmarshalYAML(unmarshal func(interface{}) error) error {
101106
var str string

src/cmd/services/m3dbnode/config/config_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ db:
5454
cacheRegexp: false
5555
cacheTerms: false
5656
cacheSearch: null
57+
series:
58+
policy: lru
5759
5860
metrics:
5961
prometheus:
@@ -344,7 +346,7 @@ func TestConfiguration(t *testing.T) {
344346
forwardIndexProbability: 0
345347
forwardIndexThreshold: 0
346348
transforms:
347-
truncateBy: 0
349+
truncateBy: none
348350
forceValue: null
349351
logging:
350352
file: /var/log/m3dbnode.log
@@ -361,8 +363,8 @@ func TestConfiguration(t *testing.T) {
361363
defaultSummaryObjectives: []
362364
onError: ""
363365
samplingRate: 1
364-
extended: 3
365-
sanitization: 2
366+
extended: detailed
367+
sanitization: prometheus
366368
listenAddress: 0.0.0.0:9000
367369
clusterListenAddress: 0.0.0.0:9001
368370
httpNodeListenAddress: 0.0.0.0:9002
@@ -376,9 +378,9 @@ func TestConfiguration(t *testing.T) {
376378
hostname: null
377379
client:
378380
config: null
379-
writeConsistencyLevel: 2
380-
readConsistencyLevel: 2
381-
connectConsistencyLevel: 0
381+
writeConsistencyLevel: majority
382+
readConsistencyLevel: unstrict_majority
383+
connectConsistencyLevel: any
382384
writeTimeout: 10s
383385
fetchTimeout: 15s
384386
connectTimeout: 20s
@@ -428,7 +430,9 @@ func TestConfiguration(t *testing.T) {
428430
verify: null
429431
blockRetrieve: null
430432
cache:
431-
series: null
433+
series:
434+
policy: lru
435+
lru: null
432436
postingsList:
433437
size: 100
434438
cacheRegexp: false

src/dbnode/discovery/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ const (
5959
M3AggregatorClusterType
6060
)
6161

62+
// MarshalYAML marshals a ConfigurationType.
63+
func (t *ConfigurationType) MarshalYAML() (interface{}, error) {
64+
return t.String(), nil
65+
}
66+
6267
// UnmarshalYAML unmarshals an ConfigurationType into a valid type from string.
6368
func (t *ConfigurationType) UnmarshalYAML(unmarshal func(interface{}) error) error {
6469
var str string

src/dbnode/encoding/iterators_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ func ParseIterateEqualTimestampStrategy(
108108
str, ValidIterateEqualTimestampStrategies())
109109
}
110110

111+
// MarshalYAML marshals an IterateEqualTimestampStrategy.
112+
func (s *IterateEqualTimestampStrategy) MarshalYAML() (interface{}, error) {
113+
return s.String(), nil
114+
}
115+
111116
// UnmarshalYAML unmarshals an IterateEqualTimestampStrategy into a
112117
// valid type from string.
113118
func (s *IterateEqualTimestampStrategy) UnmarshalYAML(unmarshal func(interface{}) error) error {

src/dbnode/persist/fs/migration/version.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ func ValidateMigrationVersion(m MigrationVersion) error {
7070
m, validMigrationVersions)
7171
}
7272

73+
// MarshalYAML marshals a MigrationVersion.
74+
func (m MigrationVersion) MarshalYAML() (interface{}, error) {
75+
return m.String(), nil
76+
}
77+
7378
// UnmarshalYAML unmarshals a migrate version.
7479
func (m *MigrationVersion) UnmarshalYAML(unmarshal func(interface{}) error) error {
7580
var str string

src/dbnode/storage/series/policy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ func ParseCachePolicy(str string) (CachePolicy, error) {
103103
str, ValidCachePolicies())
104104
}
105105

106+
// MarshalYAML marshals a CachePolicy.
107+
func (p CachePolicy) MarshalYAML() (interface{}, error) {
108+
return p.String(), nil
109+
}
110+
106111
// UnmarshalYAML unmarshals an CachePolicy into a valid type from string.
107112
func (p *CachePolicy) UnmarshalYAML(unmarshal func(interface{}) error) error {
108113
var str string

src/dbnode/storage/series/truncate_type.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ func (t TruncateType) String() string {
6363
}
6464
}
6565

66+
// MarshalYAML marshals a TruncateType.
67+
func (t TruncateType) MarshalYAML() (interface{}, error) {
68+
return t.String(), nil
69+
}
70+
6671
// UnmarshalYAML unmarshals a stored truncation type.
6772
func (t *TruncateType) UnmarshalYAML(unmarshal func(interface{}) error) error {
6873
var str string

src/dbnode/topology/consistency_level.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ func ValidateConsistencyLevel(v ConsistencyLevel) error {
9292
return errConsistencyLevelInvalid
9393
}
9494

95+
// MarshalYAML marshals a ConsistencyLevel.
96+
func (l *ConsistencyLevel) MarshalYAML() (interface{}, error) {
97+
return l.String(), nil
98+
}
99+
95100
// UnmarshalYAML unmarshals an ConnectConsistencyLevel into a valid type from string.
96101
func (l *ConsistencyLevel) UnmarshalYAML(unmarshal func(interface{}) error) error {
97102
var str string
@@ -183,6 +188,11 @@ func ValidateConnectConsistencyLevel(v ConnectConsistencyLevel) error {
183188
return errClusterConnectConsistencyLevelInvalid
184189
}
185190

191+
// MarshalYAML marshals a ConnectConsistencyLevel.
192+
func (l *ConnectConsistencyLevel) MarshalYAML() (interface{}, error) {
193+
return l.String(), nil
194+
}
195+
186196
// UnmarshalYAML unmarshals an ConnectConsistencyLevel into a valid type from string.
187197
func (l *ConnectConsistencyLevel) UnmarshalYAML(unmarshal func(interface{}) error) error {
188198
var str string
@@ -300,6 +310,11 @@ func ValidateReadConsistencyLevel(v ReadConsistencyLevel) error {
300310
return errReadConsistencyLevelInvalid
301311
}
302312

313+
// MarshalYAML marshals a ReadConsistencyLevel.
314+
func (l *ReadConsistencyLevel) MarshalYAML() (interface{}, error) {
315+
return l.String(), nil
316+
}
317+
303318
// UnmarshalYAML unmarshals an ConnectConsistencyLevel into a valid type from string.
304319
func (l *ReadConsistencyLevel) UnmarshalYAML(unmarshal func(interface{}) error) error {
305320
var str string

src/metrics/aggregation/type.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ func (a Type) Proto() (aggregationpb.AggregationType, error) {
258258
return s, nil
259259
}
260260

261+
// MarshalYAML marshals a Type.
262+
func (a Type) MarshalYAML() (interface{}, error) {
263+
return a.String(), nil
264+
}
265+
261266
// UnmarshalYAML unmarshals text-encoded data into an aggregation type.
262267
func (a *Type) UnmarshalYAML(unmarshal func(interface{}) error) error {
263268
var str string

0 commit comments

Comments
 (0)