From 872e87168f57779f59d42473e772d25974ef0cbd Mon Sep 17 00:00:00 2001 From: Xi Chen Date: Tue, 20 Mar 2018 11:41:35 -0400 Subject: [PATCH] Add metric metadata --- metadata/metadata.go | 77 ++++++++++++++++++++++++++++++++ op/applied/type.go | 95 ++++++++++++++++++++++++++++++++++++++++ policy/storage_policy.go | 6 +++ 3 files changed, 178 insertions(+) create mode 100644 metadata/metadata.go create mode 100644 op/applied/type.go diff --git a/metadata/metadata.go b/metadata/metadata.go new file mode 100644 index 0000000..d169e1b --- /dev/null +++ b/metadata/metadata.go @@ -0,0 +1,77 @@ +// Copyright (c) 2018 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package metadata + +import ( + "github.com/m3db/m3metrics/aggregation" + "github.com/m3db/m3metrics/op/applied" + "github.com/m3db/m3metrics/policy" +) + +// Metadata represents the metadata associated with a metric. +type Metadata struct { + // List of aggregation types. + AggregationID aggregation.ID + + // List of storage policies. + StoragePolicies []policy.StoragePolicy + + // Pipeline of operations that may be applied to the metric. + Pipeline applied.Pipeline +} + +// IsDefault returns whether this is the default metadata. +func (m Metadata) IsDefault() bool { + return m.AggregationID.IsDefault() && + policy.IsDefaultStoragePolicies(m.StoragePolicies) && + m.Pipeline.IsEmpty() +} + +// ForwardMetadata represents the metadata information associated with forwarded metrics. +type ForwardMetadata struct { + // List of aggregation types. + AggregationID aggregation.ID + + // Storage policy. + StoragePolicy policy.StoragePolicy + + // Pipeline of operations that may be applied to the metric. + Pipeline applied.Pipeline +} + +// StagedMetadata represents metadata with a staged cutover time. +type StagedMetadata struct { + Metadata + + // Cutover is when the metadata is applicable. + CutoverNanos int64 + + // Tombstoned determines whether the associated metric has been tombstoned. + Tombstoned bool +} + +// StagedMetadatas contains a list of staged metadatas. +type StagedMetadatas []StagedMetadatas + +// IsDefault determines whether the list of staged metadata is a default list. +func (sms StagedMetadatas) IsDefault() bool { + return len(sms) == 1 && sms[0].IsDefault() +} diff --git a/op/applied/type.go b/op/applied/type.go new file mode 100644 index 0000000..084b801 --- /dev/null +++ b/op/applied/type.go @@ -0,0 +1,95 @@ +// Copyright (c) 2018 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package applied + +import ( + "bytes" + "fmt" + + "github.com/m3db/m3metrics/aggregation" + "github.com/m3db/m3metrics/op" +) + +// Rollup captures the rollup metadata after the operation is applied against a metric ID. +type Rollup struct { + // Metric ID generated as a result of the rollup. + ID []byte + // Type of aggregation performed within each unique dimension combination. + AggregationType aggregation.Type +} + +func (op Rollup) String() string { + var b bytes.Buffer + b.WriteString("{") + fmt.Fprintf(&b, "id: %s, ", op.ID) + fmt.Fprintf(&b, "aggregation: %v", op.AggregationType) + b.WriteString("}") + return b.String() +} + +// Union is a union of different types of operation. +type Union struct { + Type op.Type + Aggregation op.Aggregation + Transformation op.Transformation + Rollup Rollup +} + +func (u Union) String() string { + var b bytes.Buffer + b.WriteString("{") + switch u.Type { + case op.AggregationType: + fmt.Fprintf(&b, "aggregation: %s", u.Aggregation.String()) + case op.TransformationType: + fmt.Fprintf(&b, "transformation: %s", u.Transformation.String()) + case op.RollupType: + fmt.Fprintf(&b, "rollup: %s", u.Rollup.String()) + default: + fmt.Fprintf(&b, "unknown op type: %v", u.Type) + } + b.WriteString("}") + return b.String() +} + +// Pipeline is a pipeline of operations. +type Pipeline struct { + // a list of pipeline operations. + Operations []Union +} + +// IsEmpty determines whether a pipeline is empty. +func (p Pipeline) IsEmpty() bool { + return len(p.Operations) == 0 +} + +func (p Pipeline) String() string { + var b bytes.Buffer + b.WriteString("{operations: [") + for i, op := range p.Operations { + b.WriteString(op.String()) + if i < len(p.Operations)-1 { + b.WriteString(", ") + } + } + b.WriteString("]}") + return b.String() +} diff --git a/policy/storage_policy.go b/policy/storage_policy.go index 70b5a95..1170812 100644 --- a/policy/storage_policy.go +++ b/policy/storage_policy.go @@ -148,3 +148,9 @@ func MustParseStoragePolicy(str string) StoragePolicy { } return sp } + +// IsDefaultStoragePolicies returns whether a list of storage policies are considered +// as default storage policies. +func IsDefaultStoragePolicies(policies []StoragePolicy) bool { + return len(policies) == 0 +}