api/v1: add cache-control header

Summary of Merged Pull Request: api/v1: add cache-control header

Author: Giedrius Statkevičius
Date: January 10, 2020
Related Issue: Works in conjunction with Cortex Query Frontend (see cortexproject/cortex#1974)

Overview:
This Pull Request introduces functionality to set a Cache-Control header in the HTTP responses of the Thanos API v1. Specifically, the header is set to no-store in the presence of warnings during query execution. This approach ensures that partial responses or responses with errors are not cached, enhancing the integrity of cached data.

Key Changes:

  • In pkg/query/api/v1.go:
    • The Respond function was modified to include a check for warnings. If warnings exist, it sets the Cache-Control header to no-store.
    • Similarly, the RespondError function was updated to ensure that error responses also include the no-store directive.

Testing:
The change was tested by intentionally causing warnings by disabling one of the sidecars. It was observed that the Cortex Query Frontend did not cache the responses under these conditions, validating the effectiveness of the header’s addition.

Notes:
The author humorously noted the unexpected positive feedback while indicating a slight delay in addressing the draft status of the PR.

This change contributes to the robustness of response handling in Thanos, especially under error conditions, aligning caching behavior with expected operational integrity.