Skip to content

Commit

Permalink
Merge branch '6.x' into 7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb committed Oct 25, 2024
2 parents 0a2d668 + 3cdcdf5 commit 1a3429f
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 35 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ jobs:
librdkafka: 'v1.9.2'
memcheck: '1'

# X32
- php: '8.3.0'
librdkafka: 'v2.6.0'
arch: 'X32'

# Latest librdkafka 2.x
- php: '8.3.0'
librdkafka: 'v2.6.0'
Expand Down Expand Up @@ -86,6 +91,7 @@ jobs:
SKIP_OAUTH: ${{ matrix.skipoauth }}
TEST_KAFKA_BROKERS: kafka:9092
TEST_KAFKA_BROKER_VERSION: 2.6
ARCH: ${{ matrix.arch }}
steps:
- name: 'Check out repository'
uses: 'actions/checkout@v2'
Expand All @@ -95,12 +101,15 @@ jobs:
- uses: actions/cache@v2
with:
path: ~/build-cache/php
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.memcheck }}
key: ${{ runner.os }}-${{ matrix.arch }}-${{ matrix.php }}-${{ matrix.memcheck }}

- uses: actions/cache@v2
with:
path: ~/build-cache/librdkafka
key: ${{ runner.os }}-${{ matrix.librdkafka }}
key: ${{ runner.os }}-${{ matrix.arch }}-${{ matrix.librdkafka }}

- name: 'Install dependencies'
run: './php-rdkafka/.github/workflows/test/install-dependencies.sh'

- name: 'Build librdkafka'
run: './php-rdkafka/.github/workflows/test/build-librdkafka.sh'
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/test/build-librdkafka.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ if ! [ -f ~/build-cache/librdkafka/usr/local/include/librdkafka/rdkafka.h ] || !

git clone --depth 1 --branch "${LIBRDKAFKA_VERSION:-v2.3.0}" "${LIBRDKAFKA_REPOSITORY_URL:-https://github.com/edenhill/librdkafka.git}"

LIBRDKAFKA_BUILD_FLAGS=

if [ "$ARCH" = "X32" ]; then
export CC="${CC:-gcc} -m32"
export CFLAGS="$CFLAGS -m32"
export CXXFLAGS="$CXXFLAGS -m32"
export LDFLAGS="$LDFLAGS -m32"
LIBRDKAFKA_BUILD_FLAGS="$LIBRDKAFKA_BUILD_FLAGS --build=i686-pc-linux-gnu"
fi

cd librdkafka
./configure
make
./configure $LIBRDKAFKA_BUILD_FLAGS
make -j $(nproc)
mkdir -p ~/build-cache/librdkafka
sudo make install DESTDIR=$HOME/build-cache/librdkafka
test -f ~/build-cache/librdkafka/usr/local/include/librdkafka/rdkafka.h || echo "librdkafka build failed"
Expand All @@ -22,7 +32,7 @@ if ! [ -f ~/build-cache/librdkafka/usr/local/include/librdkafka/rdkafka.h ] || !

cd kafkacat
./configure
make
make -j $(nproc)
sudo make install DESTDIR=$HOME/build-cache/librdkafka

else
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/test/build-php-rdkafka.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ PACKAGE_VERSION="$(grep -m 1 '<release>' package.xml|cut -d'>' -f2|cut -d'<' -f1

pecl package

if [ $MEMORY_CHECK -eq 1 ]; then
PHP_RDKAFKA_CFLAGS="-Wall -Werror -Wno-deprecated-declarations"
if [ $MEMORY_CHECK -eq 1 ] || [ "$ARCH" = "X32" ]; then
export CFLAGS="$CFLAGS -Wall -Werror -Wno-deprecated-declarations"
fi

sudo CFLAGS="$PHP_RDKAFKA_CFLAGS" pecl install "./rdkafka-$PACKAGE_VERSION.tgz"
if [ "$ARCH" = "X32" ]; then
export CC="${CC:-gcc} -m32"
export CFLAGS="$CFLAGS -m32"
export CXXFLAGS="$CXXFLAGS -m32"
export LDFLAGS="$LDFLAGS -m32"
fi

sudo -E pecl install "./rdkafka-$PACKAGE_VERSION.tgz"

echo "extension=rdkafka.so"|sudo tee /usr/local/etc/php/rdkafka.ini >/dev/null
12 changes: 8 additions & 4 deletions .github/workflows/test/build-php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

set -ex

if [ $MEMORY_CHECK -eq 1 ]; then
sudo apt-get -y install valgrind
fi

if ! [ -f ~/build-cache/php/usr/local/bin/php ]; then
echo "PHP build is not cached"

Expand All @@ -22,6 +18,14 @@ if ! [ -f ~/build-cache/php/usr/local/bin/php ]; then
PHP_BUILD_FLAGS="$PHP_BUILD_FLAGS --enable-zts"
fi

if [ "$ARCH" = "X32" ]; then
export CC="${CC:-gcc} -m32"
export CFLAGS="$CFLAGS -m32"
export CXXFLAGS="$CXXFLAGS -m32"
export LDFLAGS="$LDFLAGS -m32"
PHP_BUILD_FLAGS="$PHP_BUILD_FLAGS --build=i686-pc-linux-gnu"
fi

./configure $PHP_BUILD_FLAGS $PHP_BUILD_EXTRA_FLAGS
make -j $(nproc)
mkdir -p ~/build-cache/php
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/test/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

set -ex

export DEBIAN_FRONTEND=noninteractive

DEPS="zlib1g-dev libssl-dev"

if [ "$ARCH" = "X32" ]; then
sudo dpkg --add-architecture i386
sudo apt-get update
DEPS="$DEPS gcc-multilib g++-multilib zlib1g-dev:i386 libssl-dev:i386"
fi

if [ "$MEMORY_CHECK" = "1" ]; then
DEPS="$DEPS valgrind"
fi

if [ -n "$DEPS" ]; then
sudo apt-get -y install $DEPS
fi
2 changes: 0 additions & 2 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,6 @@ static void kafka_conf_set_oauthbearer_token_refresh_cb(rd_kafka_t *rk, const ch
zval_ptr_dtor(&args[1]);
}



/* {{{ proto RdKafka\Conf::__construct() */
PHP_METHOD(RdKafka_Conf, __construct)
{
Expand Down
28 changes: 25 additions & 3 deletions rdkafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ PHP_METHOD(RdKafka, setLogLevel)
}
/* }}} */

/* {{{ proto void RdKafka::oauthbearerSetToken(string $token_value, int $lifetime_ms, string $principal_name, array $extensions = [])
/* {{{ proto void RdKafka::oauthbearerSetToken(string $token_value, int|float|string $lifetime_ms, string $principal_name, array $extensions = [])
* Set SASL/OAUTHBEARER token and metadata
*
* The SASL/OAUTHBEARER token refresh callback or event handler should cause
Expand All @@ -440,18 +440,40 @@ PHP_METHOD(RdKafka, oauthbearerSetToken)
kafka_object *intern;
char *token_value;
size_t token_value_len;
zend_long lifetime_ms;
zval *zlifetime_ms;
int64_t lifetime_ms;
char *principal_name;
size_t principal_len;
HashTable *extensions_hash = NULL;

char errstr[512];
rd_kafka_resp_err_t ret = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "sls|h", &token_value, &token_value_len, &lifetime_ms, &principal_name, &principal_len, &extensions_hash) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "szs|h", &token_value, &token_value_len, &zlifetime_ms, &principal_name, &principal_len, &extensions_hash) == FAILURE) {
return;
}

/* On 32-bits, it might be required to pass $lifetime_ms as a float or a
* string */
switch (Z_TYPE_P(zlifetime_ms)) {
case IS_LONG:
lifetime_ms = (int64_t) Z_LVAL_P(zlifetime_ms);
break;
case IS_DOUBLE:
lifetime_ms = (int64_t) Z_DVAL_P(zlifetime_ms);
break;
case IS_STRING:;
char *str = Z_STRVAL_P(zlifetime_ms);
char *end;
lifetime_ms = (int64_t) strtoll(str, &end, 10);
if (end != str + Z_STRLEN_P(zlifetime_ms)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Argument #2 ($lifetime_ms) must be a valid integer");
return;
}
break;
EMPTY_SWITCH_DEFAULT_CASE();
}

intern = get_kafka_object(getThis());
if (!intern) {
return;
Expand Down
2 changes: 1 addition & 1 deletion rdkafka.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function pausePartitions(array $topic_partitions): array {}
public function resumePartitions(array $topic_partitions): array {}

/** @tentative-return-type */
public function oauthbearerSetToken(string $token_value, int $lifetime_ms, string $principal_name, array $extensions = []): void {}
public function oauthbearerSetToken(string $token_value, int|float|string $lifetime_ms, string $principal_name, array $extensions = []): void {}

/** @tentative-return-type */
public function oauthbearerSetTokenFailure(string $error): void {}
Expand Down
4 changes: 2 additions & 2 deletions rdkafka_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 278f62b10f92f6211d8095be7fb0eef539ecca2e */
* Stub hash: a7de61984c96ac34a70cd48ea1785a4ed5ed00d5 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -115,7 +115,7 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_RdKafka_oauthbea
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_oauthbearerSetToken, 0, 0, 3)
#endif
ZEND_ARG_TYPE_INFO(0, token_value, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, lifetime_ms, IS_LONG, 0)
ZEND_ARG_TYPE_MASK(0, lifetime_ms, MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING, NULL)
ZEND_ARG_TYPE_INFO(0, principal_name, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, extensions, IS_ARRAY, 0, "[]")
ZEND_END_ARG_INFO()
Expand Down
2 changes: 1 addition & 1 deletion tests/bug508.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ array(10) {
["topic_name"]=>
string(%d) "test_rdkafka_%s"
["timestamp"]=>
int(%d)
int(%f)
["partition"]=>
int(0)
["payload"]=>
Expand Down
5 changes: 3 additions & 2 deletions tests/oauthbearer_integration.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ $conf->setErrorCb(function ($producer, $err, $errstr) {
$conf->setOauthbearerTokenRefreshCb(function ($producer) {
echo "Refreshing token and succeeding\n";
$token = generateJws();
$producer->oauthbearerSetToken($token['value'], $token['expiryMs'], $token['principal']);
$producer->oauthbearerSetToken($token['value'], (string) $token['expiryMs'], $token['principal']);
});
$producer = new \RdKafka\Producer($conf);
$producer->poll(0);
Expand All @@ -64,7 +64,8 @@ try {
$producer->getMetadata(false, $topic, 10*1000);
echo "Metadata retrieved successfully when refresh callback set token\n";
} catch (\RdKafka\Exception $e) {
echo "FAIL: Caught exception when getting metadata after successfully refreshing any token\n";
echo "FAIL: Caught exception when getting metadata after successfully refreshing any token:\n";
printf("%s: %s\n", get_class($e), $e->getMessage());
}

// Test that refresh token with setting token failure will fail when getting metadata
Expand Down
24 changes: 12 additions & 12 deletions topic.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ PHP_METHOD(RdKafka_ConsumerTopic, consumeCallback)
}

if (partition < 0 || partition > 0x7FFFFFFF) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '%ld' for $partition", partition);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '" ZEND_LONG_FMT "' for $partition", partition);
return;
}

