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"
)
// NewConsul creates a new Consul based Discovery.
func NewConsul(cfg *config.ConsulSDConfig) (*consul.Discovery, error) {
return consul.NewDiscovery(cfg)
}

View File

@ -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

View File

@ -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"`

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.
func (rule *AlertingRule) Name() string {
return rule.name
func (r *AlertingRule) Name() string {
return r.name
}
func (r *AlertingRule) equal(o *AlertingRule) bool {
@ -255,17 +255,17 @@ func (r *AlertingRule) currentAlerts() []*Alert {
return alerts
}
func (rule *AlertingRule) String() string {
s := fmt.Sprintf("ALERT %s", rule.name)
s += fmt.Sprintf("\n\tIF %s", rule.vector)
if rule.holdDuration > 0 {
s += fmt.Sprintf("\n\tFOR %s", model.Duration(rule.holdDuration))
func (r *AlertingRule) String() string {
s := fmt.Sprintf("ALERT %s", r.name)
s += fmt.Sprintf("\n\tIF %s", r.vector)
if r.holdDuration > 0 {
s += fmt.Sprintf("\n\tFOR %s", model.Duration(r.holdDuration))
}
if len(rule.labels) > 0 {
s += fmt.Sprintf("\n\tLABELS %s", rule.labels)
if len(r.labels) > 0 {
s += fmt.Sprintf("\n\tLABELS %s", r.labels)
}
if len(rule.annotations) > 0 {
s += fmt.Sprintf("\n\tANNOTATIONS %s", rule.annotations)
if len(r.annotations) > 0 {
s += fmt.Sprintf("\n\tANNOTATIONS %s", r.annotations)
}
return s
}
@ -273,21 +273,21 @@ func (rule *AlertingRule) String() string {
// HTMLSnippet returns an HTML snippet representing this alerting rule. The
// resulting snippet is expected to be presented in a <pre> element, so that
// 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{
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("\n IF <a href=%q>%s</a>", pathPrefix+strutil.GraphLinkForExpression(rule.vector.String()), rule.vector)
if rule.holdDuration > 0 {
s += fmt.Sprintf("\n FOR %s", model.Duration(rule.holdDuration))
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(r.vector.String()), r.vector)
if r.holdDuration > 0 {
s += fmt.Sprintf("\n FOR %s", model.Duration(r.holdDuration))
}
if len(rule.labels) > 0 {
s += fmt.Sprintf("\n LABELS %s", rule.labels)
if len(r.labels) > 0 {
s += fmt.Sprintf("\n LABELS %s", r.labels)
}
if len(rule.annotations) > 0 {
s += fmt.Sprintf("\n ANNOTATIONS %s", rule.annotations)
if len(r.annotations) > 0 {
s += fmt.Sprintf("\n ANNOTATIONS %s", r.annotations)
}
return template.HTML(s)
}