Skip to content

Commit

Permalink
Fix most golint warnings.
Browse files Browse the repository at this point in the history
This is with `golint -min_confidence=0.5`.

I left several lint warnings untouched because they were either
incorrect or I felt it was better not to change them at the moment.
  • Loading branch information
juliusv committed Aug 26, 2015
1 parent 6664b77 commit 995d3b8
Show file tree
Hide file tree
Showing 23 changed files with 124 additions and 117 deletions.
1 change: 1 addition & 0 deletions cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func main() {
os.Exit(Main())
}

// Main manages the startup and shutdown lifecycle of the entire Prometheus server.
func Main() int {
if err := parse(os.Args[1:]); err != nil {
return 2
Expand Down
31 changes: 16 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ func LoadFile(filename string) (*Config, error) {

// The defaults applied before parsing the respective config sections.
var (
// The default top-level configuration.
// DefaultConfig is the default top-level configuration.
DefaultConfig = Config{
GlobalConfig: DefaultGlobalConfig,
}

// The default global configuration.
// DefaultGlobalConfig is the default global configuration.
DefaultGlobalConfig = GlobalConfig{
ScrapeInterval: Duration(1 * time.Minute),
ScrapeTimeout: Duration(10 * time.Second),
EvaluationInterval: Duration(1 * time.Minute),
}

// The default scrape configuration.
// DefaultScrapeConfig is the default scrape configuration.
DefaultScrapeConfig = ScrapeConfig{
// ScrapeTimeout and ScrapeInterval default to the
// configured globals.
Expand All @@ -89,30 +89,30 @@ var (
HonorLabels: false,
}

// The default Relabel configuration.
// DefaultRelabelConfig is the default Relabel configuration.
DefaultRelabelConfig = RelabelConfig{
Action: RelabelReplace,
Separator: ";",
}

// The default DNS SD configuration.
// DefaultDNSSDConfig is the default DNS SD configuration.
DefaultDNSSDConfig = DNSSDConfig{
RefreshInterval: Duration(30 * time.Second),
Type: "SRV",
}

// The default file SD configuration.
// DefaultFileSDConfig is the default file SD configuration.
DefaultFileSDConfig = FileSDConfig{
RefreshInterval: Duration(5 * time.Minute),
}

// The default Consul SD configuration.
// DefaultConsulSDConfig is the default Consul SD configuration.
DefaultConsulSDConfig = ConsulSDConfig{
TagSeparator: ",",
Scheme: "http",
}

// The default Serverset SD configuration.
// DefaultServersetSDConfig is the default Serverset SD configuration.
DefaultServersetSDConfig = ServersetSDConfig{
Timeout: Duration(10 * time.Second),
}
Expand All @@ -122,15 +122,15 @@ var (
RefreshInterval: Duration(30 * time.Second),
}

// The default Kubernetes SD configuration
// DefaultKubernetesSDConfig is the default Kubernetes SD configuration
DefaultKubernetesSDConfig = KubernetesSDConfig{
KubeletPort: 10255,
RequestTimeout: Duration(10 * time.Second),
RetryInterval: Duration(1 * time.Second),
}
)

// This custom URL type allows validating at configuration load time.
// URL is a custom URL type that allows validation at configuration load time.
type URL struct {
*url.URL
}
Expand Down Expand Up @@ -633,6 +633,7 @@ func (c *MarathonSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) erro
return checkOverflow(c.XXX, "marathon_sd_config")
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *KubernetesSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultKubernetesSDConfig
type plain KubernetesSDConfig
Expand All @@ -655,15 +656,15 @@ func (c *KubernetesSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
type RelabelAction string

const (
// Performs a regex replacement.
// RelabelReplace performs a regex replacement.
RelabelReplace RelabelAction = "replace"
// Drops targets for which the input does not match the regex.
// RelabelKeep drops targets for which the input does not match the regex.
RelabelKeep RelabelAction = "keep"
// Drops targets for which the input does match the regex.
// RelabelDrop drops targets for which the input does match the regex.
RelabelDrop RelabelAction = "drop"
// Sets a label to the modulus of a hash of labels.
// RelabelHashMod sets a label to the modulus of a hash of labels.
RelabelHashMod RelabelAction = "hashmod"
// Copy labels to other labelnames based on a regex.
// RelabelLabelMap copies labels to other labelnames based on a regex.
RelabelLabelMap RelabelAction = "labelmap"
)

Expand Down
10 changes: 5 additions & 5 deletions promql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ func (e *ParenExpr) Type() model.ValueType { return e.Expr.Type() }
func (e *StringLiteral) Type() model.ValueType { return model.ValString }
func (e *UnaryExpr) Type() model.ValueType { return e.Expr.Type() }
func (e *VectorSelector) Type() model.ValueType { return model.ValVector }

func (e *BinaryExpr) Type() model.ValueType {
if e.LHS.Type() == model.ValScalar && e.RHS.Type() == model.ValScalar {
return model.ValScalar
Expand All @@ -197,7 +196,7 @@ func (*StringLiteral) expr() {}
func (*UnaryExpr) expr() {}
func (*VectorSelector) expr() {}

// VectorMatchCardinaly describes the cardinality relationship
// VectorMatchCardinality describes the cardinality relationship
// of two vectors in a binary operation.
type VectorMatchCardinality int

Expand Down Expand Up @@ -235,9 +234,10 @@ type VectorMatching struct {
Include model.LabelNames
}

// A Visitor's Visit method is invoked for each node encountered by Walk.
// If the result visitor w is not nil, Walk visits each of the children
// of node with the visitor w, followed by a call of w.Visit(nil).
// Visitor allows visiting a Node and its child nodes. The Visit method is
// invoked for each node encountered by Walk. If the result visitor w is not
// nil, Walk visits each of the children of node with the visitor w, followed
// by a call of w.Visit(nil).
type Visitor interface {
Visit(node Node) (w Visitor)
}
Expand Down
12 changes: 6 additions & 6 deletions promql/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ func init() {
key["nan"] = itemNumber
}

func (t itemType) String() string {
if s, ok := itemTypeStr[t]; ok {
func (i itemType) String() string {
if s, ok := itemTypeStr[i]; ok {
return s
}
return fmt.Sprintf("<item %d>", t)
return fmt.Sprintf("<item %d>", i)
}

func (i item) desc() string {
Expand All @@ -242,8 +242,8 @@ func (i item) desc() string {
return fmt.Sprintf("%s %s", i.typ.desc(), i)
}

func (t itemType) desc() string {
switch t {
func (i itemType) desc() string {
switch i {
case itemError:
return "error"
case itemEOF:
Expand All @@ -261,7 +261,7 @@ func (t itemType) desc() string {
case itemDuration:
return "duration"
}
return fmt.Sprintf("%q", t)
return fmt.Sprintf("%q", i)
}

const eof = -1
Expand Down
2 changes: 1 addition & 1 deletion promql/promql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestEvaluations(t *testing.T) {
t.Fatal(err)
}
for _, fn := range files {
test, err := NewTestFromFile(t, fn)
test, err := newTestFromFile(t, fn)
if err != nil {
t.Errorf("error creating test for %s: %s", fn, err)
}
Expand Down
3 changes: 2 additions & 1 deletion promql/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewTest(t testutil.T, input string) (*Test, error) {
return test, err
}

func NewTestFromFile(t testutil.T, filename string) (*Test, error) {
func newTestFromFile(t testutil.T, filename string) (*Test, error) {
content, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
Expand Down Expand Up @@ -477,6 +477,7 @@ func (t *Test) clear() {
t.queryEngine = NewEngine(t.storage, nil)
}

// Close closes resources associated with the Test.
func (t *Test) Close() {
t.queryEngine.Stop()
t.closeStorage()
Expand Down
48 changes: 24 additions & 24 deletions retrieval/discovery/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ const (
consulWatchTimeout = 30 * time.Second
consulRetryInterval = 15 * time.Second

// ConsuleAddressLabel is the name for the label containing a target's address.
ConsulAddressLabel = model.MetaLabelPrefix + "consul_address"
// ConsuleNodeLabel is the name for the label containing a target's node name.
ConsulNodeLabel = model.MetaLabelPrefix + "consul_node"
// ConsulTagsLabel is the name of the label containing the tags assigned to the target.
ConsulTagsLabel = model.MetaLabelPrefix + "consul_tags"
// ConsulServiceLabel is the name of the label containing the service name.
ConsulServiceLabel = model.MetaLabelPrefix + "consul_service"
// ConsulServiceAddressLabel is the name of the label containing the (optional) service address.
ConsulServiceAddressLabel = model.MetaLabelPrefix + "consul_service_address"
// ConsulServicePortLabel is the name of the label containing the service port.
ConsulServicePortLabel = model.MetaLabelPrefix + "consul_service_port"
// ConsulDCLabel is the name of the label containing the datacenter ID.
ConsulDCLabel = model.MetaLabelPrefix + "consul_dc"
// ConsulServiceIDLabel is the name of the label containing the service ID.
ConsulServiceIDLabel = model.MetaLabelPrefix + "consul_service_id"
// consulAddressLabel is the name for the label containing a target's address.
consulAddressLabel = model.MetaLabelPrefix + "consul_address"
// consulNodeLabel is the name for the label containing a target's node name.
consulNodeLabel = model.MetaLabelPrefix + "consul_node"
// consulTagsLabel is the name of the label containing the tags assigned to the target.
consulTagsLabel = model.MetaLabelPrefix + "consul_tags"
// consulServiceLabel is the name of the label containing the service name.
consulServiceLabel = model.MetaLabelPrefix + "consul_service"
// consulServiceAddressLabel is the name of the label containing the (optional) service address.
consulServiceAddressLabel = model.MetaLabelPrefix + "consul_service_address"
// consulServicePortLabel is the name of the label containing the service port.
consulServicePortLabel = model.MetaLabelPrefix + "consul_service_port"
// consulDCLabel is the name of the label containing the datacenter ID.
consulDCLabel = model.MetaLabelPrefix + "consul_dc"
// consulServiceIDLabel is the name of the label containing the service ID.
consulServiceIDLabel = model.MetaLabelPrefix + "consul_service_id"
)

// ConsulDiscovery retrieves target information from a Consul server
Expand Down Expand Up @@ -226,8 +226,8 @@ func (cd *ConsulDiscovery) watchServices(update chan<- *consulService, done <-ch
cd.services[name] = srv
}
srv.tgroup.Labels = model.LabelSet{
ConsulServiceLabel: model.LabelValue(name),
ConsulDCLabel: model.LabelValue(cd.clientDatacenter),
consulServiceLabel: model.LabelValue(name),
consulDCLabel: model.LabelValue(cd.clientDatacenter),
}
update <- srv
}
Expand Down Expand Up @@ -272,12 +272,12 @@ func (cd *ConsulDiscovery) watchService(srv *consulService, ch chan<- *config.Ta

srv.tgroup.Targets = append(srv.tgroup.Targets, model.LabelSet{
model.AddressLabel: model.LabelValue(addr),
ConsulAddressLabel: model.LabelValue(node.Address),
ConsulNodeLabel: model.LabelValue(node.Node),
ConsulTagsLabel: model.LabelValue(tags),
ConsulServiceAddressLabel: model.LabelValue(node.ServiceAddress),
ConsulServicePortLabel: model.LabelValue(strconv.Itoa(node.ServicePort)),
ConsulServiceIDLabel: model.LabelValue(node.ServiceID),
consulAddressLabel: model.LabelValue(node.Address),
consulNodeLabel: model.LabelValue(node.Node),
consulTagsLabel: model.LabelValue(tags),
consulServiceAddressLabel: model.LabelValue(node.ServiceAddress),
consulServicePortLabel: model.LabelValue(strconv.Itoa(node.ServicePort)),
consulServiceIDLabel: model.LabelValue(node.ServiceID),
})
}

Expand Down
4 changes: 2 additions & 2 deletions retrieval/discovery/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
const (
resolvConf = "/etc/resolv.conf"

DNSNameLabel = model.MetaLabelPrefix + "dns_name"
dnsNameLabel = model.MetaLabelPrefix + "dns_name"

// Constants for instrumentation.
namespace = "prometheus"
Expand Down Expand Up @@ -161,7 +161,7 @@ func (dd *DNSDiscovery) refresh(name string, ch chan<- *config.TargetGroup) erro
}
tg.Targets = append(tg.Targets, model.LabelSet{
model.AddressLabel: target,
DNSNameLabel: model.LabelValue(name),
dnsNameLabel: model.LabelValue(name),
})
}

Expand Down
4 changes: 2 additions & 2 deletions retrieval/discovery/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/prometheus/prometheus/config"
)

const FileSDFilepathLabel = model.MetaLabelPrefix + "filepath"
const fileSDFilepathLabel = model.MetaLabelPrefix + "filepath"

// FileDiscovery provides service discovery functionality based
// on files that contain target groups in JSON or YAML format. Refreshing
Expand Down Expand Up @@ -245,7 +245,7 @@ func readFile(filename string) ([]*config.TargetGroup, error) {
if tg.Labels == nil {
tg.Labels = model.LabelSet{}
}
tg.Labels[FileSDFilepathLabel] = model.LabelValue(filename)
tg.Labels[fileSDFilepathLabel] = model.LabelValue(filename)
}
return targetGroups, nil
}
5 changes: 3 additions & 2 deletions retrieval/discovery/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
"github.com/prometheus/prometheus/retrieval/discovery/kubernetes"
)

func NewKubernetesDiscovery(conf *config.KubernetesSDConfig) (*kubernetes.KubernetesDiscovery, error) {
kd := &kubernetes.KubernetesDiscovery{
// NewKubernetesDiscovery creates a Kubernetes service discovery based on the passed-in configuration.
func NewKubernetesDiscovery(conf *config.KubernetesSDConfig) (*kubernetes.Discovery, error) {
kd := &kubernetes.Discovery{
Conf: conf,
}
err := kd.Initialize()
Expand Down
Loading

0 comments on commit 995d3b8

Please sign in to comment.