-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TempoDB: Restrict Ingestion time range #1332
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,9 @@ const maxDataEncodingLength = 32 | |
// AppendBlock is a block that is actively used to append new objects to. It stores all data in the appendFile | ||
// in the order it was received and an in memory sorted index. | ||
type AppendBlock struct { | ||
meta *backend.BlockMeta | ||
encoding encoding.VersionedEncoding | ||
meta *backend.BlockMeta | ||
encoding encoding.VersionedEncoding | ||
ingestionSlack time.Duration | ||
|
||
appendFile *os.File | ||
appender encoding.Appender | ||
|
@@ -32,7 +33,7 @@ type AppendBlock struct { | |
once sync.Once | ||
} | ||
|
||
func newAppendBlock(id uuid.UUID, tenantID string, filepath string, e backend.Encoding, dataEncoding string) (*AppendBlock, error) { | ||
func newAppendBlock(id uuid.UUID, tenantID string, filepath string, e backend.Encoding, dataEncoding string, ingestionSlack time.Duration) (*AppendBlock, error) { | ||
if strings.ContainsRune(dataEncoding, ':') || | ||
len([]rune(dataEncoding)) > maxDataEncodingLength { | ||
return nil, fmt.Errorf("dataEncoding %s is invalid", dataEncoding) | ||
|
@@ -44,9 +45,10 @@ func newAppendBlock(id uuid.UUID, tenantID string, filepath string, e backend.En | |
} | ||
|
||
h := &AppendBlock{ | ||
encoding: v, | ||
meta: backend.NewBlockMeta(tenantID, id, v.Version(), e, dataEncoding), | ||
filepath: filepath, | ||
encoding: v, | ||
meta: backend.NewBlockMeta(tenantID, id, v.Version(), e, dataEncoding), | ||
filepath: filepath, | ||
ingestionSlack: ingestionSlack, | ||
} | ||
|
||
name := h.fullFilename() | ||
|
@@ -69,7 +71,7 @@ func newAppendBlock(id uuid.UUID, tenantID string, filepath string, e backend.En | |
|
||
// newAppendBlockFromFile returns an AppendBlock that can not be appended to, but can | ||
// be completed. It can return a warning or a fatal error | ||
func newAppendBlockFromFile(filename string, path string, fn RangeFunc) (*AppendBlock, error, error) { | ||
func newAppendBlockFromFile(filename string, path string, ingestionSlack time.Duration, additionalStartSlack time.Duration, fn RangeFunc) (*AppendBlock, error, error) { | ||
var warning error | ||
blockID, tenantID, version, e, dataEncoding, err := ParseFilename(filename) | ||
if err != nil { | ||
|
@@ -82,9 +84,10 @@ func newAppendBlockFromFile(filename string, path string, fn RangeFunc) (*Append | |
} | ||
|
||
b := &AppendBlock{ | ||
meta: backend.NewBlockMeta(tenantID, blockID, version, e, dataEncoding), | ||
filepath: path, | ||
encoding: v, | ||
meta: backend.NewBlockMeta(tenantID, blockID, version, e, dataEncoding), | ||
filepath: path, | ||
encoding: v, | ||
ingestionSlack: ingestionSlack, | ||
} | ||
|
||
// replay file to extract records | ||
|
@@ -101,6 +104,7 @@ func newAppendBlockFromFile(filename string, path string, fn RangeFunc) (*Append | |
if err != nil { | ||
return err | ||
} | ||
start, end = b.adjustTimeRangeForSlack(start, end, additionalStartSlack) | ||
if start < blockStart { | ||
blockStart = start | ||
} | ||
|
@@ -128,6 +132,7 @@ func (a *AppendBlock) Append(id common.ID, b []byte, start, end uint32) error { | |
if err != nil { | ||
return err | ||
} | ||
start, end = a.adjustTimeRangeForSlack(start, end, 0) | ||
a.meta.ObjectAdded(id, start, end) | ||
return nil | ||
} | ||
|
@@ -238,3 +243,25 @@ func (a *AppendBlock) file() (*os.File, error) { | |
|
||
return a.readFile, err | ||
} | ||
|
||
func (a *AppendBlock) adjustTimeRangeForSlack(start uint32, end uint32, additionalStartSlack time.Duration) (uint32, uint32) { | ||
now := time.Now() | ||
startOfRange := uint32(now.Add(-a.ingestionSlack).Add(-additionalStartSlack).Unix()) | ||
endOfRange := uint32(now.Add(a.ingestionSlack).Unix()) | ||
|
||
warn := false | ||
if start < startOfRange { | ||
warn = true | ||
start = uint32(now.Unix()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these clip to the range instead of now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I decided to do use If we use |
||
} | ||
if end > endOfRange { | ||
warn = true | ||
end = uint32(now.Unix()) | ||
} | ||
|
||
if warn { | ||
metricWarnings.WithLabelValues(a.meta.TenantID, reasonOutsideIngestionSlack).Inc() | ||
} | ||
|
||
return start, end | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah agree this is a hard spot but understand the reasons, and this is reasonable. Maybe a comment ?