From a51ebdb587d3aa84672cd6f26ab1a72f4e88b45d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Serv=C3=A9n=20Mar=C3=ADn?= Date: Tue, 11 Jun 2019 12:27:41 +0200 Subject: [PATCH] pkg/receive: rename host->node This commit renames `host` to `node` in the context of the receive hashring. This is because more often than not, the hashring will deal with endpoints rather than simply hosts and node is a more generic term for the operand of a hashring. --- pkg/receive/hashring.go | 19 ++++----- pkg/receive/hashring_test.go | 80 ++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 50 deletions(-) diff --git a/pkg/receive/hashring.go b/pkg/receive/hashring.go index 1ca1c187ead..11ab56040d3 100644 --- a/pkg/receive/hashring.go +++ b/pkg/receive/hashring.go @@ -13,11 +13,10 @@ import ( const sep = '\xff' -// Hashring finds the correct host to handle a given time series // for a specified tenant. -// It returns the hostname and any error encountered. +// It returns the node and any error encountered. type Hashring interface { - GetHost(tenant string, timeSeries *prompb.TimeSeries) (string, error) + Get(tenant string, timeSeries *prompb.TimeSeries) (string, error) } // Matcher determines whether or tenant matches a hashring. @@ -71,8 +70,8 @@ type simpleHashring struct { targetgroup.Group } -// GetHost returns a hostname to handle the given tenant and time series. -func (s *simpleHashring) GetHost(tenant string, ts *prompb.TimeSeries) (string, error) { +// Get returns a target to handle the given tenant and time series. +func (s *simpleHashring) Get(tenant string, ts *prompb.TimeSeries) (string, error) { // Always return nil here to implement the Hashring interface. return string(s.Targets[hash(tenant, ts)%uint64(len(s.Targets))][model.AddressLabel]), nil } @@ -85,18 +84,18 @@ type matchingHashring struct { matcher Matcher } -// GetHost returns a hostname to handle the given tenant and time series. -func (m matchingHashring) GetHost(tenant string, ts *prompb.TimeSeries) (string, error) { +// Get returns a target to handle the given tenant and time series. +func (m matchingHashring) Get(tenant string, ts *prompb.TimeSeries) (string, error) { if h, ok := m.cache[tenant]; ok { - return h.GetHost(tenant, ts) + return h.Get(tenant, ts) } for name := range m.hashrings { if m.matcher.Match(tenant, name) { m.cache[tenant] = m.hashrings[name] - return m.hashrings[name].GetHost(tenant, ts) + return m.hashrings[name].Get(tenant, ts) } } - return "", errors.New("no matching hosts to handle tenant") + return "", errors.New("no matching hashring to handle tenant") } // NewHashring creates a multi-tenant hashring for a given slice of diff --git a/pkg/receive/hashring_test.go b/pkg/receive/hashring_test.go index a3f2fad1a6d..9f5edddb8be 100644 --- a/pkg/receive/hashring_test.go +++ b/pkg/receive/hashring_test.go @@ -31,7 +31,7 @@ func TestHash(t *testing.T) { } } -func TestGetHost(t *testing.T) { +func TestHashringGet(t *testing.T) { ts := &prompb.TimeSeries{ Labels: []prompb.Label{ { @@ -48,7 +48,7 @@ func TestGetHost(t *testing.T) { for _, tc := range []struct { name string cfg []*targetgroup.Group - hosts map[string]struct{} + nodes map[string]struct{} tenant string }{ { @@ -62,12 +62,12 @@ func TestGetHost(t *testing.T) { { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host1", + model.AddressLabel: "node1", }, }, }, }, - hosts: map[string]struct{}{"host1": struct{}{}}, + nodes: map[string]struct{}{"node1": struct{}{}}, }, { name: "specific", @@ -75,7 +75,7 @@ func TestGetHost(t *testing.T) { { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host1", + model.AddressLabel: "node1", }, }, Source: "", @@ -83,13 +83,13 @@ func TestGetHost(t *testing.T) { { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host2", + model.AddressLabel: "node2", }, }, Source: "tenant1", }, }, - hosts: map[string]struct{}{"host2": struct{}{}}, + nodes: map[string]struct{}{"node2": struct{}{}}, tenant: "tenant1", }, { @@ -98,7 +98,7 @@ func TestGetHost(t *testing.T) { { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host1", + model.AddressLabel: "node1", }, }, Source: "tenant1", @@ -106,7 +106,7 @@ func TestGetHost(t *testing.T) { { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host2", + model.AddressLabel: "node2", }, }, Source: "tenant2", @@ -114,13 +114,13 @@ func TestGetHost(t *testing.T) { { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host3", + model.AddressLabel: "node3", }, }, Source: "tenant3", }, }, - hosts: map[string]struct{}{"host1": struct{}{}}, + nodes: map[string]struct{}{"node1": struct{}{}}, tenant: "tenant1", }, { @@ -129,7 +129,7 @@ func TestGetHost(t *testing.T) { { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host1", + model.AddressLabel: "node1", }, }, Source: "tenant1", @@ -137,7 +137,7 @@ func TestGetHost(t *testing.T) { { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host2", + model.AddressLabel: "node2", }, }, Source: "tenant2", @@ -145,7 +145,7 @@ func TestGetHost(t *testing.T) { { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host3", + model.AddressLabel: "node3", }, }, Source: "tenant3", @@ -154,18 +154,18 @@ func TestGetHost(t *testing.T) { tenant: "tenant4", }, { - name: "many hosts", + name: "many nodes", cfg: []*targetgroup.Group{ { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host1", + model.AddressLabel: "node1", }, model.LabelSet{ - model.AddressLabel: "host2", + model.AddressLabel: "node2", }, model.LabelSet{ - model.AddressLabel: "host3", + model.AddressLabel: "node3", }, }, Source: "tenant1", @@ -173,38 +173,38 @@ func TestGetHost(t *testing.T) { { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host4", + model.AddressLabel: "node4", }, model.LabelSet{ - model.AddressLabel: "host5", + model.AddressLabel: "node5", }, model.LabelSet{ - model.AddressLabel: "host6", + model.AddressLabel: "node6", }, }, Source: "", }, }, - hosts: map[string]struct{}{ - "host1": struct{}{}, - "host2": struct{}{}, - "host3": struct{}{}, + nodes: map[string]struct{}{ + "node1": struct{}{}, + "node2": struct{}{}, + "node3": struct{}{}, }, tenant: "tenant1", }, { - name: "many hosts 2", + name: "many nodes 2", cfg: []*targetgroup.Group{ { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host1", + model.AddressLabel: "node1", }, model.LabelSet{ - model.AddressLabel: "host2", + model.AddressLabel: "node2", }, model.LabelSet{ - model.AddressLabel: "host3", + model.AddressLabel: "node3", }, }, Source: "tenant1", @@ -212,33 +212,33 @@ func TestGetHost(t *testing.T) { { Targets: []model.LabelSet{ model.LabelSet{ - model.AddressLabel: "host4", + model.AddressLabel: "node4", }, model.LabelSet{ - model.AddressLabel: "host5", + model.AddressLabel: "node5", }, model.LabelSet{ - model.AddressLabel: "host6", + model.AddressLabel: "node6", }, }, }, }, - hosts: map[string]struct{}{ - "host4": struct{}{}, - "host5": struct{}{}, - "host6": struct{}{}, + nodes: map[string]struct{}{ + "node4": struct{}{}, + "node5": struct{}{}, + "node6": struct{}{}, }, }, } { hs := NewHashring(ExactMatcher, tc.cfg) - h, err := hs.GetHost(tc.tenant, ts) - if tc.hosts != nil { + h, err := hs.Get(tc.tenant, ts) + if tc.nodes != nil { if err != nil { t.Errorf("case %q: got unexpected error: %v", tc.name, err) continue } - if _, ok := tc.hosts[h]; !ok { - t.Errorf("case %q: got unexpected host %q", tc.name, h) + if _, ok := tc.nodes[h]; !ok { + t.Errorf("case %q: got unexpected node %q", tc.name, h) } continue }