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

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Wang committed May 25, 2017
1 parent 3c14edc commit 27264bf
Show file tree
Hide file tree
Showing 38 changed files with 2,313 additions and 856 deletions.
1 change: 1 addition & 0 deletions .excludelint
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(vendor/)
(generated/)
(_mock.go)
(_string.go)
33 changes: 28 additions & 5 deletions generated/proto/policy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,38 @@ syntax = "proto3";
package schema;

message Resolution {
int64 window_size = 1;
int64 precision = 2;
int64 window_size = 1;
int64 precision = 2;
}

message Retention {
int64 period = 1;
int64 period = 1;
}

message StoragePolicy {
Resolution resolution = 1;
Retention retention = 2;
}

message Policy {
Resolution resolution = 1;
Retention retention = 2;
StoragePolicy storage_policy = 1;
repeated AggregationType aggregation_types = 2;
}

enum AggregationType {
UNKNOWN = 0;
LAST = 1;
LOWER = 2;
UPPER = 3;
MEAN = 4;
MEDIAN = 5;
COUNT = 6;
SUM = 7;
SUMSQ = 8;
STDEV = 9;
P50 = 10;
P95 = 11;
P99 = 12;
P999 = 13;
P9999 = 14;
}
1 change: 1 addition & 0 deletions generated/proto/schema/namespace.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 111 additions & 20 deletions generated/proto/schema/policy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ testImport:
version: d77da356e56a7428ad25149ca77381849a6a5232
subpackages:
- require
- package: github.com/cw9/bitset
version: d79da395ef228e37d81befaf8c71827ab0cb2275
8 changes: 4 additions & 4 deletions metric/aggregated/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ type RawMetric interface {
// MetricWithPolicy is a metric with applicable policy.
type MetricWithPolicy struct {
Metric
policy.Policy
policy.StoragePolicy
}

// String is the string representation of a metric with policy.
func (mp MetricWithPolicy) String() string {
return fmt.Sprintf("{metric:%s,policy:%s}", mp.Metric.String(), mp.Policy.String())
return fmt.Sprintf("{metric:%s,policy:%s}", mp.Metric.String(), mp.StoragePolicy.String())
}

// ChunkedMetricWithPolicy is a chunked metric with applicable policy.
type ChunkedMetricWithPolicy struct {
ChunkedMetric
policy.Policy
policy.StoragePolicy
}

// RawMetricWithPolicy is a raw metric with applicable policy.
type RawMetricWithPolicy struct {
RawMetric
policy.Policy
policy.StoragePolicy
}
105 changes: 105 additions & 0 deletions policy/aggregation_id_compress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) 2017 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 policy

import (
"fmt"

"github.com/cw9/bitset"
)

// AggregationIDCompressor can compress AggregationTypes into an AggregationID.
type AggregationIDCompressor interface {
Compress(aggTypes AggregationTypes) (AggregationID, error)
}

// AggregationIDDecompressor can decompress AggregationID.
type AggregationIDDecompressor interface {
// Decompress decompresses aggregation types,
// returns error if any invalid aggregation type is encountered.
Decompress(compressed AggregationID) (AggregationTypes, error)
}

type aggregationIDCompressor struct {
bs *bitset.BitSet
}

// NewAggregationTypeCompressor returns a new AggregationTypeCompressor.
func NewAggregationTypeCompressor() AggregationIDCompressor {
// NB(cw): If we start to support more than 64 types, the library will
// expand the underlying word list itself.
return &aggregationIDCompressor{
bs: bitset.New(totalAggregationTypes),
}
}

func (c *aggregationIDCompressor) Compress(aggTypes AggregationTypes) (AggregationID, error) {
c.bs.ClearAll()
for _, aggType := range aggTypes {
if !aggType.IsValid() {
return DefaultAggregationID, fmt.Errorf("could not compress invalid AggregationType %v", aggType)
}
c.bs.Set(uint(aggType))
}
codes := c.bs.Bytes()
var id AggregationID
for i := 0; i < AggregationIDLen; i++ {
id[i] = codes[i]
}
return id, nil
}

type aggregationIDDecompressor struct {
bs *bitset.BitSet
buf []uint64
res []AggregationType
}

// NewAggregationTypeDecompressor returns a new AggregationTypeDecompressor.
func NewAggregationTypeDecompressor() AggregationIDDecompressor {
bs := bitset.New(totalAggregationTypes)
return &aggregationIDDecompressor{
bs: bs,
buf: bs.Bytes(),
res: make([]AggregationType, 0, totalAggregationTypes),
}
}

func (c *aggregationIDDecompressor) Decompress(id AggregationID) (AggregationTypes, error) {
for i := range id {
c.buf[i] = id[i]
}

c.bs.Reset(c.buf)

c.res = c.res[:0]
for i, e := c.bs.NextSet(0); e; i, e = c.bs.NextSet(i + 1) {
aggType := AggregationType(i)
if !aggType.IsValid() {
return DefaultAggregationTypes, fmt.Errorf("invalid AggregationType: %s", aggType.String())
}
c.res = append(c.res, aggType)
}

res := make(AggregationTypes, len(c.res))
copy(res, c.res)
return res, nil
}
Loading

0 comments on commit 27264bf

Please sign in to comment.