summaryrefslogtreecommitdiffstats
path: root/src/fluent-bit/lib/librdkafka-2.1.0/CONTRIBUTING.md
blob: 45ab45f9b70310715b3429a232ad843085826bb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# Contributing to librdkafka

(This document is based on [curl's CONTRIBUTE.md](https://github.com/curl/curl/blob/master/docs/CONTRIBUTE.md) - thank you!)

This document is intended to offer guidelines on how to best contribute to the
librdkafka project. This concerns new features as well as bug fixes and
general improvements.

### License and copyright

When contributing with code, you agree to put your changes and new code under
the same license librdkafka is already using unless stated and agreed
otherwise.

When changing existing source code, you do not alter the copyright of the
original file(s). The copyright will still be owned by the original creator(s)
or those who have been assigned copyright by the original author(s).

By submitting a patch to the librdkafka, you are assumed to have the right
to the code and to be allowed by your employer or whatever to hand over that
patch/code to us. We will credit you for your changes as far as possible, to
give credit but also to keep a trace back to who made what changes. Please
always provide us with your full real name when contributing!

Official librdkafka project maintainer(s) assume ownership and copyright
ownership of all accepted submissions.


## Write a good patch

### API and ABI compatibility guarantees

librdkafka maintains a strict API and ABI compatibility guarantee, we guarantee
not to break existing applications and we honour the SONAME version.

**Note:** ABI compatibility is guaranteed only for the C library, not C++.

**Note to librdkafka maintainers:**

Don't think we can or should bump the SONAME version, it will break all
existing applications relying on librdkafka, and there's no change important
enough to warrant that.
Instead deprecate (but keep) old APIs and add new better APIs as required.
Deprecate APIs through documentation (`@deprecate ..`) rather than
compiler hints (`RD_DEPRECATED`) - since the latter will cause compilation
warnings/errors for users.


#### Changes to existing APIs

Existing public APIs MUST NEVER be changed, as this would be a breaking API
and ABI change. This line must never be crossed.

This means that no changes are allowed to:
 * public function or method signatures - arguments, types, return values.
 * public structs - existing fields may not be modified and new fields must
                    not be added.


As for semantic changes (i.e., a function changes its behaviour), these are
allowed under the following conditions:

 * the existing behaviour that is changed is not documented and not widely
   relied upon. Typically this revolves around what error codes a function
   returns.
 * the existing behaviour is well known but is clearly wrong and consistently
   trips people up.

All such changes must be clearly stated in the "Upgrade considerations" section
of the release in CHANGELOG.md.


#### New public APIs

Since changes to existing APIs are strictly limited to the above rules, it is
also clear that new APIs must be delicately designed to be complete and future
proof, since once they've been introduced they can never be changed.

 * Never add public structs - there are some public structs in librdkafka
   and they were all mistakes, they've all been headaches.
   Instead add private types and provide accessor methods to set/get values.
   This allows future extension without breaking existing applications.
 * Avoid adding synchronous APIs, try to make them asynch by the use of
   `rd_kafka_queue_t` result queues, if possible.
   This may complicate the APIs a bit, but they're most of the time abstracted
   in higher-level language clients and it allows both synchronous and
   asynchronous usage.



### Portability

librdkafka is highly portable and needs to stay that way; this means we're
limited to almost-but-not-quite C99, and standard library (libc, et.al)
functions that are generally available across platforms.

Also avoid adding new dependencies since dependency availability across
platforms and package managers are a common problem.

If an external dependency is required, make sure that it is available as a
vcpkg, and also add it as a source build dependency to mklove
(see mklove/modules/configure.libcurl for an example) so that it can be built
and linked statically into librdkafka as part of the packaging process.

Less is more. Don't try to be fancy, be boring.


### Follow code style

When writing C code, follow the code style already established in
the project. Consistent style makes code easier to read and mistakes less
likely to happen.

clang-format is used to check, and fix, the style for C/C++ files,
while flake8 and autopep8 is used for the Python scripts.

You must check the style before committing by running `make style-check-changed`
from the top-level directory, and if any style errors are reported you can
automatically fix them using `make style-fix-changed` (or just run
that command directly).

The Python code may need some manual fixing since autopep8 is unable to fix
all warnings reported by flake8, in particular it will not split long lines,
in which case a `  # noqa: E501` may be needed to turn off the warning.

See the end of this document for the C style guide to use in librdkafka.


### Write Separate Changes

It is annoying when you get a huge patch from someone that is said to fix 511
odd problems, but discussions and opinions don't agree with 510 of them - or
509 of them were already fixed in a different way. Then the person merging
this change needs to extract the single interesting patch from somewhere
within the huge pile of source, and that gives a lot of extra work.

Preferably, each fix that correct a problem should be in its own patch/commit
with its own description/commit message stating exactly what they correct so
that all changes can be selectively applied by the maintainer or other
interested parties.

Also, separate changes enable bisecting much better when we track problems
and regression in the future.

### Patch Against Recent Sources

Please try to make your patches against latest master branch.

### Test Cases

Bugfixes should also include a new test case in the regression test suite
that verifies the bug is fixed.
Create a new tests/00<freenumber>-<short_bug_description>.c file and
try to reproduce the issue in its most simple form.
Verify that the test case fails for earlier versions and passes with your
bugfix in-place.

New features and APIs should also result in an added test case.

Submitted patches must pass all existing tests.
For more information on the test suite see [tests/README.md].



## How to get your changes into the main sources

File a [pull request on github](https://github.com/edenhill/librdkafka/pulls)

Your change will be reviewed and discussed there and you will be
expected to correct flaws pointed out and update accordingly, or the change
risk stalling and eventually just get deleted without action. As a submitter
of a change, you are the owner of that change until it has been merged.

Make sure to monitor your PR on github and answer questions and/or
fix nits/flaws. This is very important. We will take lack of replies as a
sign that you're not very anxious to get your patch accepted and we tend to
simply drop such changes.

When you adjust your pull requests after review, please squash the
commits so that we can review the full updated version more easily
and keep history cleaner.

For example:

    # Interactive rebase to let you squash/fixup commits
    $ git rebase -i master

    # Mark fixes-on-fixes commits as 'fixup' (or just 'f') in the
    # first column. These will be silently integrated into the
    # previous commit, so make sure to move the fixup-commit to
    # the line beneath the parent commit.

    # Since this probably rewrote the history of previously pushed
    # commits you will need to make a force push, which is usually
    # a bad idea but works good for pull requests.
    $ git push --force origin your_feature_branch


### Write good commit messages

A short guide to how to write good commit messages.

    ---- start ----
    [area]: [short line describing the main effect] [(#issuenumber)]
           -- empty line --
    [full description, no wider than 72 columns that describe as much as
    possible as to why this change is made, and possibly what things
    it fixes and everything else that is related]
    ---- stop ----

Example:

    cgrp: Restart query timer on all heartbeat failures (#10023)

    If unhandled errors were received in HeartbeatResponse
    the cgrp could get stuck in a state where it would not
    refresh its coordinator.


**Important**: Rebase your PR branch on top of master (`git rebase -i master`)
               and squash interim commits (to make a clean and readable git history)
               before pushing. Use force push to keep your history clean even after
               the initial PR push.

**Note**: Good PRs with bad commit messages or messy commit history
          such as "fixed review comment", will be squashed up in
          to a single commit with a proper commit message.


### Add changelog

If the changes in the PR affects the end user in any way, such as for a user
visible bug fix, new feature, API or doc change, etc, a release changelog item
needs to be added to [CHANGELOG.md](CHANGELOG.md) for the next release.

Add a single line to the appropriate section (Enhancements, Fixes, ..)
outlining the change, an issue number (if any), and your name or GitHub
user id for attribution.

E.g.:
```
## Enhancements
 * Improve commit() async parameter documentation (Paul Nit, #123)
```



# librdkafka C style and naming guide

*Note: The code format style is enforced by our clang-format and pep8 rules,
so that is not covered here.*

## C standard "C98"

This is a mix of C89 and C99, to be compatible with old MSVC versions.

Notable, it is C99 with the following limitations:

 * No variable declarations after statements.
 * No in-line variable declarations.


## Function and globals naming

Use self-explanatory hierarchical snake-case naming.
Pretty much all symbols should start with `rd_kafka_`, followed by
their subsystem (e.g., `cgrp`, `broker`, `buf`, etc..), followed by an
action (e.g, `find`, `get`, `clear`, ..).

The exceptions are:
 - Protocol requests and fields, use their Apache Kafka CamelCase names, .e.g:
   `rd_kafka_ProduceRequest()` and `int16_t ErrorCode`.
 - Public APIs that closely mimic the Apache Kafka Java counterpart, e.g.,
   the Admin API: `rd_kafka_DescribeConsumerGroups()`.


## Variable naming

For existing types use the type prefix as variable name.
The type prefix is typically the first part of struct member fields.
Example:

  * `rd_kafka_broker_t` has field names starting with `rkb_..`, thus broker
     variable names should be named `rkb`

Be consistent with using the same variable name for the same type throughout
the code, it makes reading the code much easier as the type can be easily
inferred from the variable.

For other types use reasonably concise but descriptive names.
`i` and `j` are typical int iterators.

## Variable declaration

Variables must be declared at the head of a scope, no in-line variable
declarations after statements are allowed.

## Function parameters/arguments

For internal functions assume that all function parameters are properly
specified, there is no need to check arguments for non-NULL, etc.
Any maluse internally is a bug, and not something we need to preemptively
protect against - the test suites should cover most of the code anyway - so
put your efforts there instead.

For arguments that may be NULL, i.e., optional arguments, we explicitlly
document in the function docstring that the argument is optional (NULL),
but there is no need to do this for non-optional arguments.

## Indenting

Use 8 spaces indent, no tabs, same as the Linux kernel.
In emacs, use `c-set-style "linux`.
For C++, use Google's C++ style.

Fix formatting issues by running `make style-fix-changed` prior to committing.


## Comments

Use `/* .. */` comments, not `// ..`

For functions, use doxygen syntax, e.g.:

    /**
     * @brief <short description>
     * ..
     * @returns <something..>
     */


Make sure to comment non-obvious code and situations where the full
context of an operation is not easily graspable.

Also make sure to update existing comments when the code changes.


## Line length

Try hard to keep line length below 80 characters, when this is not possible
exceed it with reason.


## Braces

Braces go on the same line as their enveloping statement:

    int some_func (..) {
      while (1) {
        if (1) {
          do something;
          ..
        } else {
          do something else;
          ..
        }
      }

      /* Single line scopes should not have braces */
      if (1)
        hi();
      else if (2)
        /* Say hello */
        hello();
      else
        bye();


## Spaces

All expression parentheses should be prefixed and suffixed with a single space:

    int some_func (int a) {

        if (1)
          ....;

        for (i = 0 ; i < 19 ; i++) {


        }
    }


Use space around operators:

    int a = 2;

    if (b >= 3)
       c += 2;

Except for these:

    d++;
    --e;


## New block on new line

New blocks should be on a new line:

    if (1)
      new();
    else
      old();


## Parentheses

Don't assume the reader knows C operator precedence by heart for complex
statements, add parentheses to ease readability and make the intent clear.


## ifdef hell

Avoid ifdef's as much as possible.
Platform support checking should be performed in configure.librdkafka.





# librdkafka C++ style guide

Follow [Google's C++ style guide](https://google.github.io/styleguide/cppguide.html)