diff --git a/retrieval/discovery/consul.go b/retrieval/discovery/consul.go index 7c7f7349b..00f388d65 100644 --- a/retrieval/discovery/consul.go +++ b/retrieval/discovery/consul.go @@ -18,6 +18,7 @@ import ( "github.com/prometheus/prometheus/retrieval/discovery/consul" ) +// NewConsul creates a new Consul based Discovery. func NewConsul(cfg *config.ConsulSDConfig) (*consul.Discovery, error) { return consul.NewDiscovery(cfg) } diff --git a/retrieval/discovery/kubernetes/discovery.go b/retrieval/discovery/kubernetes/discovery.go index fd7974f8f..4f639c50c 100644 --- a/retrieval/discovery/kubernetes/discovery.go +++ b/retrieval/discovery/kubernetes/discovery.go @@ -253,10 +253,10 @@ func (kd *Discovery) updateNode(node *Node, eventType EventType) { defer kd.nodesMu.Unlock() updatedNodeName := node.ObjectMeta.Name switch eventType { - case deleted: + case Deleted: // Deleted - remove from nodes map. delete(kd.nodes, updatedNodeName) - case added, modified: + case Added, Modified: // Added/Modified - update the node in the nodes map. kd.nodes[updatedNodeName] = node } @@ -331,7 +331,7 @@ func (kd *Discovery) watchNodes(events chan interface{}, done <-chan struct{}, r kd.nodes = map[string]*Node{} for _, node := range nodes { - events <- &nodeEvent{added, node} + events <- &nodeEvent{Added, node} } req, err := http.NewRequest("GET", nodesURL, nil) @@ -391,12 +391,12 @@ func (kd *Discovery) startServiceWatch(events chan<- interface{}, done <-chan st for oldNSName, oldNS := range existingServices { if ns, ok := services[oldNSName]; !ok { for _, service := range existingServices[oldNSName] { - events <- &serviceEvent{deleted, service} + events <- &serviceEvent{Deleted, service} } } else { for oldServiceName, oldService := range oldNS { if _, ok := ns[oldServiceName]; !ok { - events <- &serviceEvent{deleted, oldService} + events <- &serviceEvent{Deleted, oldService} } } } @@ -407,7 +407,7 @@ func (kd *Discovery) startServiceWatch(events chan<- interface{}, done <-chan st for _, ns := range services { for _, service := range ns { - events <- &serviceEvent{added, service} + events <- &serviceEvent{Added, service} } } @@ -510,9 +510,9 @@ func (kd *Discovery) updateService(service *Service, eventType EventType) *confi defer kd.servicesMu.Unlock() switch eventType { - case deleted: + case Deleted: return kd.deleteService(service) - case added, modified: + case Added, Modified: return kd.addService(service) } return nil diff --git a/retrieval/discovery/kubernetes/types.go b/retrieval/discovery/kubernetes/types.go index 52a75887e..28f5c31bf 100644 --- a/retrieval/discovery/kubernetes/types.go +++ b/retrieval/discovery/kubernetes/types.go @@ -13,12 +13,14 @@ package kubernetes +// EventType can legally only have the values defined as constants below. type EventType string +// Possible values for EventType. const ( - added EventType = "ADDED" - modified EventType = "MODIFIED" - deleted EventType = "DELETED" + Added EventType = "ADDED" + Modified EventType = "MODIFIED" + Deleted EventType = "DELETED" ) type nodeEvent struct { @@ -200,6 +202,7 @@ type NodeStatus struct { Addresses []NodeAddress `json:"addresses,omitempty" description:"list of addresses reachable to the node; see http://releases.k8s.io/HEAD/docs/admin/node.md#node-addresses" patchStrategy:"merge" patchMergeKey:"type"` } +// NodeAddressType can legally only have the values defined as constants below. type NodeAddressType string // These are valid address types of node. NodeLegacyHostIP is used to transit @@ -211,6 +214,7 @@ const ( NodeInternalIP NodeAddressType = "InternalIP" ) +// NodeAddress defines the address of a node. type NodeAddress struct { Type NodeAddressType `json:"type" description:"node address type, one of Hostname, ExternalIP or InternalIP"` Address string `json:"address" description:"the node address"`