This is an automated email from the ASF dual-hosted git repository.

zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 3aca8379ae Fix TR logging when cqhv field is absent (#7340)
3aca8379ae is described below

commit 3aca8379aece0508f849b710d84856ad9ffa0d6b
Author: Srijeet Chatterjee <[email protected]>
AuthorDate: Fri Feb 3 16:55:50 2023 -0700

    Fix TR logging when cqhv field is absent (#7340)
    
    * Fix TR logging when cqhv field is absent
    
    * fix changelog
    
    * code review
---
 CHANGELOG.md                                                |  1 +
 .../traffic_router/core/http/HTTPAccessEventBuilder.java    |  2 +-
 .../core/http/HTTPAccessEventBuilderTest.java               | 13 ++++++++++++-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2b90f63b77..4205c4f8b1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -43,6 +43,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.
diff --git 
a/traffic_router/core/src/main/java/org/apache/traffic_control/traffic_router/core/http/HTTPAccessEventBuilder.java
 
b/traffic_router/core/src/main/java/org/apache/traffic_control/traffic_router/core/http/HTTPAccessEventBuilder.java
index cb2f81fad0..c3f7e7963a 100644
--- 
a/traffic_router/core/src/main/java/org/apache/traffic_control/traffic_router/core/http/HTTPAccessEventBuilder.java
+++ 
b/traffic_router/core/src/main/java/org/apache/traffic_control/traffic_router/core/http/HTTPAccessEventBuilder.java
@@ -43,7 +43,7 @@ public class HTTPAccessEventBuilder {
     }
 
     private static String formatObject(final Object o) {
-        return (o == null) ? "-" : o.toString();
+        return (o == null || o.toString().equals("")) ? "-" : o.toString();
     }
 
     private static String formatRequestHeaders(final Map<String, String> 
requestHeaders) {
diff --git 
a/traffic_router/core/src/test/java/org/apache/traffic_control/traffic_router/core/http/HTTPAccessEventBuilderTest.java
 
b/traffic_router/core/src/test/java/org/apache/traffic_control/traffic_router/core/http/HTTPAccessEventBuilderTest.java
index d999eeaff1..adc0ff957c 100644
--- 
a/traffic_router/core/src/test/java/org/apache/traffic_control/traffic_router/core/http/HTTPAccessEventBuilderTest.java
+++ 
b/traffic_router/core/src/test/java/org/apache/traffic_control/traffic_router/core/http/HTTPAccessEventBuilderTest.java
@@ -79,10 +79,21 @@ public class HTTPAccessEventBuilderTest {
         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>() {

Reply via email to