Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Rename schema to proto
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 committed May 24, 2018
1 parent 6ad3d3d commit 835e846
Show file tree
Hide file tree
Showing 19 changed files with 225 additions and 225 deletions.
6 changes: 3 additions & 3 deletions aggregation/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ var (
// ID represents a compressed view of Types.
type ID [IDLen]uint64

// NewIDFromSchema creates an ID from schema.
func NewIDFromSchema(input []aggregationpb.AggregationType) (ID, error) {
aggTypes, err := NewTypesFromSchema(input)
// NewIDFromProto creates an ID from proto.
func NewIDFromProto(input []aggregationpb.AggregationType) (ID, error) {
aggTypes, err := NewTypesFromProto(input)
if err != nil {
return DefaultID, err
}
Expand Down
28 changes: 14 additions & 14 deletions aggregation/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ var (
// Type defines an aggregation function.
type Type int

// NewTypeFromSchema creates an aggregation type from a schema.
func NewTypeFromSchema(input aggregationpb.AggregationType) (Type, error) {
// NewTypeFromProto creates an aggregation type from a proto.
func NewTypeFromProto(input aggregationpb.AggregationType) (Type, error) {
aggType := Type(input)
if !aggType.IsValid() {
return UnknownType, fmt.Errorf("invalid aggregation type from schema: %s", input)
return UnknownType, fmt.Errorf("invalid aggregation type from proto: %s", input)
}
return aggType, nil
}
Expand Down Expand Up @@ -190,10 +190,10 @@ func (a Type) Quantile() (float64, bool) {
}
}

// Schema returns the schema of the aggregation type.
func (a Type) Schema() (aggregationpb.AggregationType, error) {
// Proto returns the proto of the aggregation type.
func (a Type) Proto() (aggregationpb.AggregationType, error) {
s := aggregationpb.AggregationType(a)
if err := validateSchemaType(s); err != nil {
if err := validateProtoType(s); err != nil {
return aggregationpb.AggregationType_UNKNOWN, err
}
return s, nil
Expand All @@ -214,10 +214,10 @@ func (a *Type) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil
}

func validateSchemaType(a aggregationpb.AggregationType) error {
func validateProtoType(a aggregationpb.AggregationType) error {
_, ok := aggregationpb.AggregationType_name[int32(a)]
if !ok {
return fmt.Errorf("invalid schema aggregation type: %v", a)
return fmt.Errorf("invalid proto aggregation type: %v", a)
}
return nil
}
Expand All @@ -234,11 +234,11 @@ func ParseType(str string) (Type, error) {
// Types is a list of Types.
type Types []Type

// NewTypesFromSchema creates a list of aggregation types from a schema.
func NewTypesFromSchema(input []aggregationpb.AggregationType) (Types, error) {
// NewTypesFromProto creates a list of aggregation types from a proto.
func NewTypesFromProto(input []aggregationpb.AggregationType) (Types, error) {
res := make([]Type, len(input))
for i, t := range input {
aggType, err := NewTypeFromSchema(t)
aggType, err := NewTypeFromProto(t)
if err != nil {
return DefaultTypes, err
}
Expand Down Expand Up @@ -358,8 +358,8 @@ func (aggTypes Types) PooledQuantiles(p pool.FloatsPool) ([]float64, bool) {
return res, pooled
}

// Schema returns the schema of the aggregation types.
func (aggTypes Types) Schema() ([]aggregationpb.AggregationType, error) {
// Proto returns the proto of the aggregation types.
func (aggTypes Types) Proto() ([]aggregationpb.AggregationType, error) {
// This is the same as returning an empty slice from the functionality perspective.
// It makes creating testing fixtures much simpler.
if aggTypes == nil {
Expand All @@ -368,7 +368,7 @@ func (aggTypes Types) Schema() ([]aggregationpb.AggregationType, error) {

res := make([]aggregationpb.AggregationType, len(aggTypes))
for i, aggType := range aggTypes {
s, err := aggType.Schema()
s, err := aggType.Proto()
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion encoding/msgpack/wire_format.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ increase the version for backward-compatible changes.
Backward-incompatible changes (e.g., removing a field or changing a field type) must be deployed
to the server-side first then to the client-side. It is REQUIRED to increase the version for
backward-incompatible changes. If the changes are deployed to the client-side first, the server
will optionally ignore the messages with the higher version.
will optionally ignore the messages with the higher version.
2 changes: 1 addition & 1 deletion matcher/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (r *ruleSet) toRuleSet(value kv.Value) (interface{}, error) {
if err := value.Unmarshal(r.proto); err != nil {
return nil, err
}
return rules.NewRuleSetFromSchema(value.Version(), r.proto, r.ruleSetOpts)
return rules.NewRuleSetFromProto(value.Version(), r.proto, r.ruleSetOpts)
}

// process processes an ruleset update.
Expand Down
24 changes: 12 additions & 12 deletions policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
// DefaultPolicy represents a default policy.
DefaultPolicy Policy

errNilPolicySchema = errors.New("nil policy schema")
errNilPolicyProto = errors.New("nil policy proto")
errInvalidPolicyString = errors.New("invalid policy string")
)

Expand All @@ -52,18 +52,18 @@ func NewPolicy(sp StoragePolicy, aggID aggregation.ID) Policy {
return Policy{StoragePolicy: sp, AggregationID: aggID}
}

// NewPolicyFromSchema creates a new policy from a schema policy.
func NewPolicyFromSchema(p *policypb.Policy) (Policy, error) {
// NewPolicyFromProto creates a new policy from a proto policy.
func NewPolicyFromProto(p *policypb.Policy) (Policy, error) {
if p == nil {
return DefaultPolicy, errNilPolicySchema
return DefaultPolicy, errNilPolicyProto
}

policy, err := NewStoragePolicyFromProto(p.StoragePolicy)
if err != nil {
return DefaultPolicy, err
}

aggID, err := aggregation.NewIDFromSchema(p.AggregationTypes)
aggID, err := aggregation.NewIDFromProto(p.AggregationTypes)
if err != nil {
return DefaultPolicy, err
}
Expand All @@ -72,8 +72,8 @@ func NewPolicyFromSchema(p *policypb.Policy) (Policy, error) {

}

// Schema returns the schema of the policy.
func (p Policy) Schema() (*policypb.Policy, error) {
// Proto returns the proto of the policy.
func (p Policy) Proto() (*policypb.Policy, error) {
var storagePolicyProto policypb.StoragePolicy
err := p.StoragePolicy.ToProto(&storagePolicyProto)
if err != nil {
Expand All @@ -85,14 +85,14 @@ func (p Policy) Schema() (*policypb.Policy, error) {
return nil, err
}

schemaAggTypes, err := aggTypes.Schema()
protoAggTypes, err := aggTypes.Proto()
if err != nil {
return nil, err
}

return &policypb.Policy{
StoragePolicy: &storagePolicyProto,
AggregationTypes: schemaAggTypes,
AggregationTypes: protoAggTypes,
}, nil
}

Expand Down Expand Up @@ -169,11 +169,11 @@ func ParsePolicy(str string) (Policy, error) {
return NewPolicy(sp, aggID), nil
}

// NewPoliciesFromSchema creates multiple new policies from given schema policies.
func NewPoliciesFromSchema(policies []*policypb.Policy) ([]Policy, error) {
// NewPoliciesFromProto creates multiple new policies from given proto policies.
func NewPoliciesFromProto(policies []*policypb.Policy) ([]Policy, error) {
res := make([]Policy, 0, len(policies))
for _, p := range policies {
policy, err := NewPolicyFromSchema(p)
policy, err := NewPolicyFromProto(p)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestPolicyUnmarshalYAMLErrors(t *testing.T) {
}
}

func TestNewPoliciesFromSchema(t *testing.T) {
func TestNewPoliciesFromProto(t *testing.T) {
input := []*policypb.Policy{
&policypb.Policy{
StoragePolicy: &policypb.StoragePolicy{
Expand Down Expand Up @@ -132,15 +132,15 @@ func TestNewPoliciesFromSchema(t *testing.T) {
},
}

res, err := NewPoliciesFromSchema(input)
res, err := NewPoliciesFromProto(input)
require.NoError(t, err)
require.Equal(t, []Policy{
NewPolicy(NewStoragePolicy(10*time.Second, xtime.Second, 24*time.Hour), aggregation.MustCompressTypes(aggregation.Mean, aggregation.P999)),
NewPolicy(NewStoragePolicy(time.Minute, xtime.Minute, 240*time.Hour), aggregation.MustCompressTypes(aggregation.Mean, aggregation.P9999)),
}, res)
}

func TestParsePolicyIntoSchema(t *testing.T) {
func TestParsePolicyIntoProto(t *testing.T) {
inputs := []struct {
str string
expected *policypb.Policy
Expand Down Expand Up @@ -225,7 +225,7 @@ func TestParsePolicyIntoSchema(t *testing.T) {
p, err := ParsePolicy(input.str)
require.NoError(t, err)

sp, err := p.Schema()
sp, err := p.Proto()
require.NoError(t, err)
require.Equal(t, input.expected, sp, input.str)
}
Expand Down
4 changes: 2 additions & 2 deletions policy/storage_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var (
// EmptyStoragePolicy represents an empty storage policy.
EmptyStoragePolicy StoragePolicy

errNilStoragePolicySchema = errors.New("nil storage policy schema")
errNilStoragePolicyProto = errors.New("nil storage policy proto")
errInvalidStoragePolicyString = errors.New("invalid storage policy string")
)

Expand All @@ -63,7 +63,7 @@ func NewStoragePolicy(window time.Duration, precision xtime.Unit, retention time
// NewStoragePolicyFromProto creates a new storage policy from a storage policy protobuf message.
func NewStoragePolicyFromProto(p *policypb.StoragePolicy) (StoragePolicy, error) {
if p == nil {
return EmptyStoragePolicy, errNilStoragePolicySchema
return EmptyStoragePolicy, errNilStoragePolicyProto
}
precision := time.Duration(p.Resolution.Precision)
unit, err := xtime.UnitFromDuration(precision)
Expand Down
2 changes: 1 addition & 1 deletion policy/storage_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func TestStoragePolicyUnmarshalYAMLErrors(t *testing.T) {
}
}

func TestNewStoragePolicyFromSchema(t *testing.T) {
func TestNewStoragePolicyFromProto(t *testing.T) {
inputs := []struct {
s *policypb.StoragePolicy
p StoragePolicy
Expand Down
22 changes: 11 additions & 11 deletions rules/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (

var (
errMappingRuleSnapshotIndexOutOfRange = errors.New("mapping rule snapshot index out of range")
errNilMappingRuleSnapshotSchema = errors.New("nil mapping rule snapshot schema")
errNilMappingRuleSchema = errors.New("nil mapping rule schema")
errNilMappingRuleSnapshotProto = errors.New("nil mapping rule snapshot proto")
errNilMappingRuleProto = errors.New("nil mapping rule proto")
)

// mappingRuleSnapshot defines a rule snapshot such that if a metric matches the
Expand All @@ -58,9 +58,9 @@ func newMappingRuleSnapshot(
opts filters.TagsFilterOptions,
) (*mappingRuleSnapshot, error) {
if r == nil {
return nil, errNilMappingRuleSnapshotSchema
return nil, errNilMappingRuleSnapshotProto
}
policies, err := policy.NewPoliciesFromSchema(r.Policies)
policies, err := policy.NewPoliciesFromProto(r.Policies)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -152,8 +152,8 @@ func (mrs *mappingRuleSnapshot) clone() mappingRuleSnapshot {
}
}

// Schema returns the given MappingRuleSnapshot in protobuf form.
func (mrs *mappingRuleSnapshot) Schema() (*rulepb.MappingRuleSnapshot, error) {
// Proto returns the given MappingRuleSnapshot in protobuf form.
func (mrs *mappingRuleSnapshot) Proto() (*rulepb.MappingRuleSnapshot, error) {
res := &rulepb.MappingRuleSnapshot{
Name: mrs.name,
Tombstoned: mrs.tombstoned,
Expand All @@ -165,7 +165,7 @@ func (mrs *mappingRuleSnapshot) Schema() (*rulepb.MappingRuleSnapshot, error) {

policies := make([]*policypb.Policy, len(mrs.policies))
for i, p := range mrs.policies {
policy, err := p.Schema()
policy, err := p.Proto()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func newMappingRule(
opts filters.TagsFilterOptions,
) (*mappingRule, error) {
if mc == nil {
return nil, errNilMappingRuleSchema
return nil, errNilMappingRuleProto
}
snapshots := make([]*mappingRuleSnapshot, 0, len(mc.Snapshots))
for i := 0; i < len(mc.Snapshots); i++ {
Expand Down Expand Up @@ -368,11 +368,11 @@ func (mc *mappingRule) history() ([]*models.MappingRuleView, error) {
return views, nil
}

// Schema returns the given MappingRule in protobuf form.
func (mc *mappingRule) Schema() (*rulepb.MappingRule, error) {
// Proto returns the given MappingRule in protobuf form.
func (mc *mappingRule) Proto() (*rulepb.MappingRule, error) {
snapshots := make([]*rulepb.MappingRuleSnapshot, len(mc.snapshots))
for i, s := range mc.snapshots {
snapshot, err := s.Schema()
snapshot, err := s.Proto()
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 835e846

Please sign in to comment.