mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
Handle a bunch of unchecked errors (#365)
As discovered by "gosec". Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
parent
dfcb7d0d50
commit
5ae6c60d39
7
block.go
7
block.go
|
@ -504,10 +504,13 @@ Outer:
|
|||
func (pb *Block) CleanTombstones(dest string, c Compactor) (*ulid.ULID, error) {
|
||||
numStones := 0
|
||||
|
||||
pb.tombstones.Iter(func(id uint64, ivs Intervals) error {
|
||||
if err := pb.tombstones.Iter(func(id uint64, ivs Intervals) error {
|
||||
numStones += len(ivs)
|
||||
return nil
|
||||
})
|
||||
}); err != nil {
|
||||
// This should never happen, as the iteration function only returns nil.
|
||||
panic(err)
|
||||
}
|
||||
if numStones == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -145,7 +145,9 @@ func (b *writeBenchmark) run() {
|
|||
if err := b.storage.Close(); err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
b.stopProfiling()
|
||||
if err := b.stopProfiling(); err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -248,7 +250,9 @@ func (b *writeBenchmark) startProfiling() {
|
|||
if err != nil {
|
||||
exitWithError(fmt.Errorf("bench: could not create cpu profile: %v", err))
|
||||
}
|
||||
pprof.StartCPUProfile(b.cpuprof)
|
||||
if err := pprof.StartCPUProfile(b.cpuprof); err != nil {
|
||||
exitWithError(fmt.Errorf("bench: could not start CPU profile: %v", err))
|
||||
}
|
||||
|
||||
// Start memory profiling.
|
||||
b.memprof, err = os.Create(filepath.Join(b.outPath, "mem.prof"))
|
||||
|
@ -271,29 +275,36 @@ func (b *writeBenchmark) startProfiling() {
|
|||
runtime.SetMutexProfileFraction(20)
|
||||
}
|
||||
|
||||
func (b *writeBenchmark) stopProfiling() {
|
||||
func (b *writeBenchmark) stopProfiling() error {
|
||||
if b.cpuprof != nil {
|
||||
pprof.StopCPUProfile()
|
||||
b.cpuprof.Close()
|
||||
b.cpuprof = nil
|
||||
}
|
||||
if b.memprof != nil {
|
||||
pprof.Lookup("heap").WriteTo(b.memprof, 0)
|
||||
if err := pprof.Lookup("heap").WriteTo(b.memprof, 0); err != nil {
|
||||
return fmt.Errorf("error writing mem profile: %v", err)
|
||||
}
|
||||
b.memprof.Close()
|
||||
b.memprof = nil
|
||||
}
|
||||
if b.blockprof != nil {
|
||||
pprof.Lookup("block").WriteTo(b.blockprof, 0)
|
||||
if err := pprof.Lookup("block").WriteTo(b.blockprof, 0); err != nil {
|
||||
return fmt.Errorf("error writing block profile: %v", err)
|
||||
}
|
||||
b.blockprof.Close()
|
||||
b.blockprof = nil
|
||||
runtime.SetBlockProfileRate(0)
|
||||
}
|
||||
if b.mtxprof != nil {
|
||||
pprof.Lookup("mutex").WriteTo(b.mtxprof, 0)
|
||||
if err := pprof.Lookup("mutex").WriteTo(b.mtxprof, 0); err != nil {
|
||||
return fmt.Errorf("error writing mutex profile: %v", err)
|
||||
}
|
||||
b.mtxprof.Close()
|
||||
b.mtxprof = nil
|
||||
runtime.SetMutexProfileFraction(0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func measureTime(stage string, f func()) time.Duration {
|
||||
|
|
|
@ -626,7 +626,9 @@ func (c *LeveledCompactor) populateBlock(blocks []BlockReader, meta *BlockMeta,
|
|||
}
|
||||
|
||||
for _, chk := range chks {
|
||||
c.chunkPool.Put(chk.Chunk)
|
||||
if err := c.chunkPool.Put(chk.Chunk); err != nil {
|
||||
return errors.Wrap(err, "put chunk")
|
||||
}
|
||||
}
|
||||
|
||||
for _, l := range lset {
|
||||
|
|
7
head.go
7
head.go
|
@ -793,7 +793,7 @@ func (h *Head) gc() {
|
|||
symbols := make(map[string]struct{})
|
||||
values := make(map[string]stringset, len(h.values))
|
||||
|
||||
h.postings.Iter(func(t labels.Label, _ index.Postings) error {
|
||||
if err := h.postings.Iter(func(t labels.Label, _ index.Postings) error {
|
||||
symbols[t.Name] = struct{}{}
|
||||
symbols[t.Value] = struct{}{}
|
||||
|
||||
|
@ -804,7 +804,10 @@ func (h *Head) gc() {
|
|||
}
|
||||
ss.set(t.Value)
|
||||
return nil
|
||||
})
|
||||
}); err != nil {
|
||||
// This should never happen, as the iteration function only returns nil.
|
||||
panic(err)
|
||||
}
|
||||
|
||||
h.symMtx.Lock()
|
||||
|
||||
|
|
|
@ -271,7 +271,9 @@ func (w *Writer) AddSeries(ref uint64, lset labels.Labels, chunks ...chunks.Meta
|
|||
}
|
||||
// We add padding to 16 bytes to increase the addressable space we get through 4 byte
|
||||
// series references.
|
||||
w.addPadding(16)
|
||||
if err := w.addPadding(16); err != nil {
|
||||
return errors.Errorf("failed to write padding bytes: %v", err)
|
||||
}
|
||||
|
||||
if w.pos%16 != 0 {
|
||||
return errors.Errorf("series write not 16-byte aligned at %d", w.pos)
|
||||
|
|
|
@ -16,12 +16,13 @@ package tsdb
|
|||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const tombstoneFilename = "tombstones"
|
||||
|
@ -72,7 +73,7 @@ func writeTombstoneFile(dir string, tr TombstoneReader) error {
|
|||
|
||||
mw := io.MultiWriter(f, hash)
|
||||
|
||||
tr.Iter(func(ref uint64, ivs Intervals) error {
|
||||
if err := tr.Iter(func(ref uint64, ivs Intervals) error {
|
||||
for _, iv := range ivs {
|
||||
buf.reset()
|
||||
|
||||
|
@ -86,7 +87,9 @@ func writeTombstoneFile(dir string, tr TombstoneReader) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}); err != nil {
|
||||
return fmt.Errorf("error writing tombstones: %v", err)
|
||||
}
|
||||
|
||||
_, err = f.Write(hash.Sum(nil))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue