Skip to content

Commit

Permalink
Satisfy yaml Marshaler interface on structs with custom Unmarshalers (#…
Browse files Browse the repository at this point in the history
…4213)

* Satisfy yaml Marshaler interface on structs with custom Unmarshalers
  • Loading branch information
justinjc authored Mar 29, 2023
1 parent c1a96fd commit 15d7fb3
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/aggregator/client/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func (t DropType) String() string {
return "unknown"
}

// MarshalYAML marshals a DropType.
func (t *DropType) MarshalYAML() (interface{}, error) {
return t.String(), nil
}

// UnmarshalYAML unmarshals a DropType into a valid type from string.
func (t *DropType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/services/m3dbnode/config/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ const (
ExcludeCommitLogBootstrapMode
)

// MarshalYAML marshals a BootstrapMode.
func (m *BootstrapMode) MarshalYAML() (interface{}, error) {
return m.String(), nil
}

// UnmarshalYAML unmarshals an BootstrapMode into a valid type from string.
func (m *BootstrapMode) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
18 changes: 11 additions & 7 deletions src/cmd/services/m3dbnode/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ db:
cacheRegexp: false
cacheTerms: false
cacheSearch: null
series:
policy: lru
metrics:
prometheus:
Expand Down Expand Up @@ -344,7 +346,7 @@ func TestConfiguration(t *testing.T) {
forwardIndexProbability: 0
forwardIndexThreshold: 0
transforms:
truncateBy: 0
truncateBy: none
forceValue: null
logging:
file: /var/log/m3dbnode.log
Expand All @@ -361,8 +363,8 @@ func TestConfiguration(t *testing.T) {
defaultSummaryObjectives: []
onError: ""
samplingRate: 1
extended: 3
sanitization: 2
extended: detailed
sanitization: prometheus
listenAddress: 0.0.0.0:9000
clusterListenAddress: 0.0.0.0:9001
httpNodeListenAddress: 0.0.0.0:9002
Expand All @@ -376,9 +378,9 @@ func TestConfiguration(t *testing.T) {
hostname: null
client:
config: null
writeConsistencyLevel: 2
readConsistencyLevel: 2
connectConsistencyLevel: 0
writeConsistencyLevel: majority
readConsistencyLevel: unstrict_majority
connectConsistencyLevel: any
writeTimeout: 10s
fetchTimeout: 15s
connectTimeout: 20s
Expand Down Expand Up @@ -428,7 +430,9 @@ func TestConfiguration(t *testing.T) {
verify: null
blockRetrieve: null
cache:
series: null
series:
policy: lru
lru: null
postingsList:
size: 100
cacheRegexp: false
Expand Down
5 changes: 5 additions & 0 deletions src/dbnode/discovery/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ const (
M3AggregatorClusterType
)

// MarshalYAML marshals a ConfigurationType.
func (t *ConfigurationType) MarshalYAML() (interface{}, error) {
return t.String(), nil
}

// UnmarshalYAML unmarshals an ConfigurationType into a valid type from string.
func (t *ConfigurationType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
5 changes: 5 additions & 0 deletions src/dbnode/encoding/iterators_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func ParseIterateEqualTimestampStrategy(
str, ValidIterateEqualTimestampStrategies())
}

// MarshalYAML marshals an IterateEqualTimestampStrategy.
func (s *IterateEqualTimestampStrategy) MarshalYAML() (interface{}, error) {
return s.String(), nil
}

// UnmarshalYAML unmarshals an IterateEqualTimestampStrategy into a
// valid type from string.
func (s *IterateEqualTimestampStrategy) UnmarshalYAML(unmarshal func(interface{}) error) error {
Expand Down
5 changes: 5 additions & 0 deletions src/dbnode/persist/fs/migration/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func ValidateMigrationVersion(m MigrationVersion) error {
m, validMigrationVersions)
}

// MarshalYAML marshals a MigrationVersion.
func (m MigrationVersion) MarshalYAML() (interface{}, error) {
return m.String(), nil
}

// UnmarshalYAML unmarshals a migrate version.
func (m *MigrationVersion) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
5 changes: 5 additions & 0 deletions src/dbnode/storage/series/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ func ParseCachePolicy(str string) (CachePolicy, error) {
str, ValidCachePolicies())
}

// MarshalYAML marshals a CachePolicy.
func (p CachePolicy) MarshalYAML() (interface{}, error) {
return p.String(), nil
}

// UnmarshalYAML unmarshals an CachePolicy into a valid type from string.
func (p *CachePolicy) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
5 changes: 5 additions & 0 deletions src/dbnode/storage/series/truncate_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func (t TruncateType) String() string {
}
}

// MarshalYAML marshals a TruncateType.
func (t TruncateType) MarshalYAML() (interface{}, error) {
return t.String(), nil
}

// UnmarshalYAML unmarshals a stored truncation type.
func (t *TruncateType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
15 changes: 15 additions & 0 deletions src/dbnode/topology/consistency_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func ValidateConsistencyLevel(v ConsistencyLevel) error {
return errConsistencyLevelInvalid
}

// MarshalYAML marshals a ConsistencyLevel.
func (l *ConsistencyLevel) MarshalYAML() (interface{}, error) {
return l.String(), nil
}

// UnmarshalYAML unmarshals an ConnectConsistencyLevel into a valid type from string.
func (l *ConsistencyLevel) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down Expand Up @@ -183,6 +188,11 @@ func ValidateConnectConsistencyLevel(v ConnectConsistencyLevel) error {
return errClusterConnectConsistencyLevelInvalid
}

// MarshalYAML marshals a ConnectConsistencyLevel.
func (l *ConnectConsistencyLevel) MarshalYAML() (interface{}, error) {
return l.String(), nil
}

// UnmarshalYAML unmarshals an ConnectConsistencyLevel into a valid type from string.
func (l *ConnectConsistencyLevel) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down Expand Up @@ -300,6 +310,11 @@ func ValidateReadConsistencyLevel(v ReadConsistencyLevel) error {
return errReadConsistencyLevelInvalid
}

// MarshalYAML marshals a ReadConsistencyLevel.
func (l *ReadConsistencyLevel) MarshalYAML() (interface{}, error) {
return l.String(), nil
}

// UnmarshalYAML unmarshals an ConnectConsistencyLevel into a valid type from string.
func (l *ReadConsistencyLevel) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
5 changes: 5 additions & 0 deletions src/metrics/aggregation/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ func (a Type) Proto() (aggregationpb.AggregationType, error) {
return s, nil
}

// MarshalYAML marshals a Type.
func (a Type) MarshalYAML() (interface{}, error) {
return a.String(), nil
}

// UnmarshalYAML unmarshals text-encoded data into an aggregation type.
func (a *Type) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
5 changes: 5 additions & 0 deletions src/metrics/metric/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ func MustParseType(typeStr string) Type {
return t
}

// MarshalYAML marshals a Type.
func (t Type) MarshalYAML() (interface{}, error) {
return t.String(), nil
}

// UnmarshalYAML unmarshals YAML object into a metric type.
func (t *Type) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
5 changes: 5 additions & 0 deletions src/metrics/transformation/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ func (t *Type) UnmarshalText(text []byte) error {
return nil
}

// MarshalYAML marshals a Type.
func (t Type) MarshalYAML() (interface{}, error) {
return t.String(), nil
}

// UnmarshalYAML unmarshals text-encoded data into an transformation type.
func (t *Type) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
5 changes: 5 additions & 0 deletions src/query/storage/error_behavior.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func ParseErrorBehavior(str string) (ErrorBehavior, error) {
return 0, fmt.Errorf("unrecognized error behavior: %v", str)
}

// MarshalYAML marshals an ErrorBehavior.
func (e *ErrorBehavior) MarshalYAML() (interface{}, error) {
return e.String(), nil
}

// UnmarshalYAML unmarshals an error behavior.
func (e *ErrorBehavior) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
5 changes: 5 additions & 0 deletions src/query/storage/m3/storagemetadata/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func ValidateMetricsType(v MetricsType) error {
v, validMetricsTypes)
}

// MarshalYAML marshals an ErrorBehavior.
func (t MetricsType) MarshalYAML() (interface{}, error) {
return t.String(), nil
}

// UnmarshalYAML unmarshals a stored merics type.
func (t *MetricsType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
5 changes: 5 additions & 0 deletions src/x/instrument/extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func (t ExtendedMetricsType) String() string {
return "unknown"
}

// MarshalYAML marshals an ExtendedMetricsType.
func (t *ExtendedMetricsType) MarshalYAML() (interface{}, error) {
return t.String(), nil
}

// UnmarshalYAML unmarshals an ExtendedMetricsType into a valid type from string.
func (t *ExtendedMetricsType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down
5 changes: 5 additions & 0 deletions src/x/instrument/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func (t MetricSanitizationType) String() string {
return "unknown"
}

// MarshalYAML marshals a MetricSanitizationType.
func (t *MetricSanitizationType) MarshalYAML() (interface{}, error) {
return t.String(), nil
}

// UnmarshalYAML unmarshals a MetricSanitizationType into a valid type from string.
func (t *MetricSanitizationType) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
Expand Down

0 comments on commit 15d7fb3

Please sign in to comment.