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

Commit

Permalink
Add metric metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 committed Mar 20, 2018
1 parent c75cf3b commit 872e871
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 0 deletions.
77 changes: 77 additions & 0 deletions metadata/metadata.go
Original file line number Diff line number Diff line change
@@ -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()
}
95 changes: 95 additions & 0 deletions op/applied/type.go
Original file line number Diff line number Diff line change
@@ -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()
}
6 changes: 6 additions & 0 deletions policy/storage_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 872e871

Please sign in to comment.