Skip to content

Commit

Permalink
Merge pull request #3678 from weaveworks/nodes-omitempty
Browse files Browse the repository at this point in the history
perf(probe): add 'omitempty' tag to Topology.Nodes
  • Loading branch information
bboreham authored Sep 17, 2019
2 parents c143099 + 4c52889 commit a811afd
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 17 deletions.
10 changes: 1 addition & 9 deletions probe/appclient/app_client_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"reflect"
"strings"
"testing"
"time"
Expand All @@ -16,6 +15,7 @@ import (
"github.com/weaveworks/common/test"
"github.com/weaveworks/scope/common/xfer"
"github.com/weaveworks/scope/report"
"github.com/weaveworks/scope/test/reflect"
)

func dummyServer(t *testing.T, expectedToken, expectedID string, expectedVersion string, expectedReport report.Report, done chan struct{}) *httptest.Server {
Expand Down Expand Up @@ -70,14 +70,6 @@ func TestAppClientPublish(t *testing.T) {
done = make(chan struct{}, 10)
)

// marshalling->unmarshaling is not idempotent due to `json:"omitempty"`
// tags, transforming empty slices into nils. So, we make DeepEqual
// happy by setting empty `json:"omitempty"` entries to nil
rpt.WalkTopologies(func(to *report.Topology) {
*to = report.MakeTopology()
to.Controls = nil
})

s := dummyServer(t, token, id, version, rpt, done)
defer s.Close()

Expand Down
7 changes: 0 additions & 7 deletions probe/probe_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ func TestProbe(t *testing.T) {
want := report.MakeReport()
node := report.MakeNodeWith("a", map[string]string{"b": "c"})

// marshalling->unmarshaling is not idempotent due to `json:"omitempty"`
// tags, transforming empty slices into nils. So, we make DeepEqual
// happy by setting empty `json:"omitempty"` entries to nil
node.Metrics = nil
want.WalkTopologies(func(t *report.Topology) {
t.Controls = nil
})
want.Endpoint.AddNode(node)

pub := mockPublisher{make(chan report.Report, 10)}
Expand Down
2 changes: 1 addition & 1 deletion report/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Topology struct {
Tag string `json:"tag,omitempty"`
Label string `json:"label,omitempty"`
LabelPlural string `json:"label_plural,omitempty"`
Nodes Nodes `json:"nodes"`
Nodes Nodes `json:"nodes,omitempty" deepequal:"nil==empty"`
Controls Controls `json:"controls,omitempty" deepequal:"nil==empty"`
MetadataTemplates MetadataTemplates `json:"metadata_templates,omitempty"`
MetricTemplates MetricTemplates `json:"metric_templates,omitempty"`
Expand Down

0 comments on commit a811afd

Please sign in to comment.