cortex icon indicating copy to clipboard operation
cortex copied to clipboard

Ingestion can be impacted by poison messages

Open khaines opened this issue 8 years ago • 9 comments

Note: This was only found when using the Dynamo storage layer. We haven't tested this against the other backends.

During some of our testing as we add more different data sources to our cortex installations, we found that it was possible to send in time series that had incredibly large names. The resulting timeseries and its chunks could not be flushed to the storage layer due to ValidationException errors thrown from dynamo due to the hash being larger than 2KB.

The primary issue is that this data is retried indefinitely in the flushLoop function of the ingester if the immediate field of the operation is set to true. The flushing of the ingester is a bit naive here and that should be ok if the ingester (or distributor) validated that the incoming sample timeseries met the constraints for storage.

I'm having a look at doing a fix and will start a WIP PR once I have something more than a few paragraphs of text. But a few statements I'm thinking about regarding behaviour here:

  • Validation and similar errors from a storage layer should never be retried. It seems futile to do anything other than drop the data at that point. Logging an event about the data & user might be useful for tracking or reporting
  • ~~Data that doesn't meet the constraints of the storage layer should be rejected ideally by the Ingester or Distributor, so that the sending party can be given an error. This way we are transparent in the action of rejecting/dropping the data, vs doing it behind the scenes in the background.~~

khaines avatar Mar 25 '18 01:03 khaines

Going over the telemetry logs again from our test runs, there is validation happening in the ingester, as I do see "label value too long" errors. However there might be a gap between what this validation checks and what results in a hash key being larger than 2KB for writes to dynamo.

khaines avatar Mar 25 '18 04:03 khaines

ValidationException errors thrown from dynamo due to the hash being larger than 2KB.

Oh dear; the limit on metric name was supposed to prevent this. But yeah, DynamoDB limit is 2k [1] and we limit to 4k [2]. So I think it would make sense to reduce our limit to 2k.

[1] https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-partition-sort-keys [2] https://github.com/weaveworks/cortex/blob/master/pkg/util/validate.go#L12:2

tomwilkie avatar Mar 25 '18 21:03 tomwilkie

Strikes me that values over a hundred bytes or so are Doing It Wrong.

bboreham avatar Mar 26 '18 09:03 bboreham

Validation and similar errors from a storage layer should never be retried.

Note that we currently rely on ProvisionedThroughputExceeded errors being retried from the ingester flush loop.

It would be more efficient if the storage layer could just carry on retrying them, but we'd need some extra mechanism to stop the flush loop initiating a whole new write of the same chunks.

bboreham avatar Mar 26 '18 15:03 bboreham

See also #578

bboreham avatar Mar 26 '18 16:03 bboreham

The logic in the storage_client for aws @ [1] is to retry ProvisionedThroughputExceeded or other errors marked as retryable. This is done internally with in the storage client instance itself and it considers everything else as critical.

However the errors sent back by the storage_client, will work its way back up to the stack and reach [2] in the ingester. Regardless of the error type here, if the operation was marked as Immediate, the flush is put back on the queue for processing. Thus, the vicious and endless cycle of flush, fail and enqueue begins.

@tomwilkie thanks for pointing out the constraints in the testing. That should make it easy to update to more tolerable levels. However, I have not had a chance to look at how this would impact users of BigTable. The limits there are larger than AWS?

@bboreham I completely agree that it would seem rather silly to have metrics more than a hundred bytes in length. While the hard limit for dynamo is 2KB (other TBD), perhaps something to be done in a different change is to add an optional limit, similar to https://github.com/weaveworks/cortex/pull/578, but for the maxlength of a label/metric name vs the number of labels.

[1] https://github.com/weaveworks/cortex/blob/master/pkg/chunk/aws/storage_client.go#L230 [2] https://github.com/weaveworks/cortex/blob/master/pkg/ingester/ingester_flush.go#L141

khaines avatar Mar 27 '18 02:03 khaines

Looking over the hash column for the index table, perhaps even capping the metric name or label value to 2048 will not be enough. The hashkey column has both potentially the metric name and the label name in there, plus some other data items. So the total for this column needs to be <=2048.

The only way to ensure this is going to fit in the column is perhaps to have even more strict constraints on the length limits for metric and label names, once the constant sized items are accounted for in the hashkey.

thoughts?

khaines avatar Mar 27 '18 03:03 khaines

What is left to do here, after #773 ?

bboreham avatar Jun 20 '18 12:06 bboreham

I believe this can be closed now. I will do so and if someone objects or has another scenario we haven't corrected, we can reopen this.

khaines avatar Jun 24 '18 16:06 khaines