Skip to content

Commit

Permalink
Merge branch 'master' into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKleyman committed Jan 10, 2022
2 parents 91adb1d + 8cb0149 commit 9819653
Show file tree
Hide file tree
Showing 53 changed files with 2,267 additions and 601 deletions.
2 changes: 1 addition & 1 deletion .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pipeline {
NOTIFY_TO = '[email protected]'
ONLY_DOCS = "false"
GITHUB_CHECK_ITS_NAME = 'Integration Tests'
ITS_PIPELINE = 'apm-integration-tests-selector-mbp/master'
ITS_PIPELINE = 'apm-integration-tests-selector-mbp/main'
}
options {
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ endif::[]
// Using the template above, release notes go here.
// CHANGELOG_AUTOMATION_KEYWORD
[[release-notes-v1.4]]
=== v1.4 - 2022/01/10
[float]
==== Features
* Background (non-blocking) communication with APM Server: {pull}584[#584]
[[release-notes-v1.3.1]]
=== v1.3.1 - 2021/10/18
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[[release-notes]]
== Release notes

* <<release-notes-v1.4>>
* <<release-notes-v1.3.1>>
* <<release-notes-v1.3>>
* <<release-notes-v1.2>>
Expand Down
2 changes: 1 addition & 1 deletion src/ElasticApm/ElasticApm.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class ElasticApm
{
use StaticClassTrait;

public const VERSION = '1.3.1';
public const VERSION = '1.4';

/**
* Begins a new transaction and sets it as the current transaction.
Expand Down
71 changes: 37 additions & 34 deletions src/ElasticApm/Impl/Config/AllOptionsMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,45 @@ final class AllOptionsMetadata
*/
public static function get(): array
{
if (!isset(self::$vaLue)) {
self::$vaLue = [
OptionNames::API_KEY => new NullableStringOptionMetadata(),
OptionNames::BREAKDOWN_METRICS => new BoolOptionMetadata(/* defaultValue: */ true),
OptionNames::DEV_INTERNAL => new NullableWildcardListOptionMetadata(),
OptionNames::DISABLE_INSTRUMENTATIONS => new NullableWildcardListOptionMetadata(),
OptionNames::DISABLE_SEND => new BoolOptionMetadata(/* defaultValue: */ false),
OptionNames::ENABLED => new BoolOptionMetadata(/* defaultValue: */ true),
OptionNames::ENVIRONMENT => new NullableStringOptionMetadata(),
OptionNames::HOSTNAME => new NullableStringOptionMetadata(),
OptionNames::LOG_LEVEL => new NullableLogLevelOptionMetadata(),
OptionNames::LOG_LEVEL_STDERR => new NullableLogLevelOptionMetadata(),
OptionNames::LOG_LEVEL_SYSLOG => new NullableLogLevelOptionMetadata(),
OptionNames::SECRET_TOKEN => new NullableStringOptionMetadata(),
OptionNames::SERVER_TIMEOUT => new DurationOptionMetadata(
0.0 /* <- minValidValueInMilliseconds */,
null /* <- maxValidValueInMilliseconds */,
DurationUnits::SECONDS /* <- defaultUnits */,
30 * 1000.0 /* <- defaultValueInMilliseconds - 30s */
),
OptionNames::SERVICE_NAME => new NullableStringOptionMetadata(),
OptionNames::SERVICE_NODE_NAME => new NullableStringOptionMetadata(),
OptionNames::SERVICE_VERSION => new NullableStringOptionMetadata(),
OptionNames::TRANSACTION_IGNORE_URLS => new NullableWildcardListOptionMetadata(),
OptionNames::TRANSACTION_MAX_SPANS => new IntOptionMetadata(
0 /* <- minValidValue */,
null /* <- maxValidValue */,
OptionDefaultValues::TRANSACTION_MAX_SPANS
),
OptionNames::TRANSACTION_SAMPLE_RATE =>
new FloatOptionMetadata(/* minValidValue */ 0.0, /* maxValidValue */ 1.0, /* defaultValue */ 1.0),
OptionNames::URL_GROUPS => new NullableWildcardListOptionMetadata(),
OptionNames::VERIFY_SERVER_CERT => new BoolOptionMetadata(/* defaultValue: */ true),
];
if (isset(self::$vaLue)) {
return self::$vaLue;
}

self::$vaLue = [
OptionNames::API_KEY => new NullableStringOptionMetadata(),
OptionNames::ASYNC_BACKEND_COMM => new BoolOptionMetadata(/* defaultValue: */ true),
OptionNames::BREAKDOWN_METRICS => new BoolOptionMetadata(/* defaultValue: */ true),
OptionNames::DEV_INTERNAL => new NullableWildcardListOptionMetadata(),
OptionNames::DISABLE_INSTRUMENTATIONS => new NullableWildcardListOptionMetadata(),
OptionNames::DISABLE_SEND => new BoolOptionMetadata(/* defaultValue: */ false),
OptionNames::ENABLED => new BoolOptionMetadata(/* defaultValue: */ true),
OptionNames::ENVIRONMENT => new NullableStringOptionMetadata(),
OptionNames::HOSTNAME => new NullableStringOptionMetadata(),
OptionNames::LOG_LEVEL => new NullableLogLevelOptionMetadata(),
OptionNames::LOG_LEVEL_STDERR => new NullableLogLevelOptionMetadata(),
OptionNames::LOG_LEVEL_SYSLOG => new NullableLogLevelOptionMetadata(),
OptionNames::SECRET_TOKEN => new NullableStringOptionMetadata(),
OptionNames::SERVER_TIMEOUT => new DurationOptionMetadata(
0.0 /* <- minValidValueInMilliseconds */,
null /* <- maxValidValueInMilliseconds */,
DurationUnits::SECONDS /* <- defaultUnits */,
30 * 1000.0 /* <- defaultValueInMilliseconds - 30s */
),
OptionNames::SERVICE_NAME => new NullableStringOptionMetadata(),
OptionNames::SERVICE_NODE_NAME => new NullableStringOptionMetadata(),
OptionNames::SERVICE_VERSION => new NullableStringOptionMetadata(),
OptionNames::TRANSACTION_IGNORE_URLS => new NullableWildcardListOptionMetadata(),
OptionNames::TRANSACTION_MAX_SPANS => new IntOptionMetadata(
0 /* <- minValidValue */,
null /* <- maxValidValue */,
OptionDefaultValues::TRANSACTION_MAX_SPANS
),
OptionNames::TRANSACTION_SAMPLE_RATE =>
new FloatOptionMetadata(/* minValidValue */ 0.0, /* maxValidValue */ 1.0, /* defaultValue */ 1.0),
OptionNames::URL_GROUPS => new NullableWildcardListOptionMetadata(),
OptionNames::VERIFY_SERVER_CERT => new BoolOptionMetadata(/* defaultValue: */ true),
];

return self::$vaLue;
}
}
1 change: 1 addition & 0 deletions src/ElasticApm/Impl/Config/OptionNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class OptionNames
use StaticClassTrait;

public const API_KEY = 'api_key';
public const ASYNC_BACKEND_COMM = 'async_backend_comm';
public const BREAKDOWN_METRICS = 'breakdown_metrics';
public const DEV_INTERNAL = 'dev_internal';
public const DISABLE_INSTRUMENTATIONS = 'disable_instrumentations';
Expand Down
3 changes: 3 additions & 0 deletions src/ElasticApm/Impl/Config/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ final class Snapshot implements LoggableInterface
/** @var string */
private $apiKey;

/** @var bool */
private $asyncBackendComm;

/** @var bool */
private $breakdownMetrics;

Expand Down
7 changes: 7 additions & 0 deletions src/ext/ConfigManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, apiKey )
# if ( ELASTIC_APM_ASSERT_ENABLED_01 != 0 )
ELASTIC_APM_DEFINE_ENUM_FIELD_ACCESS_FUNCS( AssertLevel, assertLevel )
# endif
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( boolValue, asyncBackendComm )
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, bootstrapPhpPartFile )
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( boolValue, breakdownMetrics )
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, devInternal )
Expand Down Expand Up @@ -692,6 +693,12 @@ static void initOptionsMetadata( OptionMetadata* optsMeta )
/* isUniquePrefixEnough: */ true );
#endif

ELASTIC_APM_INIT_METADATA(
buildBoolOptionMetadata,
asyncBackendComm,
ELASTIC_APM_CFG_OPT_NAME_ASYNC_BACKEND_COMM,
/* defaultValue: */ true );

ELASTIC_APM_INIT_METADATA(
buildStringOptionMetadata,
bootstrapPhpPartFile,
Expand Down
3 changes: 3 additions & 0 deletions src/ext/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ enum OptionId
#if ( ELASTIC_APM_ASSERT_ENABLED_01 != 0 )
optionId_assertLevel,
#endif
optionId_asyncBackendComm,
optionId_bootstrapPhpPartFile,
optionId_breakdownMetrics,
optionId_devInternal,
Expand Down Expand Up @@ -116,6 +117,7 @@ struct ConfigSnapshot
AssertLevel assertLevel;
#endif
String apiKey;
bool asyncBackendComm;
String bootstrapPhpPartFile;
bool breakdownMetrics;
String devInternal;
Expand Down Expand Up @@ -240,6 +242,7 @@ const ConfigSnapshot* getGlobalCurrentConfigSnapshot();
# if ( ELASTIC_APM_ASSERT_ENABLED_01 != 0 )
#define ELASTIC_APM_CFG_OPT_NAME_ASSERT_LEVEL "assert_level"
# endif
#define ELASTIC_APM_CFG_OPT_NAME_ASYNC_BACKEND_COMM "async_backend_comm"
#define ELASTIC_APM_CFG_OPT_NAME_BOOTSTRAP_PHP_PART_FILE "bootstrap_php_part_file"
#define ELASTIC_APM_CFG_OPT_NAME_BREAKDOWN_METRICS "breakdown_metrics"
#define ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL "dev_internal"
Expand Down
8 changes: 8 additions & 0 deletions src/ext/ResultCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ static inline String resultCodeToString( ResultCode resultCode )
resultCode = (expr); \
if ( resultCode != resultSuccess ) goto failure; \
} while ( 0 )

#define ELASTIC_APM_SET_RESULT_CODE_AND_GOTO_FAILURE_EX( failureResultCode ) \
do { \
resultCode = (failureResultCode); \
goto failure; \
} while ( 0 )

#define ELASTIC_APM_SET_RESULT_CODE_AND_GOTO_FAILURE() ELASTIC_APM_SET_RESULT_CODE_AND_GOTO_FAILURE_EX( resultFailure )
156 changes: 156 additions & 0 deletions src/ext/TextOutputStream.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include "TextOutputStream.h"

TextOutputStream makeTextOutputStream( char* bufferBegin, size_t bufferSize )
{
ELASTIC_APM_ASSERT_VALID_PTR( bufferBegin );
ELASTIC_APM_ASSERT_GE_UINT64( bufferSize, ELASTIC_APM_TEXT_OUTPUT_STREAM_MIN_BUFFER_SIZE );

TextOutputStream txtOutStream =
{
.bufferBegin = bufferBegin,
.bufferSize = bufferSize,
.freeSpaceBegin = bufferBegin,
.isOverflowed = false,
.autoTermZero = true,
.shouldEncloseUserString = true
};
ELASTIC_APM_ASSERT_VALID_PTR_TEXT_OUTPUT_STREAM( &txtOutStream );

// We cannot work with a buffer that doesn't have reserved space
if ( bufferSize < ELASTIC_APM_TEXT_OUTPUT_STREAM_MIN_BUFFER_SIZE )
{
txtOutStream.isOverflowed = true;

// If buffer is not zero sized then mark it as empty
if ( bufferSize != 0 ) *bufferBegin = '\0';

ELASTIC_APM_ASSERT( textOutputStreamIsOverflowed( &txtOutStream ), "" );
}

ELASTIC_APM_ASSERT_VALID_PTR_TEXT_OUTPUT_STREAM( &txtOutStream );
return txtOutStream;
}

bool textOutputStreamStartEntry( TextOutputStream* txtOutStream, TextOutputStreamState* txtOutStreamState )
{
ELASTIC_APM_ASSERT_VALID_PTR_TEXT_OUTPUT_STREAM( txtOutStream );
ELASTIC_APM_ASSERT_VALID_PTR( txtOutStreamState );

if ( textOutputStreamIsOverflowed( txtOutStream ) ) return false;

txtOutStreamState->autoTermZero = txtOutStream->autoTermZero;
txtOutStreamState->freeSpaceBegin = txtOutStream->freeSpaceBegin;

txtOutStream->autoTermZero = false;

return true;
}

String streamStringView( StringView value, TextOutputStream* txtOutStream )
{
TextOutputStreamState txtOutStreamStateOnEntryStart;
if ( ! textOutputStreamStartEntry( txtOutStream, &txtOutStreamStateOnEntryStart ) )
return ELASTIC_APM_TEXT_OUTPUT_STREAM_NOT_ENOUGH_SPACE_MARKER;

const size_t freeSizeBeforeWrite = textOutputStreamGetFreeSpaceSize( txtOutStream );

const size_t numberOfCharsToCopy = ELASTIC_APM_MIN( value.length, freeSizeBeforeWrite );
if ( numberOfCharsToCopy != 0 )
memcpy( txtOutStreamStateOnEntryStart.freeSpaceBegin, value.begin, numberOfCharsToCopy * sizeof( char ) );
textOutputStreamSkipNChars( txtOutStream, numberOfCharsToCopy );

if ( numberOfCharsToCopy < value.length )
return textOutputStreamEndEntryAsOverflowed( &txtOutStreamStateOnEntryStart, txtOutStream );

return textOutputStreamEndEntry( &txtOutStreamStateOnEntryStart, txtOutStream );
}

