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

Commit

Permalink
Define protobuf messages for policies and rules and add rule matching…
Browse files Browse the repository at this point in the history
… logic
  • Loading branch information
xichen2020 committed Jan 23, 2017
1 parent ffa77a9 commit 2b9cb7b
Show file tree
Hide file tree
Showing 16 changed files with 1,580 additions and 41 deletions.
42 changes: 42 additions & 0 deletions .ci/auto-gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
. "$(dirname $0)/variables.sh"

autogen_clear() {
DIR="$1"

rm -f ${DIR}/*
}

autogen_cleanup() {
DIR="$1"

FILES=${DIR}/*.go
for FILE in $(ls $FILES);
do
add_license $FILE $DIR
done
}

add_license() {
FILE="$1"
DIR="$2"

# Add uber license
PREV_PWD=$(pwd)
cd $DIR
$LICENSE_BIN --silent --file $(basename $FILE)
cd $PREV_PWD
}

if [ $# -ne 2 ] || [ -z "$1" ] || [ -z "$2" ]; then
echo "usage: auto-gen.sh output_directory file_generation_rules_directory"
exit 1
fi

set -e

. "$(dirname $0)/variables.sh"

autogen_clear $1
go generate $PACKAGE/$2
autogen_cleanup $1
1 change: 1 addition & 0 deletions .ci/uber-licence
Submodule uber-licence added at e35b7f
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ lint_check := .ci/lint.sh
m3metrics_package := github.com/m3db/m3metrics
gopath_prefix := $(GOPATH)/src
vendor_prefix := vendor
license_dir := .ci/uber-licence
license_node_modules := $(license_dir)/node_modules
auto_gen := .ci/auto-gen.sh
protoc_go_package := github.com/golang/protobuf/protoc-gen-go
proto_output_dir := generated/proto/schema
proto_rules_dir := generated/proto

BUILD := $(abspath ./bin)
LINUX_AMD64_ENV := GOOS=linux GOARCH=amd64 CGO_ENABLED=0
Expand All @@ -22,8 +28,24 @@ install-vendor: install-glide
@echo Installing glide deps
glide install

install-license-bin: install-vendor
@echo Installing node modules
git submodule update --init --recursive
[ -d $(license_node_modules) ] || (cd $(license_dir) && npm install)

install-proto-bin: install-vendor
@echo Installing protobuf binaries
@echo Note: the protobuf compiler v3.0.0 can be downloaded from https://github.com/google/protobuf/releases or built from source at https://github.com/google/protobuf.
go install $(m3metrics_package)/$(vendor_prefix)/$(protoc_go_package)

install-glide:
@which glide > /dev/null || go get -u github.com/Masterminds/glide
@which glide > /dev/null || go get -u github.com/Masterminds/glide && cd $(GOPATH)/src/github.com/Masterminds/glide && git checkout v0.12.3 && go install

proto-gen: install-proto-bin install-license-bin
@echo Generating protobuf files
$(auto_gen) $(proto_output_dir) $(proto_rules_dir)

all-gen: proto-gen

lint:
@which golint > /dev/null || go get -u github.com/golang/lint/golint
Expand Down
42 changes: 2 additions & 40 deletions policy/types.go → generated/proto/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package policy
//go:generate sh -c "protoc -I$GOPATH/src/$PACKAGE/generated/proto --go_out=$GOPATH/src/$PACKAGE/generated/proto/schema $GOPATH/src/$PACKAGE/generated/proto/*.proto"

import (
"time"

"github.com/m3db/m3x/time"
)

// Resolution is the sampling resolution for datapoints
type Resolution struct {
// Window is the bucket size represented by the resolution
Window time.Duration

// Precision is the precision of datapoints stored at this resoluion
Precision xtime.Unit
}

// Retention is the retention period for datapoints
type Retention time.Duration

// Policy represents the resolution and retention period metric datapoints
// are stored at
type Policy struct {
// Resolution is the resolution datapoints are stored at
Resolution Resolution

// Retention is the period datatpoints are retained for
Retention Retention
}

// VersionedPolicies represent a list of policies at a specified version
type VersionedPolicies struct {
// Version is the version of the policies
Version int

// Cutover is when the policies take effect
Cutover time.Time

// Policies represent the list of policies
Policies []Policy
}
package proto
16 changes: 16 additions & 0 deletions generated/proto/policy.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";
package schema;

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

message Retention {
int64 period = 1;
}

message Policy {
Resolution resolution = 1;
Retention retention = 2;
}
30 changes: 30 additions & 0 deletions generated/proto/rule.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";
package schema;

import "policy.proto";

message MappingRule {
map<string,string> tag_filters = 1;
repeated Policy policies = 2;
}

message RollupTarget {
string name = 1;
repeated string tags = 2;
repeated Policy policies = 3;
}

message RollupRule {
map<string,string> tag_filters = 1;
repeated RollupTarget targets = 2;
}

message RuleSet {
string namespace = 1;
int64 created_at = 2;
int64 last_updated_at = 3;
int32 version = 4;
int64 cutover = 5;
repeated MappingRule mapping_rules = 6;
repeated RollupRule rollup_rules = 7;
}
123 changes: 123 additions & 0 deletions generated/proto/schema/policy.pb.go

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

Loading

0 comments on commit 2b9cb7b

Please sign in to comment.