Skip to content

Commit

Permalink
Miscellaneous lint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-rushakoff committed Jan 10, 2017
1 parent 3dc789b commit 0fc59af
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 32 deletions.
2 changes: 1 addition & 1 deletion alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func newAlertNode(et *ExecutingTask, n *pipeline.AlertNode, l *log.Logger) (an *
an.bufPool.Put(tmpBuffer)
}()

json.NewEncoder(tmpBuffer).Encode(v)
_ = json.NewEncoder(tmpBuffer).Encode(v)

return html.JS(tmpBuffer.String())
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/kapacitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (d *dbrps) Set(value string) error {
}
value = value[n+1:]
if value[0] == '"' {
dbrp.RetentionPolicy, n = parseQuotedStr(value)
dbrp.RetentionPolicy, _ = parseQuotedStr(value)
} else {
dbrp.RetentionPolicy = value
}
Expand Down
2 changes: 1 addition & 1 deletion global_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func init() {
}

func Uptime() time.Duration {
return time.Now().Sub(startTime)
return time.Since(startTime)
}

// NewStatistics creates an expvar-based map. Within there "name" is the Measurement name, "tags" are the tags,
Expand Down
2 changes: 1 addition & 1 deletion http_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (h *HTTPOutNode) runOut([]byte) error {
http.StatusInternalServerError,
)
} else {
w.Write(b)
_, _ = w.Write(b)
}
}