Expand Down Expand Up @@ -161,7 +161,7 @@ PHP_METHOD(RdKafka_ConsumerTopic, consumeQueueStart)
}

if (partition != RD_KAFKA_PARTITION_UA && (partition < 0 || partition > 0x7FFFFFFF)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '%ld' for $partition", partition);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '" ZEND_LONG_FMT "' for $partition", partition);
return;
}

Expand Down Expand Up @@ -219,7 +219,7 @@ PHP_METHOD(RdKafka_ConsumerTopic, consumeStart)
}

if (partition != RD_KAFKA_PARTITION_UA && (partition < 0 || partition > 0x7FFFFFFF)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '%ld' for $partition", partition);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '" ZEND_LONG_FMT "' for $partition", partition);
return;
}

Expand Down Expand Up @@ -271,7 +271,7 @@ PHP_METHOD(RdKafka_ConsumerTopic, consumeStop)
}

if (partition != RD_KAFKA_PARTITION_UA && (partition < 0 || partition > 0x7FFFFFFF)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '%ld' for $partition", partition);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '" ZEND_LONG_FMT "' for $partition", partition);
return;
}

Expand Down Expand Up @@ -312,7 +312,7 @@ PHP_METHOD(RdKafka_ConsumerTopic, consume)
}

if (partition != RD_KAFKA_PARTITION_UA && (partition < 0 || partition > 0x7FFFFFFF)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '%ld' for $partition", partition);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '" ZEND_LONG_FMT "' for $partition", partition);
return;
}

Expand Down Expand Up @@ -353,12 +353,12 @@ PHP_METHOD(RdKafka_ConsumerTopic, consumeBatch)
}

if (0 >= batch_size) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '%ld' for batch_size", batch_size);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '" ZEND_LONG_FMT "' for batch_size", batch_size);
return;
}

if (partition != RD_KAFKA_PARTITION_UA && (partition < 0 || partition > 0x7FFFFFFF)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '%ld' for $partition", partition);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '" ZEND_LONG_FMT "' for $partition", partition);
return;
}

Expand Down Expand Up @@ -402,7 +402,7 @@ PHP_METHOD(RdKafka_ConsumerTopic, offsetStore)
}

if (partition < 0 || partition > 0x7FFFFFFF) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '%ld' for $partition", partition);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '" ZEND_LONG_FMT "' for $partition", partition);
return;
}

Expand Down Expand Up @@ -445,12 +445,12 @@ PHP_METHOD(RdKafka_ProducerTopic, produce)
ZEND_PARSE_PARAMETERS_END();

if (partition != RD_KAFKA_PARTITION_UA && (partition < 0 || partition > 0x7FFFFFFF)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '%ld' for $partition", partition);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '" ZEND_LONG_FMT "' for $partition", partition);
return;
}

if (msgflags != 0 && msgflags != RD_KAFKA_MSG_F_BLOCK) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Invalid value '%ld' for $msgflags", msgflags);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Invalid value '" ZEND_LONG_FMT "' for $msgflags", msgflags);
return;
}

Expand Down Expand Up @@ -507,12 +507,12 @@ PHP_METHOD(RdKafka_ProducerTopic, producev)
ZEND_PARSE_PARAMETERS_END();

if (partition != RD_KAFKA_PARTITION_UA && (partition < 0 || partition > 0x7FFFFFFF)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '%ld' for $partition", partition);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Out of range value '" ZEND_LONG_FMT "' for $partition", partition);
return;
}

if (msgflags != 0 && msgflags != RD_KAFKA_MSG_F_BLOCK) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Invalid value '%ld' for $msgflags", msgflags);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Invalid value '" ZEND_LONG_FMT "' for $msgflags", msgflags);
return;
}

Expand Down

0 comments on commit 1a3429f

Please sign in to comment.