Browse code

c-rest-engine: INFO level logging patch for detecting requests

Change-Id: I34c17d86d51e22b9835f55ed0ce9eda1c730d233
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/4529
Reviewed-by: Kumar Kaushik <kaushikk@vmware.com>
Tested-by: Kumar Kaushik <kaushikk@vmware.com>

Kumar Kaushik authored on 2017/12/16 12:09:02
Showing 2 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 Name:          c-rest-engine
2 2
 Summary:       minimal http(s) server library
3 3
 Version:       1.1
4
-Release:       6%{?dist}
4
+Release:       7%{?dist}
5 5
 Group:         Applications/System
6 6
 Vendor:        VMware, Inc.
7 7
 License:       Apache 2.0
... ...
@@ -17,6 +17,7 @@ Patch1:        syslog_noInit.patch
17 17
 Patch2:        socket_logging.patch
18 18
 Patch3:        errno_init.patch
19 19
 Patch4:        ssl_shutdown.patch
20
+Patch5:        minimal_request_logging.patch
20 21
 %define sha1   c-rest-engine=a25927fd98ec92df5e210cc4941fa626604636f6
21 22
 
22 23
 %description
... ...
@@ -40,6 +41,7 @@ development libs and header files for c-rest-engine
40 40
 %patch2 -p1
41 41
 %patch3 -p1
42 42
 %patch4 -p1
43
+%patch5 -p1
43 44
 
44 45
 %build
45 46
 cd build
... ...
@@ -72,6 +74,8 @@ find %{buildroot} -name '*.la' -delete
72 72
 # %doc ChangeLog README COPYING
73 73
 
74 74
 %changelog
75
+*  Fri Dec 15 2017 Kumar Kaushik <kaushikk@vmware.com> 1.1-7
76
+-  Adding patch for minimal packet level logging.
75 77
 *  Wed Nov 29 2017 Kumar Kaushik <kaushikk@vmware.com> 1.1-6
76 78
 -  Adding patch for ssl_shutdown order.
77 79
 *  Wed Nov 29 2017 Kumar Kaushik <kaushikk@vmware.com> 1.1-5
