Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

add mmv version 2 support #24

Merged
merged 22 commits into from Aug 6, 2016
Commits
Jump to file or symbol
Failed to load files and symbols.
+49 −19
Split
Viewing a subset of changes. View all
View
@@ -165,6 +165,11 @@ func (c *PCPClient) initializeInstanceAndInstanceDomainOffsets(instanceoffset, i
for _, i := range indom.instances {
i.offset = instanceoffset
instanceoffset += InstanceLength
+
+ if c.r.version2 {
+ i.name.offset = *stringsoffset
+ *stringsoffset += StringLength
+ }
}
if indom.shortDescription.val != "" {
@@ -367,7 +372,17 @@ func (c *PCPClient) writeInstanceAndInstanceDomainBlock() {
c.buffer.MustWriteInt64(int64(indom.offset))
c.buffer.MustWriteInt32(0)
c.buffer.MustWriteUint32(i.id)
- c.buffer.MustWriteString(i.name)
+
+ if c.r.version2 {
+ c.buffer.MustWriteUint64(uint64(i.name.offset))
+
+ pos := c.buffer.Pos()
+ c.buffer.MustSetPos(i.name.offset)
+ c.buffer.MustWriteString(i.name.val)
+ c.buffer.MustSetPos(pos)
+ } else {
+ c.buffer.MustWriteString(i.name.val)
+ }
}
}
}
View
@@ -366,8 +366,8 @@ func matchInstance(i *mmvdump.Instance, pi *pcpInstance, id *PCPInstanceDomain,
t.Errorf("expected indom offset to be %d, got %d", i.Indom, id.offset)
}
- if in := i.External[:len(pi.name)]; pi.name != string(in) {
- t.Errorf("expected instance name to be %v, got %v", pi.name, in)
+ if in := i.External[:len(pi.name.val)]; pi.name.val != string(in) {
+ t.Errorf("expected instance name to be %v, got %v", pi.name.val, in)
}
}
View
@@ -5,7 +5,7 @@ type Instances map[string]interface{}
// pcpInstance wraps a PCP compatible Instance
type pcpInstance struct {
- name string
+ name *pcpString
id uint32
offset int
}
@@ -17,10 +17,10 @@ type pcpInstance struct {
// but instead added using the AddInstance method of InstanceDomain
func newpcpInstance(name string) *pcpInstance {
return &pcpInstance{
- name, hash(name, 0), 0,
+ newpcpString(name), hash(name, 0), 0,
}
}
func (i *pcpInstance) String() string {
- return "Instance: " + i.name
+ return "Instance: " + i.name.val
}
View
@@ -1,6 +1,9 @@
package speed
-import "errors"
+import (
+ "errors"
+ "fmt"
+)
// InstanceDomain defines the interface for an instance domain
type InstanceDomain interface {
@@ -9,6 +12,7 @@ type InstanceDomain interface {
Description() string // description for the instance domain
HasInstance(name string) bool // checks if an instance is in the indom
InstanceCount() int // returns the number of instances in the indom
+ Instances() []string // returns a slice of instances in the instance domain
}
// PCPInstanceDomainBitLength is the maximum bit length of a PCP Instance Domain
@@ -52,6 +56,10 @@ func NewPCPInstanceDomain(name string, instances []string, desc ...string) (*PCP
imap := make(map[string]*pcpInstance)
for _, instance := range instances {
+ if len(instance) > StringLength {
+ return nil, fmt.Errorf("instance name %v is too long", instance)
+ }
+
imap[instance] = newpcpInstance(instance)
}
@@ -81,6 +89,15 @@ func (indom *PCPInstanceDomain) InstanceCount() int {
return len(indom.instances)
}
+// Instances returns a slice of defined instances for the instance domain
+func (indom *PCPInstanceDomain) Instances() []string {
+ var ans []string
+ for k := range indom.instances {
+ ans = append(ans, k)
+ }
+ return ans
+}
+
// MatchInstances returns true if the passed InstanceDomain
// has exactly the same instances as the passed array
func (indom *PCPInstanceDomain) MatchInstances(ins []string) bool {
@@ -107,13 +124,5 @@ func (indom *PCPInstanceDomain) Description() string {
}
func (indom *PCPInstanceDomain) String() string {
- s := "InstanceDomain: " + indom.name
- if len(indom.instances) > 0 {
- s += "["
- for _, i := range indom.instances {
- s += i.name + ","
- }
- s += "]"
- }
- return s
+ return fmt.Sprintf("%s%v", indom.name, indom.Instances())
}
View
2 pcp.go
@@ -11,5 +11,3 @@ type pcpString struct {
func newpcpString(s string) *pcpString {
return &pcpString{s, 0}
}
-
-func (s *pcpString) String() string { return s.val }
View
@@ -108,7 +108,7 @@ func (r *PCPRegistry) ValuesCount() int { return r.valueCount }
// StringCount returns the number of strings in the registry
func (r *PCPRegistry) StringCount() int {
if r.version2 {
- return r.stringcount + r.MetricCount()
+ return r.stringcount + r.MetricCount() + r.InstanceCount()
}
return r.stringcount
@@ -148,6 +148,14 @@ func (r *PCPRegistry) AddInstanceDomain(indom InstanceDomain) error {
r.instanceDomains[indom.Name()] = indom.(*PCPInstanceDomain)
r.instanceCount += indom.InstanceCount()
+ if !r.version2 {
+ for _, v := range indom.Instances() {
+ if len(v) > MaxV1MetricNameLength {
+ r.version2 = true
+ }
+ }
+ }
+
log.WithFields(logrus.Fields{
"prefix": "registry",
"name": indom.Name(),