Expand Down
4 changes: 3 additions & 1 deletion influxdb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ func (c *HTTPClient) do(req *http.Request, result interface{}, codes ...int) (*h
rp := struct {
Error string `json:"error"`
}{}
d.Decode(&rp)
if err := d.Decode(&rp); err != nil {
return nil, err
}
if rp.Error != "" {
return nil, errors.New(rp.Error)
}
Expand Down
8 changes: 6 additions & 2 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func (s *LogNode) runLog([]byte) error {
case pipeline.StreamEdge:
for p, ok := s.ins[0].NextPoint(); ok; p, ok = s.ins[0].NextPoint() {
buf.Reset()
env.Encode(p)
if err := env.Encode(p); err != nil {
return err
}
s.logger.Println(key, buf.String())
for _, child := range s.outs {
err := child.CollectPoint(p)
Expand All @@ -52,7 +54,9 @@ func (s *LogNode) runLog([]byte) error {
case pipeline.BatchEdge:
for b, ok := s.ins[0].NextBatch(); ok; b, ok = s.ins[0].NextBatch() {
buf.Reset()
env.Encode(b)
if err := env.Encode(b); err != nil {
return err
}
s.logger.Println(key, buf.String())
for _, child := range s.outs {
err := child.CollectBatch(b)
Expand Down
2 changes: 1 addition & 1 deletion pipeline/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (n *node) addParent(c Node) {

func (n *node) linkChild(c Node) {
c.setPipeline(n.p)
n.p.assignID(c)
_ = n.p.assignID(c)
n.children = append(n.children, c)
c.addParent(n)
}
Expand Down
4 changes: 2 additions & 2 deletions pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type Pipeline struct {

func (p *Pipeline) addSource(src Node) {
src.setPipeline(p)
p.assignID(src)
_ = p.assignID(src)
p.sources = append(p.sources, src)
}

Expand Down Expand Up @@ -185,7 +185,7 @@ func (p *Pipeline) Dot(name string) []byte {
buf.Write([]byte("digraph "))
buf.Write([]byte(name))
buf.Write([]byte(" {\n"))
p.Walk(func(n Node) error {
_ = p.Walk(func(n Node) error {
n.dot(&buf)
return nil
})
Expand Down
20 changes: 15 additions & 5 deletions replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ func replayBatchFromChan(clck clock.Clock, batches <-chan models.Batch, collecto
b.TMax = b.TMax.UTC()
tmax = b.TMax
}
collector.CollectBatch(b)
if err := collector.CollectBatch(b); err != nil {
return err
}
continue
}
if start.IsZero() {
Expand All @@ -209,7 +211,9 @@ func replayBatchFromChan(clck clock.Clock, batches <-chan models.Batch, collecto
}
b.TMax = b.TMax.UTC()
tmax = b.TMax
collector.CollectBatch(b)
if err := collector.CollectBatch(b); err != nil {
return err
}
}
return nil
}
Expand Down Expand Up @@ -253,9 +257,15 @@ func readBatchFromIO(data io.ReadCloser, batches chan<- models.Batch) error {
}

func WritePointForRecording(w io.Writer, p models.Point, precision string) error {
fmt.Fprintf(w, "%s\n%s\n", p.Database, p.RetentionPolicy)
w.Write(p.Bytes(precision))
w.Write([]byte("\n"))
if _, err := fmt.Fprintf(w, "%s\n%s\n", p.Database, p.RetentionPolicy); err != nil {
return err
}
if _, err := w.Write(p.Bytes(precision)); err != nil {
return err
}
if _, err := w.Write([]byte("\n")); err != nil {
return err
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion result.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func ResultFromJSON(in io.Reader) (r Result) {
return
}

json.Unmarshal(b, &r)
_ = json.Unmarshal(b, &r)
// Convert all times to time.Time
ConvertResultTimes(&r)
return
Expand Down
4 changes: 3 additions & 1 deletion server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ func (c *Config) applyEnvOverrides(prefix string, fieldDesc string, spec reflect
}
s.SetFloat(floatValue)
case reflect.Struct:
c.applyEnvOverridesToStruct(prefix, s)
if err := c.applyEnvOverridesToStruct(prefix, s); err != nil {
return err
}
}
return nil
}
Expand Down
10 changes: 7 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ type dynamicService interface {

func (s *Server) SetDynamicService(name string, srv dynamicService) {
s.DynamicServices[name] = srv
s.TesterService.AddTester(name, srv)
_ = s.TesterService.AddTester(name, srv)
}

func (s *Server) appendStorageService() {
Expand Down Expand Up @@ -793,7 +793,9 @@ func (s *Server) startProfile(cpuprofile, memprofile string) {
}
s.Logger.Printf("I! writing CPU profile to: %s\n", cpuprofile)
prof.cpu = f
pprof.StartCPUProfile(prof.cpu)
if err := pprof.StartCPUProfile(prof.cpu); err != nil {
s.Logger.Fatalf("#! start cpu profile: %v", err)
}
}

if memprofile != "" {
Expand All @@ -816,7 +818,9 @@ func (s *Server) stopProfile() {
s.Logger.Println("I! CPU profile stopped")
}
if prof.mem != nil {
pprof.Lookup("heap").WriteTo(prof.mem, 0)
if err := pprof.Lookup("heap").WriteTo(prof.mem, 0); err != nil {
s.Logger.Printf("I! failed to write mem profile: %v\n", err)
}
prof.mem.Close()
s.Logger.Println("I! mem profile stopped")
}
Expand Down
54 changes: 54 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2954,6 +2954,9 @@ test value=1 0000000012
}

recordings, err := cli.ListRecordings(nil)
if err != nil {
t.Error(err)
}
if exp, got := 1, len(recordings); exp != got {
t.Fatalf("unexpected recordings list:\ngot %v\nexp %v\nrecordings %v", got, exp, recordings)
}
Expand All @@ -2964,11 +2967,17 @@ test value=1 0000000012
}

recordings, err = cli.ListRecordings(nil)
if err != nil {
t.Error(err)
}
if exp, got := 0, len(recordings); exp != got {
t.Errorf("unexpected recordings list after delete:\ngot %v\nexp %v\nrecordings %v", got, exp, recordings)
}

replays, err := cli.ListReplays(nil)
if err != nil {
t.Error(err)
}
if exp, got := 1, len(replays); exp != got {
t.Fatalf("unexpected replays list:\ngot %v\nexp %v\nreplays %v", got, exp, replays)
}
Expand All @@ -2979,6 +2988,9 @@ test value=1 0000000012
}

replays, err = cli.ListReplays(nil)
if err != nil {
t.Error(err)
}
if exp, got := 0, len(replays); exp != got {
t.Errorf("unexpected replays list after delete:\ngot %v\nexp %v\nreplays %v", got, exp, replays)
}
Expand Down Expand Up @@ -3181,6 +3193,9 @@ func TestServer_RecordReplayBatch(t *testing.T) {
}

recordings, err := cli.ListRecordings(nil)
if err != nil {
t.Error(err)
}
if exp, got := 1, len(recordings); exp != got {
t.Fatalf("unexpected recordings list:\ngot %v\nexp %v", got, exp)
}
Expand All @@ -3191,11 +3206,17 @@ func TestServer_RecordReplayBatch(t *testing.T) {
}

recordings, err = cli.ListRecordings(nil)
if err != nil {
t.Error(err)
}
if exp, got := 0, len(recordings); exp != got {
t.Errorf("unexpected recordings list:\ngot %v\nexp %v", got, exp)
}

replays, err := cli.ListReplays(nil)
if err != nil {
t.Error(err)
}
if exp, got := 1, len(replays); exp != got {
t.Fatalf("unexpected replays list:\ngot %v\nexp %v", got, exp)
}
Expand All @@ -3206,6 +3227,9 @@ func TestServer_RecordReplayBatch(t *testing.T) {
}

replays, err = cli.ListReplays(nil)
if err != nil {
t.Error(err)
}
if exp, got := 0, len(replays); exp != got {
t.Errorf("unexpected replays list:\ngot %v\nexp %v", got, exp)
}
Expand Down Expand Up @@ -3382,11 +3406,17 @@ func TestServer_ReplayBatch(t *testing.T) {
}

recordings, err := cli.ListRecordings(nil)
if err != nil {
t.Error(err)
}
if exp, got := 0, len(recordings); exp != got {
t.Fatalf("unexpected recordings list:\ngot %v\nexp %v", got, exp)
}

replays, err := cli.ListReplays(nil)
if err != nil {
t.Error(err)
}
if exp, got := 1, len(replays); exp != got {
t.Fatalf("unexpected replays list:\ngot %v\nexp %v", got, exp)
}
Expand All @@ -3397,6 +3427,9 @@ func TestServer_ReplayBatch(t *testing.T) {
}

replays, err = cli.ListReplays(nil)
if err != nil {
t.Error(err)
}
if exp, got := 0, len(replays); exp != got {
t.Errorf("unexpected replays list:\ngot %v\nexp %v", got, exp)
}
Expand Down Expand Up @@ -3629,6 +3662,9 @@ func TestServer_RecordReplayQuery(t *testing.T) {
// Test List/Delete Recordings/Replays

recordings, err := cli.ListRecordings(nil)
if err != nil {
t.Error(err)
}
if exp, got := 1, len(recordings); exp != got {
t.Fatalf("unexpected recordings list:\ngot %v\nexp %v", got, exp)
}
Expand Down Expand Up @@ -3659,11 +3695,17 @@ func TestServer_RecordReplayQuery(t *testing.T) {
}

recordings, err = cli.ListRecordings(nil)
if err != nil {
t.Error(err)
}
if exp, got := 0, len(recordings); exp != got {
t.Errorf("unexpected recordings list:\ngot %v\nexp %v", got, exp)
}

replays, err := cli.ListReplays(nil)
if err != nil {
t.Error(err)
}
if exp, got := 1, len(replays); exp != got {
t.Fatalf("unexpected replays list:\ngot %v\nexp %v", got, exp)
}
Expand Down Expand Up @@ -3694,6 +3736,9 @@ func TestServer_RecordReplayQuery(t *testing.T) {
}

replays, err = cli.ListReplays(nil)
if err != nil {
t.Error(err)
}
if exp, got := 0, len(replays); exp != got {
t.Errorf("unexpected replays list:\ngot %v\nexp %v", got, exp)
}
Expand Down Expand Up @@ -3898,11 +3943,17 @@ func TestServer_ReplayQuery(t *testing.T) {
}

recordings, err := cli.ListRecordings(nil)
if err != nil {
t.Error(err)
}
if exp, got := 0, len(recordings); exp != got {
t.Fatalf("unexpected recordings list:\ngot %v\nexp %v", got, exp)
}

replays, err := cli.ListReplays(nil)
if err != nil {
t.Error(err)
}
if exp, got := 1, len(replays); exp != got {
t.Fatalf("unexpected replays list:\ngot %v\nexp %v", got, exp)
}
Expand All @@ -3913,6 +3964,9 @@ func TestServer_ReplayQuery(t *testing.T) {
}

replays, err = cli.ListReplays(nil)
if err != nil {
t.Error(err)
}
if exp, got := 0, len(replays); exp != got {
t.Errorf("unexpected replays list:\ngot %v\nexp %v", got, exp)
}
Expand Down
7 changes: 7 additions & 0 deletions services/influxdb/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@ func (c *influxdbCluster) linkSubscriptions(ctx context.Context) error {
// This is an just the cluster ID
// drop it and recreate with new name.
err := c.dropSub(se.name, se.db, se.rp)
if err != nil {
return err
}
se.name = c.subName
err = c.createSub(se.name, se.db, se.rp, si.Mode, si.Destinations)
if err != nil {
Expand Down Expand Up @@ -875,6 +878,10 @@ func (c *influxdbCluster) linkSubscriptions(ctx context.Context) error {
continue
}
host, port, err := net.SplitHostPort(u.Host)
if err != nil {
c.logger.Println("E! invalid host in subscription:", err)
continue
}
if host == c.hostname {
if u.Scheme == "udp" {
_, err := c.startUDPListener(se, port)
Expand Down
Loading

0 comments on commit 0fc59af

Please sign in to comment.