Skip to content
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

Fix TR logging when cqhv field is absent #7340

Merged
merged 4 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7044](https://github.com/apache/trafficcontrol/issues/7044) *CDN in a Box* [CDN in a Box, the t3c integration tests, and the tc health client integration tests now use Apache Traffic Server 9.1.

### Fixed
- [#7340](https://github.com/apache/trafficcontrol/pull/7340) *Traffic Router* Fixed TR logging for the `cqhv` field when absent.
- [#5557](https://github.com/apache/trafficcontrol/issues/5557) *Traffic Portal* Moved `Fair Queueing Pacing Rate Bps` DS field to `Cache Configuration Settings` section.
- [#7252](https://github.com/apache/trafficcontrol/issues/7252) *Traffic Router* Fixed integer overflow for `czCount`, by resetting the count to max value when it overflows.
- [#7221](https://github.com/apache/trafficcontrol/issues/7221) *Docs* Fixed request structure spec in cdn locks description in APIv4.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ private static String formatRequestHeaders(final Map<String, String> requestHead
return stringBuilder.toString();
}

private static boolean validProtocol(final String protocol) {
if (protocol != null &&
!protocol.equals("")) {
return true;
}
return false;
}

@SuppressWarnings({"PMD.UseStringBufferForStringAppends", "PMD.NPathComplexity"})
public static String create(final HTTPAccessRecord httpAccessRecord) {
final long start = httpAccessRecord.getRequestDate().getTime();
Expand All @@ -84,7 +92,11 @@ public static String create(final HTTPAccessRecord httpAccessRecord) {
String chi = formatObject(httpServletRequest.getRemoteAddr());
final String url = formatRequest(httpServletRequest);
final String cqhm = formatObject(httpServletRequest.getMethod());
final String cqhv = formatObject(httpServletRequest.getProtocol());
String cqhv = "-";
final String protocol = formatObject(httpServletRequest.getProtocol());
if (validProtocol(protocol)) {
cqhv = protocol;
}
srijeet0406 marked this conversation as resolved.
Show resolved Hide resolved

final String resultType = formatObject(httpAccessRecord.getResultType());
final String rerr = formatObject(httpAccessRecord.getRerr());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,21 @@ public void itGeneratesAccessEvents() throws Exception {
HTTPAccessRecord httpAccessRecord = builder.build();

String httpAccessEvent = HTTPAccessEventBuilder.create(httpAccessRecord);

assertThat(httpAccessEvent, equalTo("144140678.000 qtype=HTTP chi=192.168.7.6 rhi=- url=\"http://example.com/index.html?foo=bar\" cqhm=GET cqhv=HTTP/1.1 rtype=- rloc=\"-\" rdtl=- rerr=\"-\" rgb=\"-\" rurl=\"-\" rurls=\"-\" uas=\"null\" svc=\"-\" rh=\"-\""));
}

@Test
public void itGeneratesAccessEventsWithCorrectCqhvDefaultValues() throws Exception {
HTTPAccessRecord.Builder builder = new HTTPAccessRecord.Builder(new Date(144140678000L), request);
HTTPAccessRecord httpAccessRecord = builder.build();
when(request.getProtocol()).thenReturn(null);
String httpAccessEvent = HTTPAccessEventBuilder.create(httpAccessRecord);
assertThat(httpAccessEvent, equalTo("144140678.000 qtype=HTTP chi=192.168.7.6 rhi=- url=\"http://example.com/index.html?foo=bar\" cqhm=GET cqhv=- rtype=- rloc=\"-\" rdtl=- rerr=\"-\" rgb=\"-\" rurl=\"-\" rurls=\"-\" uas=\"null\" svc=\"-\" rh=\"-\""));
when(request.getProtocol()).thenReturn("");
httpAccessEvent = HTTPAccessEventBuilder.create(httpAccessRecord);
assertThat(httpAccessEvent, equalTo("144140678.000 qtype=HTTP chi=192.168.7.6 rhi=- url=\"http://example.com/index.html?foo=bar\" cqhm=GET cqhv=- rtype=- rloc=\"-\" rdtl=- rerr=\"-\" rgb=\"-\" rurl=\"-\" rurls=\"-\" uas=\"null\" svc=\"-\" rh=\"-\""));
}

@Test
public void itAddsResponseData() throws Exception {
Answer<Long> nanoTimeAnswer = new Answer<Long>() {
Expand Down