Merge pull request #1645 from prometheus/beorn7/style

Fix same style issues
This commit is contained in:
Björn Rabenstein 2016-05-20 13:51:10 +02:00
commit 95ef7b14a7
4 changed files with 37 additions and 32 deletions

View file

@ -18,6 +18,7 @@ import (
"github.com/prometheus/prometheus/retrieval/discovery/consul" "github.com/prometheus/prometheus/retrieval/discovery/consul"
) )
// NewConsul creates a new Consul based Discovery.
func NewConsul(cfg *config.ConsulSDConfig) (*consul.Discovery, error) { func NewConsul(cfg *config.ConsulSDConfig) (*consul.Discovery, error) {
return consul.NewDiscovery(cfg) return consul.NewDiscovery(cfg)
} }

View file

@ -253,10 +253,10 @@ func (kd *Discovery) updateNode(node *Node, eventType EventType) {
defer kd.nodesMu.Unlock() defer kd.nodesMu.Unlock()
updatedNodeName := node.ObjectMeta.Name updatedNodeName := node.ObjectMeta.Name
switch eventType { switch eventType {
case deleted: case Deleted:
// Deleted - remove from nodes map. // Deleted - remove from nodes map.
delete(kd.nodes, updatedNodeName) delete(kd.nodes, updatedNodeName)
case added, modified: case Added, Modified:
// Added/Modified - update the node in the nodes map. // Added/Modified - update the node in the nodes map.
kd.nodes[updatedNodeName] = node kd.nodes[updatedNodeName] = node
} }
@ -331,7 +331,7 @@ func (kd *Discovery) watchNodes(events chan interface{}, done <-chan struct{}, r
kd.nodes = map[string]*Node{} kd.nodes = map[string]*Node{}
for _, node := range nodes { for _, node := range nodes {
events <- &nodeEvent{added, node} events <- &nodeEvent{Added, node}
} }
req, err := http.NewRequest("GET", nodesURL, nil) 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 { for oldNSName, oldNS := range existingServices {
if ns, ok := services[oldNSName]; !ok { if ns, ok := services[oldNSName]; !ok {
for _, service := range existingServices[oldNSName] { for _, service := range existingServices[oldNSName] {
events <- &serviceEvent{deleted, service} events <- &serviceEvent{Deleted, service}
} }
} else { } else {
for oldServiceName, oldService := range oldNS { for oldServiceName, oldService := range oldNS {
if _, ok := ns[oldServiceName]; !ok { 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 _, ns := range services {
for _, service := range ns { 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() defer kd.servicesMu.Unlock()
switch eventType { switch eventType {
case deleted: case Deleted:
return kd.deleteService(service) return kd.deleteService(service)
case added, modified: case Added, Modified:
return kd.addService(service) return kd.addService(service)
} }
return nil return nil

View file

@ -13,12 +13,14 @@
package kubernetes package kubernetes
// EventType can legally only have the values defined as constants below.
type EventType string type EventType string
// Possible values for EventType.
const ( const (
added EventType = "ADDED" Added EventType = "ADDED"
modified EventType = "MODIFIED" Modified EventType = "MODIFIED"
deleted EventType = "DELETED" Deleted EventType = "DELETED"
) )
type nodeEvent struct { 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"` 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 type NodeAddressType string
// These are valid address types of node. NodeLegacyHostIP is used to transit // These are valid address types of node. NodeLegacyHostIP is used to transit
@ -211,6 +214,7 @@ const (
NodeInternalIP NodeAddressType = "InternalIP" NodeInternalIP NodeAddressType = "InternalIP"
) )
// NodeAddress defines the address of a node.
type NodeAddress struct { type NodeAddress struct {
Type NodeAddressType `json:"type" description:"node address type, one of Hostname, ExternalIP or InternalIP"` Type NodeAddressType `json:"type" description:"node address type, one of Hostname, ExternalIP or InternalIP"`
Address string `json:"address" description:"the node address"` Address string `json:"address" description:"the node address"`

View file

@ -106,8 +106,8 @@ func NewAlertingRule(name string, vec promql.Expr, hold time.Duration, lbls, ann
} }
// Name returns the name of the alert. // Name returns the name of the alert.
func (rule *AlertingRule) Name() string { func (r *AlertingRule) Name() string {
return rule.name return r.name
} }
func (r *AlertingRule) equal(o *AlertingRule) bool { func (r *AlertingRule) equal(o *AlertingRule) bool {
@ -255,17 +255,17 @@ func (r *AlertingRule) currentAlerts() []*Alert {
return alerts return alerts
} }
func (rule *AlertingRule) String() string { func (r *AlertingRule) String() string {
s := fmt.Sprintf("ALERT %s", rule.name) s := fmt.Sprintf("ALERT %s", r.name)
s += fmt.Sprintf("\n\tIF %s", rule.vector) s += fmt.Sprintf("\n\tIF %s", r.vector)
if rule.holdDuration > 0 { if r.holdDuration > 0 {
s += fmt.Sprintf("\n\tFOR %s", model.Duration(rule.holdDuration)) s += fmt.Sprintf("\n\tFOR %s", model.Duration(r.holdDuration))
} }
if len(rule.labels) > 0 { if len(r.labels) > 0 {
s += fmt.Sprintf("\n\tLABELS %s", rule.labels) s += fmt.Sprintf("\n\tLABELS %s", r.labels)
} }
if len(rule.annotations) > 0 { if len(r.annotations) > 0 {
s += fmt.Sprintf("\n\tANNOTATIONS %s", rule.annotations) s += fmt.Sprintf("\n\tANNOTATIONS %s", r.annotations)
} }
return s return s
} }
@ -273,21 +273,21 @@ func (rule *AlertingRule) String() string {
// HTMLSnippet returns an HTML snippet representing this alerting rule. The // HTMLSnippet returns an HTML snippet representing this alerting rule. The
// resulting snippet is expected to be presented in a <pre> element, so that // resulting snippet is expected to be presented in a <pre> element, so that
// line breaks and other returned whitespace is respected. // line breaks and other returned whitespace is respected.
func (rule *AlertingRule) HTMLSnippet(pathPrefix string) template.HTML { func (r *AlertingRule) HTMLSnippet(pathPrefix string) template.HTML {
alertMetric := model.Metric{ alertMetric := model.Metric{
model.MetricNameLabel: alertMetricName, model.MetricNameLabel: alertMetricName,
alertNameLabel: model.LabelValue(rule.name), alertNameLabel: model.LabelValue(r.name),
} }
s := fmt.Sprintf("ALERT <a href=%q>%s</a>", pathPrefix+strutil.GraphLinkForExpression(alertMetric.String()), rule.name) s := fmt.Sprintf("ALERT <a href=%q>%s</a>", pathPrefix+strutil.GraphLinkForExpression(alertMetric.String()), r.name)
s += fmt.Sprintf("\n IF <a href=%q>%s</a>", pathPrefix+strutil.GraphLinkForExpression(rule.vector.String()), rule.vector) s += fmt.Sprintf("\n IF <a href=%q>%s</a>", pathPrefix+strutil.GraphLinkForExpression(r.vector.String()), r.vector)
if rule.holdDuration > 0 { if r.holdDuration > 0 {
s += fmt.Sprintf("\n FOR %s", model.Duration(rule.holdDuration)) s += fmt.Sprintf("\n FOR %s", model.Duration(r.holdDuration))
} }
if len(rule.labels) > 0 { if len(r.labels) > 0 {
s += fmt.Sprintf("\n LABELS %s", rule.labels) s += fmt.Sprintf("\n LABELS %s", r.labels)
} }
if len(rule.annotations) > 0 { if len(r.annotations) > 0 {
s += fmt.Sprintf("\n ANNOTATIONS %s", rule.annotations) s += fmt.Sprintf("\n ANNOTATIONS %s", r.annotations)
} }
return template.HTML(s) return template.HTML(s)
} }