-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes out of order samples handling (#1563)
* Fixes out of order samples handling Signed-off-by: Devin Trejo <[email protected]> * Ignore errcheck for rollback Signed-off-by: Devin Trejo <[email protected]> * Process all valid samples in remote-write call Signed-off-by: Devin Trejo <[email protected]> * pkg/receive: surface conflict error This commit adds support to the receive component to identify if a failed request is due to an ErrOutOfOrderSample error. If a request is determined to have failed due to this reason, the handler responds with a 409 Conflict status. Fixes: #1509 Signed-off-by: Lucas Servén Marín <[email protected]> * Remove rollback from errcheck exclude Signed-off-by: Devin Trejo <[email protected]> * Return conflict for duplicate samples Signed-off-by: Devin Trejo <[email protected]> * Summarize any fast-add errors rather than logging every occurrence of the error. Signed-off-by: Devin Trejo <[email protected]>
- Loading branch information
Showing
3 changed files
with
168 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package receive | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/prometheus/prometheus/storage" | ||
terrors "github.com/prometheus/prometheus/tsdb/errors" | ||
) | ||
|
||
func TestHasCause(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
err error | ||
f func(error) bool | ||
out bool | ||
}{ | ||
{ | ||
name: "nil", | ||
f: isConflict, | ||
out: false, | ||
}, | ||
{ | ||
name: "nil multierror", | ||
err: terrors.MultiError([]error{}), | ||
f: isConflict, | ||
out: false, | ||
}, | ||
{ | ||
name: "non-matching multierror", | ||
err: terrors.MultiError([]error{ | ||
errors.New("foo"), | ||
errors.New("bar"), | ||
}), | ||
f: isConflict, | ||
out: false, | ||
}, | ||
{ | ||
name: "nested non-matching multierror", | ||
err: errors.Wrap(terrors.MultiError([]error{ | ||
errors.New("foo"), | ||
errors.New("bar"), | ||
}), "baz"), | ||
f: isConflict, | ||
out: false, | ||
}, | ||
{ | ||
name: "deep nested non-matching multierror", | ||
err: errors.Wrap(terrors.MultiError([]error{ | ||
errors.New("foo"), | ||
terrors.MultiError([]error{ | ||
errors.New("bar"), | ||
errors.New("qux"), | ||
}), | ||
}), "baz"), | ||
f: isConflict, | ||
out: false, | ||
}, | ||
{ | ||
name: "matching multierror", | ||
err: terrors.MultiError([]error{ | ||
storage.ErrOutOfOrderSample, | ||
errors.New("foo"), | ||
errors.New("bar"), | ||
}), | ||
f: isConflict, | ||
out: true, | ||
}, | ||
{ | ||
name: "nested matching multierror", | ||
err: errors.Wrap(terrors.MultiError([]error{ | ||
storage.ErrOutOfOrderSample, | ||
errors.New("foo"), | ||
errors.New("bar"), | ||
}), "baz"), | ||
f: isConflict, | ||
out: true, | ||
}, | ||
{ | ||
name: "deep nested matching multierror", | ||
err: errors.Wrap(terrors.MultiError([]error{ | ||
terrors.MultiError([]error{ | ||
errors.New("qux"), | ||
errors.New(strconv.Itoa(http.StatusConflict)), | ||
}), | ||
errors.New("foo"), | ||
errors.New("bar"), | ||
}), "baz"), | ||
f: isConflict, | ||
out: true, | ||
}, | ||
} { | ||
if hasCause(tc.err, tc.f) != tc.out { | ||
t.Errorf("test case %s: expected %t, got %t", tc.name, tc.out, !tc.out) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters