Skip to content

Commit

Permalink
Merge pull request grafana#1036 from cortexproject/print-chunk-error-id
Browse files Browse the repository at this point in the history
Include the chunk ID that caused an error
  • Loading branch information
tomwilkie committed Sep 28, 2018
2 parents 85c8fce + cf1f4ca commit 08f101e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ import (

// Errors that decode can return
const (
ErrInvalidChunkID = errs.Error("invalid chunk ID")
ErrInvalidChecksum = errs.Error("invalid chunk checksum")
ErrWrongMetadata = errs.Error("wrong chunk metadata")
ErrMetadataLength = errs.Error("chunk metadata wrong length")
)

var castagnoliTable = crc32.MakeTable(crc32.Castagnoli)

func errInvalidChunkID(s string) error {
return errors.Errorf("invalid chunk ID %q", s)
}

// Chunk contains encoded timeseries data
type Chunk struct {
// These two fields will be missing from older chunks (as will the hash).
Expand Down Expand Up @@ -107,7 +110,7 @@ func ParseExternalKey(userID, externalKey string) (Chunk, error) {
func parseLegacyChunkID(userID, key string) (Chunk, error) {
parts := strings.Split(key, ":")
if len(parts) != 3 {
return Chunk{}, errors.WithStack(ErrInvalidChunkID)
return Chunk{}, errInvalidChunkID(key)
}
fingerprint, err := strconv.ParseUint(parts[0], 10, 64)
if err != nil {
Expand All @@ -132,12 +135,12 @@ func parseLegacyChunkID(userID, key string) (Chunk, error) {
func parseNewExternalKey(key string) (Chunk, error) {
parts := strings.Split(key, "/")
if len(parts) != 2 {
return Chunk{}, errors.WithStack(ErrInvalidChunkID)
return Chunk{}, errInvalidChunkID(key)
}
userID := parts[0]
hexParts := strings.Split(parts[1], ":")
if len(hexParts) != 4 {
return Chunk{}, errors.WithStack(ErrInvalidChunkID)
return Chunk{}, errInvalidChunkID(key)
}
fingerprint, err := strconv.ParseUint(hexParts[0], 16, 64)
if err != nil {
Expand Down

0 comments on commit 08f101e

Please sign in to comment.