78 80
new file mode 100644
... ...
@@ -0,0 +1,180 @@
0
+From 3fbf376fe21d544bfe1373c17369fd8f916813da Mon Sep 17 00:00:00 2001
1
+From: Kumar Kaushik <kaushikk@vmware.com>
2
+Date: Fri, 15 Dec 2017 18:36:44 -0800
3
+Subject: [PATCH] Adding minimal INFO level packet trace logging
4
+
5
+Change-Id: I932706c8446b44c70aa8a015852e28a65f0b4a16
6
+(cherry picked from commit 305dda1d5e242dd78f3e867232e6f0247b8fdf10)
7
+---
8
+ server/restengine/httpProtocolHead.c  | 19 ++++++++++++++++---
9
+ server/restengine/httpUtilsExternal.c |  4 ++--
10
+ server/restengine/restProtocolHead.c  |  2 +-
11
+ transport/posix/socket.c              |  6 ++++++
12
+ 4 files changed, 25 insertions(+), 6 deletions(-)
13
+
14
+diff --git a/server/restengine/httpProtocolHead.c b/server/restengine/httpProtocolHead.c
15
+index 0a1e5e5..18cff08 100644
16
+--- a/server/restengine/httpProtocolHead.c
17
+@@ -598,6 +598,7 @@ VmRESTSendHeader(
18
+             );
19
+         buffer = NULL;
20
+     }
21
++    VMREST_LOG_ERROR(pRESTHandle,"%s","Sending header data failed");
22
+     goto cleanup;
23
+ }
24
+ 
25
+@@ -669,6 +670,7 @@ VmRESTSendChunkedPayload(
26
+             );
27
+         buffer = NULL;
28
+     }
29
++    VMREST_LOG_ERROR(pRESTHandle,"%s","Sending chunked payload data failed");
30
+     goto cleanup;
31
+ }
32
+ 
33
+@@ -777,6 +779,7 @@ VmRESTSendHeaderAndPayload(
34
+             );
35
+         buffer = NULL;
36
+     }
37
++    VMREST_LOG_ERROR(pRESTHandle,"%s","Sending header and payload data failed");
38
+     goto cleanup;
39
+ }
40
+ 
41
+@@ -1209,6 +1212,7 @@ VmRESTProcessHeaders(
42
+     {
43
+         *nProcessed = 0;
44
+     }
45
++    VMREST_LOG_ERROR(pRESTHandle,"Failed while processing headers... dwError %u", dwError);
46
+     goto cleanup;
47
+ 
48
+ }
49
+@@ -1313,13 +1317,15 @@ VmRESTProcessPayload(
50
+     return dwError;
51
+ 
52
+ error:
53
+-    VMREST_LOG_ERROR(pRESTHandle,"Errorcode %u", dwError);
54
+-
55
+     if (dwError == REST_ENGINE_MORE_IO_REQUIRED)
56
+     {
57
+         *nProcessed = 0;
58
+         dwError = REST_ENGINE_SUCCESS;
59
+     }
60
++    else
61
++    {
62
++        VMREST_LOG_ERROR(pRESTHandle,"Failed while processing payload ... dwError %u", dwError);
63
++    }
64
+     goto cleanup;
65
+ 
66
+ }
67
+@@ -1396,12 +1402,17 @@ VmRESTProcessBuffer(
68
+ 
69
+              case PROCESS_APPLICATION_CALLBACK:
70
+                  /**** Give callback to application ****/
71
+-                 VMREST_LOG_DEBUG(pRESTHandle,"%s","Giving callback to application...");
72
++                 VMREST_LOG_INFO(pRESTHandle,"%s","C-REST-ENGINE: Giving callback to application...");
73
+                  dwError = VmRESTTriggerAppCb(
74
+                                pRESTHandle,
75
+                                pRequest,
76
+                                &(pRequest->pResponse)
77
+                                );
78
++                 VMREST_LOG_INFO(pRESTHandle,"C-REST-ENGINE: Application callback returns dwError %u", dwError);
79
++                 if ((dwError != REST_ENGINE_SUCCESS) && pRequest && pRequest->pResponse && pRequest->pResponse->statusLine)
80
++                 {
81
++                     VMREST_LOG_INFO(pRESTHandle,"C-REST-ENGINE: Status code: %s, header sent %d", pRequest->pResponse->statusLine->statusCode, pRequest->pResponse->bHeaderSent);
82
++                 }
83
+                  BAIL_ON_VMREST_ERROR(dwError);
84
+                  bInitiateClose = TRUE;
85
+                  break;
86
+@@ -1428,6 +1439,7 @@ VmRESTProcessBuffer(
87
+ 
88
+ error:
89
+ 
90
++    VMREST_LOG_ERROR(pRESTHandle,"Process buffer failed with error code %u, sending failure response", dwError);
91
+     ret = VmRESTSendFailureResponse(
92
+                   pRESTHandle,
93
+                   dwError,
94
+@@ -1475,6 +1487,7 @@ VmRESTTriggerAppCb(
95
+         dwError = VMREST_APPLICATION_VALIDATION_FAILED;
96
+     }
97
+     BAIL_ON_VMREST_ERROR(dwError);
98
++    
99
+ 
100
+     pRequest->state = PROCESS_INVALID;
101
+ 
102
+diff --git a/server/restengine/httpUtilsExternal.c b/server/restengine/httpUtilsExternal.c
103
+index b75756d..a9e9222 100644
104
+--- a/server/restengine/httpUtilsExternal.c
105
+@@ -258,7 +258,7 @@ VmRESTGetHttpPayload(
106
+ 
107
+     return dwError;
108
+ error:
109
+-
110
++    VMREST_LOG_ERROR(pRESTHandle,"Get payload failed with error code %u", dwError);
111
+     goto cleanup;
112
+ 
113
+ }
114
+@@ -375,7 +375,7 @@ VmRESTSetHttpPayload(
115
+ cleanup:
116
+     return dwError;
117
+ error:
118
+-    VMREST_LOG_ERROR(pRESTHandle,"%s","Set Payload Failed");
119
++    VMREST_LOG_ERROR(pRESTHandle,"Set Payload Failed with error Code %u", dwError);
120
+     goto cleanup;
121
+ }
122
+ 
123
+diff --git a/server/restengine/restProtocolHead.c b/server/restengine/restProtocolHead.c
124
+index 0446d1a..53a5864 100644
125
+--- a/server/restengine/restProtocolHead.c
126
+@@ -76,7 +76,7 @@ VmRestEngineHandler(
127
+         ptr = NULL;
128
+     }
129
+ 
130
+-    VMREST_LOG_DEBUG(pRESTHandle,"HTTP URI %s", httpURI);
131
++    VMREST_LOG_INFO(pRESTHandle,"C-REST-ENGINE: HTTP URI %s", httpURI);
132
+ 
133
+     /**** 4. Get the End point from URI ****/
134
+     dwError = VmRestGetEndPointURIfromRequestURI(
135
+diff --git a/transport/posix/socket.c b/transport/posix/socket.c
136
+index 18cef89..6c0e14e 100644
137
+--- a/transport/posix/socket.c
138
+@@ -553,10 +553,12 @@ VmSockPosixWaitForEvent(
139
+             }
140
+             else if (pEventSocket->type == VM_SOCK_TYPE_LISTENER)
141
+             {
142
++                VMREST_LOG_INFO(pRESTHandle,"%s","C-REST-ENGINE: ========================  NEW REQUEST ==========================");
143
+                 dwError = VmSockPosixAcceptConnection(
144
+                               pEventSocket,
145
+                               &pSocket);
146
+                 BAIL_ON_VMREST_ERROR(dwError);
147
++                VMREST_LOG_INFO(pRESTHandle,"C-REST-ENGINE: Accepted new connection with socket fd %d", pSocket->fd);
148
+ 
149
+                 dwError = VmSockPosixSetNonBlocking(pRESTHandle,pSocket);
150
+                 BAIL_ON_VMREST_ERROR(dwError);
151
+@@ -694,6 +696,7 @@ VmSockPosixWaitForEvent(
152
+ 
153
+ error:
154
+ 
155
++    VMREST_LOG_ERROR(pRESTHandle,"%s","Socket layer - wait for event error");
156
+     if (ppSocket)
157
+     {
158
+         *ppSocket = NULL;
159
+@@ -1077,6 +1080,7 @@ VmSockPosixWrite(
160
+ 
161
+ error:
162
+ 
163
++    VMREST_LOG_ERROR(pRESTHandle,"%s", "Socket write failed");
164
+     goto cleanup;
165
+ }
166
+ 
167
+@@ -1114,6 +1118,8 @@ VmSockPosixCloseSocket(
168
+     }
169
+     BAIL_ON_VMREST_ERROR(dwError);
170
+ 
171
++    VMREST_LOG_INFO(pRESTHandle,"C-REST-ENGINE: Closing socket with fd %d", pSocket->fd);
172
++
173
+     dwError = VmRESTLockMutex(pSocket->pMutex);
174
+     BAIL_ON_VMREST_ERROR(dwError);
175
+