blob: cf1e08c3c4121c92cb09e6fabcdb0ca7de92e8db [file] [log] [blame]
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[9499],{3905:(e,n,t)=>{t.d(n,{Zo:()=>u,kt:()=>f});var a=t(7294);function i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function r(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,a)}return t}function o(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?r(Object(t),!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):r(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function s(e,n){if(null==e)return{};var t,a,i=function(e,n){if(null==e)return{};var t,a,i={},r=Object.keys(e);for(a=0;a<r.length;a++)t=r[a],n.indexOf(t)>=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(a=0;a<r.length;a++)t=r[a],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}var p=a.createContext({}),l=function(e){var n=a.useContext(p),t=n;return e&&(t="function"==typeof e?e(n):o(o({},n),e)),t},u=function(e){var n=l(e.components);return a.createElement(p.Provider,{value:n},e.children)},m="mdxType",d={inlineCode:"code",wrapper:function(e){var n=e.children;return a.createElement(a.Fragment,{},n)}},k=a.forwardRef((function(e,n){var t=e.components,i=e.mdxType,r=e.originalType,p=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),m=l(t),k=i,f=m["".concat(p,".").concat(k)]||m[k]||d[k]||r;return t?a.createElement(f,o(o({ref:n},u),{},{components:t})):a.createElement(f,o({ref:n},u))}));function f(e,n){var t=arguments,i=n&&n.mdxType;if("string"==typeof e||i){var r=t.length,o=new Array(r);o[0]=k;var s={};for(var p in n)hasOwnProperty.call(n,p)&&(s[p]=n[p]);s.originalType=e,s[m]="string"==typeof e?e:i,o[1]=s;for(var l=2;l<r;l++)o[l]=t[l];return a.createElement.apply(null,o)}return a.createElement.apply(null,t)}k.displayName="MDXCreateElement"},9442:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>u,contentTitle:()=>p,default:()=>f,frontMatter:()=>s,metadata:()=>l,toc:()=>m});var a=t(7462),i=t(3366),r=(t(7294),t(3905)),o=["components"],s={id:"kafka-ingestion",title:"Apache Kafka ingestion",sidebar_label:"Apache Kafka ingestion",description:"Overview of the Kafka indexing service for Druid. Includes example supervisor specs to help you get started."},p=void 0,l={unversionedId:"development/extensions-core/kafka-ingestion",id:"development/extensions-core/kafka-ingestion",title:"Apache Kafka ingestion",description:"Overview of the Kafka indexing service for Druid. Includes example supervisor specs to help you get started.",source:"@site/docs/26.0.0/development/extensions-core/kafka-ingestion.md",sourceDirName:"development/extensions-core",slug:"/development/extensions-core/kafka-ingestion",permalink:"/docs/26.0.0/development/extensions-core/kafka-ingestion",draft:!1,tags:[],version:"current",frontMatter:{id:"kafka-ingestion",title:"Apache Kafka ingestion",sidebar_label:"Apache Kafka ingestion",description:"Overview of the Kafka indexing service for Druid. Includes example supervisor specs to help you get started."},sidebar:"docs",previous:{title:"Schema design tips",permalink:"/docs/26.0.0/ingestion/schema-design"},next:{title:"Apache Kafka supervisor",permalink:"/docs/26.0.0/development/extensions-core/kafka-supervisor-reference"}},u={},m=[{value:"Kafka support",id:"kafka-support",level:2},{value:"Load the Kafka indexing service",id:"load-the-kafka-indexing-service",level:2},{value:"Define a supervisor spec",id:"define-a-supervisor-spec",level:2},{value:"JSON input format supervisor spec example",id:"json-input-format-supervisor-spec-example",level:3},{value:"Kafka input format supervisor spec example",id:"kafka-input-format-supervisor-spec-example",level:3},{value:"Submit a supervisor spec",id:"submit-a-supervisor-spec",level:2}],d={toc:m},k="wrapper";function f(e){var n=e.components,t=(0,i.Z)(e,o);return(0,r.kt)(k,(0,a.Z)({},d,t,{components:n,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"When you enable the Kafka indexing service, you can configure supervisors on the Overlord to manage the creation and lifetime of Kafka indexing tasks."),(0,r.kt)("p",null,"Kafka indexing tasks read events using Kafka's own partition and offset mechanism to guarantee exactly-once ingestion. The supervisor oversees the state of the indexing tasks to:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"coordinate handoffs"),(0,r.kt)("li",{parentName:"ul"},"manage failures"),(0,r.kt)("li",{parentName:"ul"},"ensure that scalability and replication requirements are maintained.")),(0,r.kt)("p",null,"This topic covers how to submit a supervisor spec to ingest event data, also known as message data, from Kafka. See the following for more information:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"For a reference of Kafka supervisor spec configuration options, see the ",(0,r.kt)("a",{parentName:"li",href:"/docs/26.0.0/development/extensions-core/kafka-supervisor-reference"},"Kafka supervisor reference"),"."),(0,r.kt)("li",{parentName:"ul"},"For operations reference information to help run and maintain Apache Kafka supervisors, see ",(0,r.kt)("a",{parentName:"li",href:"/docs/26.0.0/development/extensions-core/kafka-supervisor-operations"},"Kafka supervisor operations"),"."),(0,r.kt)("li",{parentName:"ul"},"For a walk-through, see the ",(0,r.kt)("a",{parentName:"li",href:"/docs/26.0.0/tutorials/tutorial-kafka"},"Loading from Apache Kafka")," tutorial.")),(0,r.kt)("h2",{id:"kafka-support"},"Kafka support"),(0,r.kt)("p",null,"The Kafka indexing service supports transactional topics introduced in Kafka 0.11.x by default. The consumer for Kafka indexing service is incompatible with older Kafka brokers. If you are using an older version, refer to the ",(0,r.kt)("a",{parentName:"p",href:"https://kafka.apache.org/documentation/#upgrade"},"Kafka upgrade guide"),"."),(0,r.kt)("p",null,"Additionally, you can set ",(0,r.kt)("inlineCode",{parentName:"p"},"isolation.level")," to ",(0,r.kt)("inlineCode",{parentName:"p"},"read_uncommitted")," in ",(0,r.kt)("inlineCode",{parentName:"p"},"consumerProperties")," if either:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"You don't need Druid to consume transactional topics."),(0,r.kt)("li",{parentName:"ul"},"You need Druid to consume older versions of Kafka. Make sure offsets are sequential, since there is no offset gap check in Druid anymore.")),(0,r.kt)("p",null,"If your Kafka cluster enables consumer-group based ACLs, you can set ",(0,r.kt)("inlineCode",{parentName:"p"},"group.id")," in ",(0,r.kt)("inlineCode",{parentName:"p"},"consumerProperties")," to override the default auto generated group id."),(0,r.kt)("h2",{id:"load-the-kafka-indexing-service"},"Load the Kafka indexing service"),(0,r.kt)("p",null,"To use the Kafka indexing service, load the ",(0,r.kt)("inlineCode",{parentName:"p"},"druid-kafka-indexing-service")," extension on both the Overlord and the MiddleManagers. See ",(0,r.kt)("a",{parentName:"p",href:"/docs/26.0.0/development/extensions#loading-extensions"},"Loading extensions")," for instructions on how to configure extensions."),(0,r.kt)("h2",{id:"define-a-supervisor-spec"},"Define a supervisor spec"),(0,r.kt)("p",null,"Similar to the ingestion spec for batch ingestion, the supervisor spec configures the data ingestion for Kafka streaming ingestion. A supervisor spec has the following sections:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"dataSchema")," to specify the Druid datasource name, primary timestamp, dimensions, metrics, transforms, and any necessary filters."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"ioConfig")," to configure Kafka connection settings and configure how Druid parses the data. Kafka-specific connection details go in the ",(0,r.kt)("inlineCode",{parentName:"li"},"consumerProperties"),". The ",(0,r.kt)("inlineCode",{parentName:"li"},"ioConfig")," is also where you define the input format (",(0,r.kt)("inlineCode",{parentName:"li"},"inputFormat"),") of your Kafka data. For supported formats for Kafka and information on how to configure the input format, see ",(0,r.kt)("a",{parentName:"li",href:"/docs/26.0.0/ingestion/data-formats"},"Data formats"),". "),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"tuningConfig")," to control various tuning parameters specific to each ingestion method.\nFor a full description of all the fields and parameters in a Kafka supervisor spec, see the ",(0,r.kt)("a",{parentName:"li",href:"/docs/26.0.0/development/extensions-core/kafka-supervisor-reference"},"Kafka supervisor reference"),".")),(0,r.kt)("p",null,"The following sections contain examples to help you get started with supervisor specs."),(0,r.kt)("h3",{id:"json-input-format-supervisor-spec-example"},"JSON input format supervisor spec example"),(0,r.kt)("p",null,"The following example demonstrates a supervisor spec for Kafka that uses the ",(0,r.kt)("inlineCode",{parentName:"p"},"JSON")," input format. In this case Druid parses the event contents in JSON format:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "type": "kafka",\n "spec": {\n "dataSchema": {\n "dataSource": "metrics-kafka",\n "timestampSpec": {\n "column": "timestamp",\n "format": "auto"\n },\n "dimensionsSpec": {\n "dimensions": [],\n "dimensionExclusions": [\n "timestamp",\n "value"\n ]\n },\n "metricsSpec": [\n {\n "name": "count",\n "type": "count"\n },\n {\n "name": "value_sum",\n "fieldName": "value",\n "type": "doubleSum"\n },\n {\n "name": "value_min",\n "fieldName": "value",\n "type": "doubleMin"\n },\n {\n "name": "value_max",\n "fieldName": "value",\n "type": "doubleMax"\n }\n ],\n "granularitySpec": {\n "type": "uniform",\n "segmentGranularity": "HOUR",\n "queryGranularity": "NONE"\n }\n },\n "ioConfig": {\n "topic": "metrics",\n "inputFormat": {\n "type": "json"\n },\n "consumerProperties": {\n "bootstrap.servers": "localhost:9092"\n },\n "taskCount": 1,\n "replicas": 1,\n "taskDuration": "PT1H"\n },\n "tuningConfig": {\n "type": "kafka",\n "maxRowsPerSegment": 5000000\n }\n } \n}\n')),(0,r.kt)("h3",{id:"kafka-input-format-supervisor-spec-example"},"Kafka input format supervisor spec example"),(0,r.kt)("p",null,"If you want to ingest data from other fields in addition to the Kafka message contents, you can use the ",(0,r.kt)("inlineCode",{parentName:"p"},"kafka")," input format. The ",(0,r.kt)("inlineCode",{parentName:"p"},"kafka")," input format lets you ingest:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"the event key field"),(0,r.kt)("li",{parentName:"ul"},"event headers"),(0,r.kt)("li",{parentName:"ul"},"the Kafka event timestamp"),(0,r.kt)("li",{parentName:"ul"},"the Kafka event value that stores the payload.")),(0,r.kt)("p",null,"For example, consider the following structure for a message that represents a fictitious wiki edit in a development environment:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"Event headers"),': {"environment": "development"}'),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"Event key"),': {"key: "wiki-edit"}'),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"Event value"),": \\<JSON object with event payload containing the change details",">"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"Event timestamp"),': "Nov. 10, 2021 at 14:06"')),(0,r.kt)("p",null,"When you use the ",(0,r.kt)("inlineCode",{parentName:"p"},"kafka")," input format, you configure the way that Druid names the dimensions created from the Kafka message:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"headerColumnPrefix"),": Supply a prefix to the Kafka headers to avoid any conflicts with named dimensions. The default is ",(0,r.kt)("inlineCode",{parentName:"li"},"kafka.header"),". Considering the header from the example, Druid maps the header to the following column: ",(0,r.kt)("inlineCode",{parentName:"li"},"kafka.header.environment"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"timestampColumnName"),": Supply a custom name for the Kafka timestamp in the Druid schema to avoid conflicts with other time columns. The default is ",(0,r.kt)("inlineCode",{parentName:"li"},"kafka.timestamp"),"."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"keyColumnName"),": Supply the name for the Kafka key column in Druid. The default is ",(0,r.kt)("inlineCode",{parentName:"li"},"kafka.key"),".\nAdditionally, you must provide information about how Druid should parse the data in the Kafka message:"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"headerFormat"),': The default "string" decodes UTF8-encoded strings from the Kafka header. If you need another format, you can implement your own parser.'),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"keyFormat"),": Takes a Druid ",(0,r.kt)("inlineCode",{parentName:"li"},"inputFormat"),' and uses the value for the first key it finds. According to the example the value is "wiki-edit". It discards the key name in this case. If you store the key as a string, use the ',(0,r.kt)("inlineCode",{parentName:"li"},"CSV")," input format. For example, if you have simple string for the the key ",(0,r.kt)("inlineCode",{parentName:"li"},"wiki-edit"),", you can use the following to parse the key:",(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre"},'"keyFormat": {\n "type": "csv",\n "hasHeaderRow": false,\n "findColumnsFromHeader": false,\n "columns": ["key"]\n } \n'))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"valueFormat"),": Define how to parse the message contents. You can use any of the Druid input formats that work for Kafka.")),(0,r.kt)("p",null,"For more information on data formats, see ",(0,r.kt)("a",{parentName:"p",href:"/docs/26.0.0/ingestion/data-formats"},"Data formats"),"."),(0,r.kt)("p",null,"Finally, add the Kafka message columns to the ",(0,r.kt)("inlineCode",{parentName:"p"},"dimensionsSpec"),". For the key and timestamp, you can use the dimension names you defined for ",(0,r.kt)("inlineCode",{parentName:"p"},"keyColumnName")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"timestampColumnName"),". For header dimensions, append the header key to the ",(0,r.kt)("inlineCode",{parentName:"p"},"headerColumnPrefix"),". For example ",(0,r.kt)("inlineCode",{parentName:"p"},"kafka.header.environment"),"."),(0,r.kt)("p",null,"The following supervisor spec demonstrates how to ingest the Kafka header, key, and timestamp into Druid dimensions:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},'{\n "type": "kafka",\n "spec": {\n "ioConfig": {\n "type": "kafka",\n "consumerProperties": {\n "bootstrap.servers": "localhost:9092"\n },\n "topic": "wiki-edits",\n "inputFormat": {\n "type": "kafka",\n "headerColumnPrefix": "kafka.header.",\n "timestampColumnName": "kafka.timestamp",\n "keyColumnName": "kafka.key",\n "headerFormat": {\n "type": "string"\n },\n "keyFormat": {\n "type": "json"\n },\n "valueFormat": {\n "type": "json"\n },\n "findColumnsFromHeader": false\n },\n "useEarliestOffset": true\n },\n "tuningConfig": {\n "type": "kafka"\n },\n "dataSchema": {\n "dataSource": "wikiticker",\n "timestampSpec": {\n "column": "timestamp",\n "format": "posix"\n },\n "dimensionsSpec": {\n "dimensions": [\n {\n "type": "string",\n "name": "kafka.key"\n },\n {\n "type": "string",\n "name": "kafka.timestamp"\n },\n {\n "type": "string",\n "name": "kafka.header.environment"\n },\n "$schema",\n {\n "type": "long",\n "name": "id"\n },\n "type",\n {\n "type": "long",\n "name": "namespace"\n },\n "title",\n "comment",\n "user",]\n ]\n },\n "granularitySpec": {\n "queryGranularity": "none",\n "rollup": false,\n "segmentGranularity": "day"\n }\n }\n },\n "tuningConfig": {\n "type": "kafka"\n }\n}\n')),(0,r.kt)("p",null,"After Druid ingests the data, you can query the Kafka message columns as follows:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-unix"},'SELECT\n "kafka.header.environment",\n "kafka.key",\n "kafka.timestamp"\nFROM "wikiticker"\n\nkafka.header.environment kafka.key kafka.timestamp\ndevelopment wiki-edit 1636399229823\n')),(0,r.kt)("p",null,"For more information, see ",(0,r.kt)("a",{parentName:"p",href:"/docs/26.0.0/ingestion/data-formats#kafka"},(0,r.kt)("inlineCode",{parentName:"a"},"kafka")," data format"),"."),(0,r.kt)("h2",{id:"submit-a-supervisor-spec"},"Submit a supervisor spec"),(0,r.kt)("p",null,"Druid starts a supervisor for a dataSource when you submit a supervisor spec. You can use the data loader in the web console or you can submit a supervisor spec to the following endpoint:"),(0,r.kt)("p",null,(0,r.kt)("inlineCode",{parentName:"p"},"http://<OVERLORD_IP>:<OVERLORD_PORT>/druid/indexer/v1/supervisor")),(0,r.kt)("p",null,"For example: "),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},"curl -X POST -H 'Content-Type: application/json' -d @supervisor-spec.json http://localhost:8090/druid/indexer/v1/supervisor\n")),(0,r.kt)("p",null,"Where the file ",(0,r.kt)("inlineCode",{parentName:"p"},"supervisor-spec.json")," contains your Kafka supervisor spec file."))}f.isMDXComponent=!0}}]);