-
Notifications
You must be signed in to change notification settings - Fork 871
Logging: add cache freshness fields #13417
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -2139,6 +2139,9 @@ HttpTransact::HandleRequestAuthorized(State *s) | |
| void | ||
| HttpTransact::DecideCacheLookup(State *s) | ||
| { | ||
| s->cache_info.freshness_limit = -1; | ||
| s->cache_info.current_age = -1; | ||
|
|
||
| // Check if a client request is lookupable. | ||
| if (s->redirect_info.redirect_in_process) { | ||
| // for redirect, we want to skip cache lookup and write into | ||
|
|
@@ -3059,6 +3062,7 @@ HttpTransact::build_response_from_cache(State *s, HTTPWarningCode warning_code) | |
| obj = s->cache_info.object_read; | ||
| } | ||
| cached_response = obj->response_get(); | ||
| set_cache_freshness_info(s, cached_response, obj->request_sent_time_get(), obj->response_received_time_get(), true); | ||
|
Contributor
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. These should use
There is also a problem on the Passing |
||
|
|
||
| // If the client request is conditional, and the cached copy meets | ||
| // the conditions, do not need to send back the full document, | ||
|
|
@@ -4835,6 +4839,7 @@ HttpTransact::handle_cache_operation_on_forward_server_response(State *s) | |
| // unset warning revalidation failed header if it set | ||
| // (potentially added by negative revalidating) | ||
| delete_warning_value(base_response, HTTPWarningCode::REVALIDATION_FAILED); | ||
| set_cache_freshness_info(s, base_response, s->request_sent_time, s->response_received_time, true); | ||
|
Contributor
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. This call is skipped by the negative revalidation path earlier in the function. That branch sets Those transactions serve the stale cached object and extend its stored |
||
| } | ||
| ink_assert(base_response->valid()); | ||
|
|
||
|
|
@@ -5223,6 +5228,8 @@ HttpTransact::set_headers_for_cache_write(State *s, HTTPInfo *cache_info, HTTPHd | |
| cache_info->response_get()->field_delete(static_cast<std::string_view>(MIME_FIELD_WWW_AUTHENTICATE)); | ||
| } | ||
|
|
||
| set_cache_freshness_info(s, cache_info->response_get(), s->request_sent_time, s->response_received_time, false); | ||
|
|
||
| dump_header(dbg_ctl_http_hdrs, cache_info->request_get(), s->state_machine_id(), "Cached Request Hdr"); | ||
| } | ||
|
|
||
|
|
@@ -7510,6 +7517,20 @@ HttpTransact::calculate_document_freshness_limit(State *s, HTTPHdr *response, ti | |
| return (freshness_limit); | ||
| } | ||
|
|
||
| void | ||
| HttpTransact::set_cache_freshness_info(State *s, HTTPHdr *response, ink_time_t request_time, ink_time_t response_time, | ||
| bool include_current_age) | ||
| { | ||
| bool heuristic = false; | ||
| ink_time_t response_date = response->get_date(); | ||
|
|
||
| s->cache_info.freshness_limit = calculate_document_freshness_limit(s, response, response_date, &heuristic); | ||
| if (include_current_age) { | ||
| s->cache_info.current_age = | ||
| HttpTransactCache::calculate_document_age(request_time, response_time, response, response_date, s->current.now); | ||
| } | ||
| } | ||
|
|
||
| ////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| ''' | ||
| Verify the cache freshness limit and current age log fields. | ||
| ''' | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| Test.Summary = 'Verify cache freshness limit and current age log fields' | ||
|
|
||
| traffic_run = Test.ATSReplayTest(replay_file='replay/cache-freshness-fields.replay.yaml') | ||
| ts = traffic_run.Processes.ts | ||
| log_path = os.path.join(ts.Variables.LOGDIR, 'cache_freshness_fields.log') | ||
|
|
||
| Test.AddAwaitFileContainsTestRun( | ||
| 'Wait for cache freshness log output', | ||
| log_path, | ||
| r'^uncacheable ', | ||
| ) | ||
|
|
||
| validation_run = Test.AddTestRun('Validate cache freshness log fields') | ||
| validation_script = os.path.join(Test.TestDirectory, 'verify_cache_freshness_fields.py') | ||
| validation_run.Processes.Default.Command = f'{sys.executable} {validation_script} {log_path}' | ||
| validation_run.Processes.Default.ReturnCode = 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| meta: | ||
| version: "1.0" | ||
|
|
||
| autest: | ||
| description: 'Exercise cache freshness logging for writes, hits, and non-cacheable responses' | ||
|
|
||
| dns: | ||
| name: dns | ||
|
|
||
| server: | ||
| name: server | ||
|
|
||
| client: | ||
| name: client | ||
|
|
||
| ats: | ||
| name: ts | ||
| process_config: | ||
| enable_cache: true | ||
|
|
||
| records_config: | ||
| proxy.config.http.cache.http: 1 | ||
| proxy.config.http.insert_age_in_response: 0 | ||
| proxy.config.log.max_secs_per_buffer: 1 | ||
|
|
||
| remap_config: | ||
| - from: "http://example.com/" | ||
| to: "http://backend.example.com:{SERVER_HTTP_PORT}/" | ||
|
|
||
| logging_yaml: | ||
| logging: | ||
| formats: | ||
| - name: cache_freshness_fields | ||
| format: '%<{uuid}cqh> %<cfl> %<cca> %<crc>' | ||
| logs: | ||
| - filename: cache_freshness_fields | ||
| format: cache_freshness_fields | ||
| mode: ascii | ||
|
|
||
| sessions: | ||
| - transactions: | ||
| - client-request: | ||
| method: GET | ||
| url: /cacheable | ||
| version: '1.1' | ||
| headers: | ||
| fields: | ||
| - [Host, example.com] | ||
| - [uuid, cache-write] | ||
|
|
||
| server-response: | ||
| status: 200 | ||
| reason: OK | ||
| headers: | ||
| fields: | ||
| - [Content-Length, 4] | ||
| - [Cache-Control, "max-age=60"] | ||
| - [Age, 7] | ||
| content: | ||
| encoding: plain | ||
| data: body | ||
|
|
||
| proxy-response: | ||
| status: 200 | ||
| content: | ||
| encoding: plain | ||
| data: body | ||
| verify: {as: equal} | ||
|
|
||
| - client-request: | ||
| delay: 100ms | ||
| method: GET | ||
| url: /cacheable | ||
| version: '1.1' | ||
| headers: | ||
| fields: | ||
| - [Host, example.com] | ||
| - [uuid, cache-hit] | ||
|
|
||
| proxy-request: | ||
| expect: absent | ||
|
|
||
| server-response: | ||
| status: 500 | ||
| reason: Not Used | ||
|
|
||
| proxy-response: | ||
| status: 200 | ||
| content: | ||
| encoding: plain | ||
| data: body | ||
| verify: {as: equal} | ||
|
|
||
| - client-request: | ||
| method: GET | ||
| url: /uncacheable | ||
| version: '1.1' | ||
| headers: | ||
| fields: | ||
| - [Host, example.com] | ||
| - [uuid, uncacheable] | ||
|
|
||
| server-response: | ||
| status: 200 | ||
| reason: OK | ||
| headers: | ||
| fields: | ||
| - [Content-Length, 4] | ||
| - [Cache-Control, no-store] | ||
| content: | ||
| encoding: plain | ||
| data: body | ||
|
|
||
| proxy-response: | ||
| status: 200 | ||
| content: | ||
| encoding: plain | ||
| data: body | ||
| verify: {as: equal} |
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.
"the effective cache configuration" is broader than what
calculate_document_freshness_limit()currently includes.The calculation uses the response headers plus
guaranteed_min/max_lifetimeandheuristic_min/max_lifetime, but nots->cache_control. That excludescache.configdirectives such asttl-in-cacheandrevalidate-after.For example, with
ttl-in-cache=300and an origin response containingmax-age=1, a hit at age 3 logscfl=1 cca=3.