Request logging

All Apache Druid services that can serve queries can also log the query requests they process. Request logs contain information on query metrics, including execution time and memory usage. You can use information in the request logs to monitor query performance, determine bottlenecks, and analyze and improve slow queries.

Request logging is disabled by default. This topic describes how to configure Druid to generate request logs to track query metrics.

Configure request logging

To enable request logging, determine the type of request logger to use, then set the configurations specific to the request logger type.

The following request logger types are available:

  • noop: Disables request logging, the default behavior.
  • file: Stores logs to disk.
  • emitter: Logs request to an external location, which is configured through an emitter.
  • slf4j: Logs queries via the SLF4J Java logging API.
  • filtered: Filters requests by query type or execution time before logging the filtered queries by the delegated request logger.
  • composing: Logs all requests to multiple request loggers.
  • switching: Logs native queries and SQL queries to separate request loggers.

Define the type of request logger in druid.request.logging.type. See the Request logging configuration for properties to set for each type of request logger. Specify these properties in the common.runtime.properties file. You must restart Druid for the changes to take effect.

Druid stores the results in the Broker logs, unless the request logging type is emitter. If you use emitter request logging, you must also configure metrics emission.

Configure metrics emission

Druid includes various emitters to send metrics and alerts. To emit query metrics, set druid.request.logging.feed=emitter, and define the emitter type in the druid.emitter property.

You can use any of the following emitters in Druid:

  • noop: Disables metric emission, the default behavior.
  • logging: Emits metrics to Log4j 2. See Logging to configure Log4j 2 for use with Druid.
  • http: Sends HTTP POST requests containing the metrics in JSON format to a user-defined endpoint.
  • parametrized: Operates like the http emitter but fine-tunes the recipient URL based on the event feed.
  • composing: Emits metrics to multiple emitter types.
  • graphite: Emits metrics to a Graphite Carbon service.

Specify these properties in the common.runtime.properties file. See the Metrics emitters configuration for properties to set for each type of metrics emitter. You must restart Druid for the changes to take effect.

Example

The following configuration shows how to enable request logging and post query metrics to the endpoint http://example.com:8080/path.

  1. # Enable request logging and configure the emitter request logger
  2. druid.request.logging.type=emitter
  3. druid.request.logging.feed=myRequestLogFeed
  4. # Enable metrics emission and tell Druid where to emit messages
  5. druid.emitter=http
  6. druid.emitter.http.recipientBaseUrl=http://example.com:8080/path
  7. # Authenticate to the base URL, if needed
  8. druid.emitter.http.basicAuthentication=username:password

The following shows an example log emitter output:

  1. [
  2. {
  3. "feed": "metrics",
  4. "timestamp": "2022-01-06T20:32:06.628Z",
  5. "service": "druid/broker",
  6. "host": "localhost:8082",
  7. "version": "2022.01.0-iap-SNAPSHOT",
  8. "metric": "sqlQuery/bytes",
  9. "value": 9351,
  10. "dataSource": "[wikipedia]",
  11. "id": "56e8317b-31cc-443d-b109-47f51b21d4c3",
  12. "nativeQueryIds": "[2b9cbced-11fc-4d78-a58c-c42863dff3c8]",
  13. "remoteAddress": "127.0.0.1",
  14. "success": "true"
  15. },
  16. {
  17. "feed": "myRequestLogFeed",
  18. "timestamp": "2022-01-06T20:32:06.585Z",
  19. "remoteAddr": "127.0.0.1",
  20. "service": "druid/broker",
  21. "sqlQueryContext":
  22. {
  23. "useApproximateCountDistinct": false,
  24. "sqlQueryId": "56e8317b-31cc-443d-b109-47f51b21d4c3",
  25. "useApproximateTopN": false,
  26. "useCache": false,
  27. "sqlOuterLimit": 101,
  28. "populateCache": false,
  29. "nativeQueryIds": "[2b9cbced-11fc-4d78-a58c-c42863dff3c8]"
  30. },
  31. "queryStats":
  32. {
  33. "sqlQuery/time": 43,
  34. "sqlQuery/planningTimeMs": 5,
  35. "sqlQuery/bytes": 9351,
  36. "success": true,
  37. "context":
  38. {
  39. "useApproximateCountDistinct": false,
  40. "sqlQueryId": "56e8317b-31cc-443d-b109-47f51b21d4c3",
  41. "useApproximateTopN": false,
  42. "useCache": false,
  43. "sqlOuterLimit": 101,
  44. "populateCache": false,
  45. "nativeQueryIds": "[2b9cbced-11fc-4d78-a58c-c42863dff3c8]"
  46. },
  47. "identity": "allowAll"
  48. },
  49. "query": null,
  50. "host": "localhost:8082",
  51. "sql": "SELECT * FROM wikipedia WHERE cityName = 'Buenos Aires'"
  52. },
  53. {
  54. "feed": "myRequestLogFeed",
  55. "timestamp": "2022-01-06T20:32:07.652Z",
  56. "remoteAddr": "",
  57. "service": "druid/broker",
  58. "sqlQueryContext":
  59. {},
  60. "queryStats":
  61. {
  62. "query/time": 16,
  63. "query/bytes": -1,
  64. "success": true,
  65. "identity": "allowAll"
  66. },
  67. "query":
  68. {
  69. "queryType": "scan",
  70. "dataSource":
  71. {
  72. "type": "table",
  73. "name": "wikipedia"
  74. },
  75. "intervals":
  76. {
  77. "type": "intervals",
  78. "intervals":
  79. [
  80. "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"
  81. ]
  82. },
  83. "virtualColumns":
  84. [
  85. {
  86. "type": "expression",
  87. "name": "v0",
  88. "expression": "'Buenos Aires'",
  89. "outputType": "STRING"
  90. }
  91. ],
  92. "resultFormat": "compactedList",
  93. "batchSize": 20480,
  94. "limit": 101,
  95. "filter":
  96. {
  97. "type": "selector",
  98. "dimension": "cityName",
  99. "value": "Buenos Aires",
  100. "extractionFn": null
  101. },
  102. "columns":
  103. [
  104. "__time",
  105. "added",
  106. "channel",
  107. "comment",
  108. "commentLength",
  109. "countryIsoCode",
  110. "countryName",
  111. "deleted",
  112. "delta",
  113. "deltaBucket",
  114. "diffUrl",
  115. "flags",
  116. "isAnonymous",
  117. "isMinor",
  118. "isNew",
  119. "isRobot",
  120. "isUnpatrolled",
  121. "metroCode",
  122. "namespace",
  123. "page",
  124. "regionIsoCode",
  125. "regionName",
  126. "user",
  127. "v0"
  128. ],
  129. "legacy": false,
  130. "context":
  131. {
  132. "populateCache": false,
  133. "queryId": "62e3d373-6e50-41b4-873b-1e56347c2950",
  134. "sqlOuterLimit": 101,
  135. "sqlQueryId": "cbb3d519-aee9-4566-8920-dbbeab6269f5",
  136. "useApproximateCountDistinct": false,
  137. "useApproximateTopN": false,
  138. "useCache": false
  139. },
  140. "descending": false,
  141. "granularity":
  142. {
  143. "type": "all"
  144. }
  145. },
  146. "host": "localhost:8082",
  147. "sql": null
  148. },
  149. ...
  150. ]

Learn more

See the following topics for more information.