This repository has been archived by the owner on Oct 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store change history in each version
- Loading branch information
1 parent
72e97c2
commit 7911f17
Showing
10 changed files
with
789 additions
and
531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// 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 rules | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/m3db/m3metrics/generated/proto/schema" | ||
) | ||
|
||
var ( | ||
emptyNamespace Namespace | ||
emptyNamespaces Namespaces | ||
|
||
errNilNamespaceSchema = errors.New("nil namespace schema") | ||
errNilNamespacesSchema = errors.New("nil namespaces schema") | ||
) | ||
|
||
// Namespace is a logical isolation unit for which rules are defined. | ||
type Namespace struct { | ||
name string | ||
tombstoned bool | ||
expireAtNs int64 | ||
} | ||
|
||
// newNameSpace creates a new namespace. | ||
func newNameSpace(namespace *schema.Namespace) (Namespace, error) { | ||
if namespace == nil { | ||
return emptyNamespace, errNilNamespaceSchema | ||
} | ||
return Namespace{ | ||
name: namespace.Name, | ||
tombstoned: namespace.Tombstoned, | ||
expireAtNs: namespace.ExpireAt, | ||
}, nil | ||
} | ||
|
||
// Name is the name of the namespace. | ||
func (n *Namespace) Name() string { return n.name } | ||
|
||
// Tombstoned determines whether the namespace has been tombstoned. | ||
func (n *Namespace) Tombstoned() bool { return n.tombstoned } | ||
|
||
// ExpireAtNs determines when the namespace will be expired. | ||
func (n *Namespace) ExpireAtNs() int64 { return n.expireAtNs } | ||
|
||
// Namespaces store the list of namespaces for which rules are defined. | ||
type Namespaces struct { | ||
version int | ||
namespaces []Namespace | ||
} | ||
|
||
// NewNamespaces creates new namespaces. | ||
func NewNamespaces(version int, namespaces *schema.Namespaces) (Namespaces, error) { | ||
if namespaces == nil { | ||
return emptyNamespaces, errNilNamespacesSchema | ||
} | ||
nss := make([]Namespace, 0, len(namespaces.Namespaces)) | ||
for _, namespace := range namespaces.Namespaces { | ||
ns, err := newNameSpace(namespace) | ||
if err != nil { | ||
return emptyNamespaces, err | ||
} | ||
nss = append(nss, ns) | ||
} | ||
return Namespaces{ | ||
version: version, | ||
namespaces: nss, | ||
}, nil | ||
} | ||
|
||
// Namespaces returns the list of namespaces. | ||
func (nss Namespaces) Namespaces() []Namespace { return nss.namespaces } | ||
|
||
// Version returns the namespaces version. | ||
func (nss Namespaces) Version() int { return nss.version } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// 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 rules | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/m3db/m3metrics/policy" | ||
) | ||
|
||
// rollupResult contains the rollup metric id and the associated policies. | ||
type rollupResult struct { | ||
ID []byte | ||
Policies []policy.Policy | ||
} | ||
|
||
// MatchResult represents a match result. | ||
type MatchResult struct { | ||
version int | ||
cutoverNs int64 | ||
expireAtNs int64 | ||
mappings []policy.Policy | ||
rollups []rollupResult | ||
} | ||
|
||
// newMatchResult creates a new match result. | ||
func newMatchResult( | ||
version int, | ||
cutoverNs int64, | ||
expireAtNs int64, | ||
mappings []policy.Policy, | ||
rollups []rollupResult, | ||
) MatchResult { | ||
return MatchResult{ | ||
version: version, | ||
cutoverNs: cutoverNs, | ||
expireAtNs: expireAtNs, | ||
mappings: mappings, | ||
rollups: rollups, | ||
} | ||
} | ||
|
||
// HasExpired returns whether the match result has expired for a given time. | ||
func (r *MatchResult) HasExpired(t time.Time) bool { return r.expireAtNs >= t.UnixNano() } | ||
|
||
// NumRollups returns the number of rollup result associated with the given id. | ||
func (r *MatchResult) NumRollups() int { return len(r.rollups) } | ||
|
||
// Mappings returns the mapping policies for the given id. | ||
func (r *MatchResult) Mappings() policy.VersionedPolicies { | ||
return r.versionedPolicies(r.mappings) | ||
} | ||
|
||
// Rollups returns the rollup metric id and corresponding policies at a given index. | ||
func (r *MatchResult) Rollups(idx int) ([]byte, policy.VersionedPolicies) { | ||
rollup := r.rollups[idx] | ||
return rollup.ID, r.versionedPolicies(rollup.Policies) | ||
} | ||
|
||
// TODO(xichen): change versioned policies to use int64 instead. | ||
func (r *MatchResult) versionedPolicies(policies []policy.Policy) policy.VersionedPolicies { | ||
// NB(xichen): if there are no policies for this id, we fall | ||
// back to the default mapping policies. | ||
if len(policies) == 0 { | ||
return policy.DefaultVersionedPolicies(r.version, time.Unix(0, r.cutoverNs)) | ||
} | ||
return policy.CustomVersionedPolicies(r.version, time.Unix(0, r.cutoverNs), policies) | ||
} |
Oops, something went wrong.