| <!--#include virtual="header.txt"--> | |
| <h1>Job Completion Kafka plugin guide</h1> | |
| <p>When configured, the <b>jobcomp/kafka</b> plugin attempts to publish a subset | |
| of the fields for each completed job record to a Kafka server. Since Slurm | |
| 25.05 it is also possible to optionally send a subset of job record fields when | |
| the job starts running. Since Slurm 26.11, records can optionally be sent for | |
| additional job state transition events: a job entering the queue, being | |
| requeued, becoming held, and being released. Each of these events, like job | |
| start, can be enabled independently and sent to its own topic. Every record | |
| carries an <code>event</code> field naming the event (<code>job finish</code>, | |
| <code>job start</code>, <code>job queue</code>, <code>job requeue</code>, | |
| <code>job hold</code>, or <code>job release</code>) and an | |
| <code>@event_time</code> field with the UTC time the record was generated, in | |
| the same format as the other time fields. A job finish record describes the | |
| end of one run of a job, not necessarily the end of the job: the finish record | |
| of a requeued run is followed, when those events are enabled, by a job requeue | |
| record and, once the job runs again, by new job start and job finish records, | |
| all with the same <code>jobid</code> value.</p> | |
| <h2 id="prereq">Requirements<a class="slurm_link" href="#prereq"></a></h2> | |
| <p>The plugin serializes the subset of fields to JSON before each produce | |
| attempt. The serialization is done using the Slurm serialization plugins, so the | |
| <b>libjson-c</b> development files are an indirect prerequisite for this plugin. | |
| </p> | |
| <p>The plugin offloads part of the client producer work to <b>librdkafka</b> and | |
| consumes its API, thus the library development files are another prerequisite. | |
| </p> | |
| <ul> | |
| <li><a href="https://github.com/confluentinc/librdkafka">librdkafka</a> | |
| development files</li> | |
| <li><a href="related_software.html#json">libjson-c</a> development | |
| files</li> | |
| </ul> | |
| <h2 id="config">Configuration<a class="slurm_link" href="#config"></a></h2> | |
| <p>The plugin is configured with the following | |
| <a href="slurm.conf.html">slurm.conf</a> options:</p> | |
| <ul> | |
| <li> | |
| <a href="slurm.conf.html#OPT_JobCompType"><b>JobCompType</b></a> | |
| Should be set to <b>jobcomp/kafka</b>. | |
| <pre>JobCompType=jobcomp/kafka</pre> | |
| </li> | |
| <li> | |
| <a href="slurm.conf.html#OPT_JobCompLoc"><b>JobCompLoc</b></a> This string | |
| represents an absolute path to a file containing 'key=value' pairs configuring | |
| <a href="https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md"> | |
| librdkafka properties</a>. For the plugin to work properly, this file | |
| needs to exist and at least the <b>bootstrap.servers</b> property needs to be | |
| be configured. | |
| <pre>JobCompLoc=/arbitrary/path/to/rdkafka.conf</pre> | |
| <p><b>NOTE</b>: There is no default value for JobCompLoc when this plugin is | |
| configured, and thus it needs to be explicitly set.</p> | |
| <p><b>NOTE</b>: The <b>librdkafka</b> parameters configured in the file | |
| referenced by this option take effect upon slurmctld restart.</p> | |
| <p><b>NOTE</b>: The plugin doesn't validate these parameters, but just logs | |
| an error and fails if any parameter passed to the library API function | |
| rd_kafka_conf_set() fails.</p> | |
| <p>An example configuration file could look like this:</p> | |
| <pre> | |
| bootstrap.servers=kafkahost1:9092 | |
| debug=broker,topic,msg | |
| linger.ms=400 | |
| log_level=7 | |
| </pre> | |
| </li> | |
| <li> | |
| <a href="slurm.conf.html#OPT_JobCompParams"><b>JobCompParams</b></a> Comma | |
| separated list of extra configurable parameters. Please refer to the slurm.conf | |
| man page for specific details. Example: | |
| <pre>JobCompParams=flush_timeout=200,poll_interval=3,requeue_on_msg_timeout, | |
| topic=mycluster</pre> | |
| <p>Or, to also send job queue and job hold records and deliver the records | |
| of every enabled event, including job finish, to a single topic:</p> | |
| <pre> | |
| JobCompParams=enable_job_queue,enable_job_hold,topic_all=mycluster-jobs | |
| </pre> | |
| <p><b>NOTE</b>: Changes to this option do not require a slurmctld restart. | |
| Reconfiguration or SIGHUP is sufficient for them to take effect.</p> | |
| <p><b>NOTE</b>: Refer to the man page to configure job start, queue, requeue, | |
| hold, and release events.</p> | |
| </li> | |
| <li> | |
| <a href="slurm.conf.html#OPT_DebugFlags"><b>DebugFlags</b></a> Optional | |
| <b>JobComp</b> debug flag for extra plugin specific logging. | |
| <pre>DebugFlags=JobComp</pre> | |
| </li> | |
| </ul> | |
| <h2 id="functionality">Plugin Functionality<a class="slurm_link" | |
| href="#functionality"></a></h2> | |
| <p>For each enabled job event, the plugin jobcomp_p_record_job_event operation | |
| is executed. A subset of the job record fields are serialized into a JSON | |
| string via the Slurm serialization plugins. Then the serialized string is | |
| attempted to be produced using the librdkafka rd_kafka_producev() API call, | |
| keyed by the job ID, so the records of a job sent to the same topic land in | |
| the same partition with the default librdkafka partitioner. Retries can | |
| reorder them unless the librdkafka property <code>enable.idempotence</code> | |
| is set to <code>true</code> in the JobCompLoc file, and messages produced | |
| again by requeue_on_msg_timeout go behind newer ones. | |
| Each job array task and each heterogeneous job component has its own job | |
| ID.</p> | |
| <p>Every record carries, when set, the fields identifying the job and its | |
| state: <code>event</code>, <code>@event_time</code>, <code>jobid</code>, | |
| <code>sluid</code>, <code>original_sluid</code>, <code>restart_cnt</code>, | |
| <code>cluster</code>, <code>username</code>, <code>user_id</code>, | |
| <code>groupname</code>, <code>group_id</code>, <code>account</code>, | |
| <code>partition</code>, <code>qos</code>, <code>job_name</code>, | |
| <code>state</code>, <code>state_reason</code>, <code>state_desc</code>, | |
| <code>priority</code>, <code>@submit</code>, <code>@eligible</code>, | |
| <code>array_job_id</code>, <code>array_task_id</code>, <code>het_job_id</code>, | |
| and <code>het_job_offset</code>. The <code>sluid</code> field matches the | |
| job's accounting record and changes on every requeue and resize, while | |
| <code>original_sluid</code> only changes on a requeue. A requeue increments | |
| <code>restart_cnt</code>: the finish record of the run that ended still | |
| carries the old value, the requeue record and every later record carry the | |
| new one. That finish record reports <code>REQUEUED</code> when a requeue ended | |
| the run, <code>NODE_FAIL</code> or <code>PREEMPTED</code> when a node failure | |
| or preemption requeued the job, as accounting does, and the run's own final | |
| state when the job was requeued after finishing, such as by RequeueExit. Job | |
| start and job finish records add the | |
| request and allocation details, such as the nodes, CPU counts, TRES, task | |
| layout, paths, time limit, the admin comment, the comment and the script when | |
| enabled, and for finish records the end time, elapsed time, and exit codes. | |
| The queue, hold, release, | |
| and requeue records carry only the common fields.</p> | |
| <p>Producing a message to librdkafka can be done even if the Kafka server is | |
| down. But an error returned from this call makes it so the message is discarded. | |
| Produced messages accumulate in the librdkafka out queue for up to "linger.ms" | |
| milliseconds (a configurable librdkafka parameter) before building | |
| a message set from the accumulated messages.</p> | |
| <p>Then the librdkafka library transmits a produce request. While no "ACK" is | |
| received, messages are conceptually considered to be "in-flight" according to | |
| the library documentation. The library then receives a produce response, which | |
| can be handled in one of two ways:</p> | |
| <dl> | |
| <dt><b>retriable error</b></dt> | |
| <dd>The library will automatically attempt a retry if | |
| no library limit parameter is hit.</dd> | |
| <dt><b>permanent error</b> or <b>success</b></dt> | |
| <dd>The message will be removed | |
| from the library out queue and is staged to the library delivery report queue. | |
| </dd></dl> | |
| <p>The following diagram illustrates the functionality being described:</p> | |
| <img src="jobcomp_kafka_fig1.png"> | |
| <p>The <b>jobcomp/kafka</b> plugin has a background poll handler thread that | |
| periodically calls the librdkafka API rd_kafka_poll() function. How frequent | |
| the thread makes the call is configurable via JobCompParams=poll_interval. | |
| The call makes it so that messages in the library delivery report queue are | |
| pulled and handled back to the plugin delivery report callback, which takes | |
| different actions depending on the error message the library set. By default, | |
| successful messages are just logged if DebugFlags=JobComp is enabled, and | |
| messages with permanent errors are discarded, unless the error is message timed | |
| out and JobCompParams is configured with "requeue_on_msg_timeout", which would | |
| instruct the callback to attempt to produce the message again.</p> | |
| <p><b>NOTE</b>: Each enabled event adds records for librdkafka to buffer while | |
| the broker is unreachable, and the job queue event adds one per submission. | |
| With the librdkafka defaults, a record is discarded after | |
| <code>message.timeout.ms</code> (300000 milliseconds, or 5 minutes), and new | |
| records are discarded once <code>queue.buffering.max.messages</code> (100000) | |
| are queued. | |
| Raise them in the JobCompLoc file for the submission rate and the longest | |
| outage the records must survive, or set JobCompParams=requeue_on_msg_timeout | |
| to produce timed-out records again.</p> | |
| <p>On plugin termination, the fini() operation is executed. The rd_kafka_purge() | |
| library API function is called which purges librdkafka out queue messages. The | |
| rd_kafka_flush() API call is also called, which waits until all outstanding | |
| produce requests (and potentially other types of requests) are completed. | |
| How much to wait is also configurable via JobCompParams=flush_timeout | |
| parameter. Purged messages are always saved to the plugin state file in the | |
| Slurm StateSaveLocation, and messages purged while "in-flight" are discarded. | |
| </p> | |
| <p><b>NOTE</b>: You must be using librdkafka v1.0.0 or later in order to take | |
| advantage of the purge functionality described above. With previous versions | |
| the outgoing queue can not be purged to the state file on shutdown, which | |
| means that any messages that weren't delivered before the termination of the | |
| kafka plugin will be lost.</p> | |
| <p>On plugin initialization, after parsing the configuration, saved messages in | |
| the state are loaded and attempted to be produced again. So undelivered messages | |
| should be resilient to slurmctld restarts.</p> | |
| <p>The Kafka broker "host:port" list should be explicitly configured in the | |
| file referenced by JobCompLoc option explained above. The default topic is | |
| the configured Slurm ClusterName, but it can also be configured via | |
| JobCompParams=topic parameter. The other events default to per-event | |
| topics named <ClusterName>-job-<event>, where the event is start, | |
| queue, requeue, hold, or release, each configurable via its own JobCompParams | |
| topic parameter. Kafka only preserves message order within a topic partition, | |
| so set JobCompParams=topic_all to send every enabled event to one topic and | |
| obtain a single stream of records per job, ordered as described above. | |
| The plugin does not create topics, so they must exist on the Kafka cluster | |
| unless its brokers create topics automatically (the | |
| <code>auto.create.topics.enable</code> broker property).</p> | |
| <p>The <b>jobcomp/kafka</b> plugin mostly logs informational messages to the | |
| JobComp DebugFlag, except for error messages. The librdkafka by default logs | |
| to the application stderr, but the plugin configures the library to forcefully | |
| log to syslog instead. The library logging level and debug contexts are also | |
| configurable via the file referenced by JobCompLoc, as well as the rest of the | |
| library configuration parameters.</p> | |
| <!--#include virtual="footer.txt"--> |