String streamVPrintf( TextOutputStream* txtOutStream, String printfFmt, va_list printfFmtArgs )
{
TextOutputStreamState txtOutStreamStateOnEntryStart;
if ( ! textOutputStreamStartEntry( txtOutStream, &txtOutStreamStateOnEntryStart ) )
return ELASTIC_APM_TEXT_OUTPUT_STREAM_NOT_ENOUGH_SPACE_MARKER;

const size_t freeSpaceSize = textOutputStreamGetFreeSpaceSize( txtOutStream );

// We can take one more char from reserved space for printf's terminating '\0'
int snprintfRetVal = vsnprintf( txtOutStreamStateOnEntryStart.freeSpaceBegin, freeSpaceSize + 1, printfFmt, printfFmtArgs );

// snprintf: If an encoding error occurs, a negative number is returned
// so we don't change advance the buffer tracker
if ( snprintfRetVal < 0 ) return "<vsnprintf returned error>";

// snprintf: when returned value is non-negative and less than buffer-size
// then the string has been completely written
// otherwise it means buffer overflowed
const bool isOverflowed = ( snprintfRetVal > freeSpaceSize );
// snprintf always writes terminating '\0'
// but return value is number of chars written not counting the terminating '\0'
textOutputStreamSkipNChars( txtOutStream, isOverflowed ? freeSpaceSize : snprintfRetVal );

return ( isOverflowed )
? textOutputStreamEndEntryAsOverflowed( &txtOutStreamStateOnEntryStart, txtOutStream )
: textOutputStreamEndEntry( &txtOutStreamStateOnEntryStart, txtOutStream );
}

size_t textOutputStreamGetFreeSpaceSize( const TextOutputStream* txtOutStream )
{
ELASTIC_APM_ASSERT_VALID_PTR_TEXT_OUTPUT_STREAM( txtOutStream );

const size_t reservedAndUsedSpaceSize =
ELASTIC_APM_TEXT_OUTPUT_STREAM_RESERVED_SPACE_SIZE +
( txtOutStream->freeSpaceBegin - txtOutStream->bufferBegin );

if ( txtOutStream->bufferSize < reservedAndUsedSpaceSize ) return 0;

return txtOutStream->bufferSize - reservedAndUsedSpaceSize;
}

String textOutputStreamEndEntryAsOverflowed( const TextOutputStreamState* txtOutStreamStateOnEntryStart, TextOutputStream* txtOutStream )
{
ELASTIC_APM_ASSERT_VALID_PTR_TEXT_OUTPUT_STREAM( txtOutStream );

const char* const contentEnd = txtOutStream->freeSpaceBegin;

if ( ! textOutputStreamIsOverflowed( txtOutStream ) )
{
ELASTIC_APM_ASSERT( textOutputStreamHasReservedSpace( txtOutStream ), "" );

strcpy( txtOutStream->freeSpaceBegin, ELASTIC_APM_TEXT_OUTPUT_STREAM_OVERFLOWED_MARKER );
txtOutStream->freeSpaceBegin += ELASTIC_APM_TEXT_OUTPUT_STREAM_OVERFLOWED_MARKER_LENGTH;

txtOutStream->isOverflowed = true;
ELASTIC_APM_ASSERT( textOutputStreamIsOverflowed( txtOutStream ), "" );
}

return textOutputStreamEndEntryEx( contentEnd, txtOutStreamStateOnEntryStart,txtOutStream );
}

String textOutputStreamEndEntry( const TextOutputStreamState* txtOutStreamStateOnEntryStart, TextOutputStream* txtOutStream )
{
// If we need to append terminating '\0' but there's no space for it
// then we consider the stream as overflowed
if ( txtOutStreamStateOnEntryStart->autoTermZero && ( textOutputStreamGetFreeSpaceSize( txtOutStream ) == 0 ) )
return textOutputStreamEndEntryAsOverflowed( txtOutStreamStateOnEntryStart, txtOutStream );

return textOutputStreamEndEntryEx( /* contentEnd: */ txtOutStream->freeSpaceBegin, txtOutStreamStateOnEntryStart, txtOutStream );
}
Loading

0 comments on commit 9819653

Please sign in to comment.