move counting sublabel definition to the topologies

This commit is contained in:
Paul Bellamy
2016-04-20 10:56:57 +01:00
parent 4ad1ae80df
commit 4bd3832219
6 changed files with 94 additions and 52 deletions

View File

@@ -30,13 +30,7 @@ type MetadataTemplate struct {
// Copy returns a value-copy of the template
func (t MetadataTemplate) Copy() MetadataTemplate {
return MetadataTemplate{
ID: t.ID,
Label: t.Label,
Truncate: t.Truncate,
Priority: t.Priority,
From: t.From,
}
return t
}
// MetadataRows returns the rows for a node

View File

@@ -103,19 +103,39 @@ type Report struct {
// MakeReport makes a clean report, ready to Merge() other reports into.
func MakeReport() Report {
return Report{
Endpoint: MakeTopology(),
Process: MakeTopology().WithShape(Square),
Container: MakeTopology().WithShape(Hexagon),
ContainerImage: MakeTopology().WithShape(Hexagon),
Host: MakeTopology().WithShape(Circle),
Pod: MakeTopology().WithShape(Heptagon),
Service: MakeTopology().WithShape(Heptagon),
Overlay: MakeTopology(),
Sampling: Sampling{},
Window: 0,
Plugins: xfer.MakePluginSpecs(),
ID: fmt.Sprintf("%d", rand.Int63()),
Probes: Probes{},
Endpoint: MakeTopology(),
Process: MakeTopology().
WithShape(Square).
WithLabel("process", "processes"),
Container: MakeTopology().
WithShape(Hexagon).
WithLabel("container", "containers"),
ContainerImage: MakeTopology().
WithShape(Hexagon).
WithLabel("image", "images"),
Host: MakeTopology().
WithShape(Circle).
WithLabel("host", "hosts"),
Pod: MakeTopology().
WithShape(Heptagon).
WithLabel("pod", "pods"),
Service: MakeTopology().
WithShape(Heptagon).
WithLabel("service", "services"),
Overlay: MakeTopology(),
Sampling: Sampling{},
Window: 0,
Plugins: xfer.MakePluginSpecs(),
ID: fmt.Sprintf("%d", rand.Int63()),
Probes: Probes{},
}
}

View File

@@ -60,13 +60,9 @@ type TableTemplate struct {
Prefix string `json:"prefix"`
}
// Copy returns a copy of the TableTemplate
// Copy returns a value-copy of the TableTemplate
func (t TableTemplate) Copy() TableTemplate {
return TableTemplate{
ID: t.ID,
Label: t.Label,
Prefix: t.Prefix,
}
return t
}
// Merge other into t, returning a fresh copy. Does fieldwise max -

View File

@@ -11,6 +11,8 @@ import (
// in the Node struct.
type Topology struct {
Shape string `json:"shape,omitempty"`
Label string `json:"label,omitempty"`
LabelPlural string `json:"label_plural,omitempty"`
Nodes `json:"nodes"`
Controls `json:"controls,omitempty"`
MetadataTemplates `json:"metadata_templates,omitempty"`
@@ -21,7 +23,6 @@ type Topology struct {
// MakeTopology gives you a Topology.
func MakeTopology() Topology {
return Topology{
Shape: Circle,
Nodes: map[string]Node{},
Controls: Controls{},
}
@@ -32,6 +33,8 @@ func MakeTopology() Topology {
func (t Topology) WithMetadataTemplates(other MetadataTemplates) Topology {
return Topology{
Shape: t.Shape,
Label: t.Label,
LabelPlural: t.LabelPlural,
Nodes: t.Nodes.Copy(),
Controls: t.Controls.Copy(),
MetadataTemplates: t.MetadataTemplates.Merge(other),
@@ -45,6 +48,8 @@ func (t Topology) WithMetadataTemplates(other MetadataTemplates) Topology {
func (t Topology) WithMetricTemplates(other MetricTemplates) Topology {
return Topology{
Shape: t.Shape,
Label: t.Label,
LabelPlural: t.LabelPlural,
Nodes: t.Nodes.Copy(),
Controls: t.Controls.Copy(),
MetadataTemplates: t.MetadataTemplates.Copy(),
@@ -58,6 +63,8 @@ func (t Topology) WithMetricTemplates(other MetricTemplates) Topology {
func (t Topology) WithTableTemplates(other TableTemplates) Topology {
return Topology{
Shape: t.Shape,
Label: t.Label,
LabelPlural: t.LabelPlural,
Nodes: t.Nodes.Copy(),
Controls: t.Controls.Copy(),
MetadataTemplates: t.MetadataTemplates.Copy(),
@@ -66,10 +73,26 @@ func (t Topology) WithTableTemplates(other TableTemplates) Topology {
}
}
// WithShape sets the shape nodes of this topology, returning a new topology.
// WithShape sets the shape of nodes from this topology, returning a new topology.
func (t Topology) WithShape(shape string) Topology {
return Topology{
Shape: shape,
Label: t.Label,
LabelPlural: t.LabelPlural,
Nodes: t.Nodes.Copy(),
Controls: t.Controls.Copy(),
MetadataTemplates: t.MetadataTemplates.Copy(),
MetricTemplates: t.MetricTemplates.Copy(),
TableTemplates: t.TableTemplates.Copy(),
}
}
// WithLabel sets the label terminology of this topology, returning a new topology.
func (t Topology) WithLabel(label, labelPlural string) Topology {
return Topology{
Shape: t.Shape,
Label: label,
LabelPlural: labelPlural,
Nodes: t.Nodes.Copy(),
Controls: t.Controls.Copy(),
MetadataTemplates: t.MetadataTemplates.Copy(),
@@ -91,10 +114,20 @@ func (t Topology) AddNode(node Node) Topology {
return t
}
// GetShape returns the current topology shape, or the default if there isn't one.
func (t Topology) GetShape() string {
if t.Shape == "" {
return Circle
}
return t.Shape
}
// Copy returns a value copy of the Topology.
func (t Topology) Copy() Topology {
return Topology{
Shape: t.Shape,
Label: t.Label,
LabelPlural: t.LabelPlural,
Nodes: t.Nodes.Copy(),
Controls: t.Controls.Copy(),
MetadataTemplates: t.MetadataTemplates.Copy(),
@@ -107,12 +140,17 @@ func (t Topology) Copy() Topology {
// The original is not modified.
func (t Topology) Merge(other Topology) Topology {
shape := t.Shape
// A circle is the lowliest shape.
if shape == Circle {
if shape == "" {
shape = other.Shape
}
label, labelPlural := t.Label, t.LabelPlural
if label == "" {
label, labelPlural = other.Label, other.LabelPlural
}
return Topology{
Shape: t.Shape,
Shape: shape,
Label: label,
LabelPlural: labelPlural,
Nodes: t.Nodes.Merge(other.Nodes),
Controls: t.Controls.Merge(other.Controls),
MetadataTemplates: t.MetadataTemplates.Merge(other.MetadataTemplates),