Skip to content

Commit fe5bdd1

Browse files
committed
Merge branch 'main' into 918_modernbuild_draft_centos
2 parents c2cd835 + 67ee736 commit fe5bdd1

File tree

61 files changed

+1035
-249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1035
-249
lines changed

agent/native/ext/ConfigManager.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, disableInstrumentations )
778778
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( boolValue, disableSend )
779779
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( boolValue, enabled )
780780
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, environment )
781+
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, globalLabels )
781782
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, hostname )
782783
ELASTIC_APM_DEFINE_ENUM_FIELD_ACCESS_FUNCS( InternalChecksLevel, internalChecksLevel )
783784
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, logFile )
@@ -1012,6 +1013,12 @@ static void initOptionsMetadata( OptionMetadata* optsMeta )
10121013
ELASTIC_APM_CFG_OPT_NAME_ENVIRONMENT,
10131014
/* defaultValue: */ NULL );
10141015

1016+
ELASTIC_APM_INIT_METADATA(
1017+
buildStringOptionMetadata,
1018+
globalLabels,
1019+
ELASTIC_APM_CFG_OPT_NAME_GLOBAL_LABELS,
1020+
/* defaultValue: */ NULL );
1021+
10151022
ELASTIC_APM_INIT_METADATA(
10161023
buildStringOptionMetadata,
10171024
hostname,

agent/native/ext/ConfigManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ enum OptionId
8080
optionId_disableSend,
8181
optionId_enabled,
8282
optionId_environment,
83+
optionId_globalLabels,
8384
optionId_hostname,
8485
optionId_internalChecksLevel,
8586
optionId_logFile,
@@ -262,6 +263,7 @@ const ConfigSnapshot* getGlobalCurrentConfigSnapshot();
262263
#define ELASTIC_APM_CFG_OPT_NAME_DISABLE_SEND "disable_send"
263264
#define ELASTIC_APM_CFG_OPT_NAME_ENABLED "enabled"
264265
#define ELASTIC_APM_CFG_OPT_NAME_ENVIRONMENT "environment"
266+
#define ELASTIC_APM_CFG_OPT_NAME_GLOBAL_LABELS "global_labels"
265267
#define ELASTIC_APM_CFG_OPT_NAME_HOSTNAME "hostname"
266268

267269
/**

agent/native/ext/ConfigSnapshot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct ConfigSnapshot
5151
bool disableSend;
5252
bool enabled;
5353
String environment;
54+
String globalLabels;
5455
String hostname;
5556
InternalChecksLevel internalChecksLevel;
5657
String logFile;

agent/native/ext/elastic_apm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ PHP_INI_BEGIN()
154154
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_DISABLE_INSTRUMENTATIONS )
155155
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_DISABLE_SEND )
156156
ELASTIC_APM_NOT_RELOADABLE_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_ENABLED )
157+
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_GLOBAL_LABELS )
157158
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_ENVIRONMENT )
158159
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_HOSTNAME )
159160
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_INTERNAL_CHECKS_LEVEL )

agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public static function get(): array
9595
OptionNames::DISABLE_SEND => new BoolOptionMetadata(/* default */ false),
9696
OptionNames::ENABLED => new BoolOptionMetadata(/* default */ true),
9797
OptionNames::ENVIRONMENT => new NullableStringOptionMetadata(),
98+
OptionNames::GLOBAL_LABELS => new NullableLabelsOptionMetadata(),
9899
OptionNames::HOSTNAME => new NullableStringOptionMetadata(),
99100
OptionNames::LOG_LEVEL => new NullableLogLevelOptionMetadata(),
100101
OptionNames::LOG_LEVEL_STDERR => new NullableLogLevelOptionMetadata(),
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/*
4+
* Licensed to Elasticsearch B.V. under one or more contributor
5+
* license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright
7+
* ownership. Elasticsearch B.V. licenses this file to you under
8+
* the Apache License, Version 2.0 (the "License"); you may
9+
* not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace Elastic\Apm\Impl\Config;
25+
26+
use Elastic\Apm\Impl\Log\LoggableToString;
27+
use Elastic\Apm\Impl\Util\TextUtil;
28+
29+
/**
30+
* Code in this file is part of implementation internals and thus it is not covered by the backward compatibility.
31+
*
32+
* @internal
33+
*
34+
* @extends OptionParser<array<string>>
35+
*/
36+
final class KeyValuePairsOptionParser extends OptionParser
37+
{
38+
/**
39+
* @param string $rawValue
40+
*
41+
* @return array<string>
42+
*/
43+
public function parse(string $rawValue): array
44+
{
45+
// Value format:
46+
// key=value[,key=value[,...]]
47+
48+
// Treat empty string as zero key-value pairs
49+
if (TextUtil::isEmptyString($rawValue)) {
50+
return [];
51+
}
52+
53+
$pairs = explode(',', $rawValue);
54+
$result = [];
55+
foreach ($pairs as $keyValuePair) {
56+
$keyValueSeparatorPos = strpos($keyValuePair, '=');
57+
if ($keyValueSeparatorPos === false) {
58+
throw new ParseException('One of key-value pairs is missing key-value separator' . ' ;' . LoggableToString::convert(['keyValuePair' => $keyValuePair, 'rawValue' => $rawValue]));
59+
}
60+
$key = trim(substr($keyValuePair, /* offset */ 0, /* length */ $keyValueSeparatorPos));
61+
$value = ($keyValueSeparatorPos === (strlen($keyValuePair) - 1)) ? '' : trim(substr($keyValuePair, /* offset */ $keyValueSeparatorPos + 1));
62+
if (array_key_exists($key, $result)) {
63+
throw new ParseException(
64+
'Key is present more than once'
65+
. ' ;' . LoggableToString::convert(['key' => $key, '1st value' => $result[$key], '2nd value' => $value, '2nd keyValuePair' => $keyValuePair, 'rawValue' => $rawValue])
66+
);
67+
}
68+
$result[$key] = $value;
69+
}
70+
return $result;
71+
}
72+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/*
4+
* Licensed to Elasticsearch B.V. under one or more contributor
5+
* license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright
7+
* ownership. Elasticsearch B.V. licenses this file to you under
8+
* the Apache License, Version 2.0 (the "License"); you may
9+
* not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace Elastic\Apm\Impl\Config;
25+
26+
use Elastic\Apm\Impl\Tracer;
27+
28+
/**
29+
* Code in this file is part of implementation internals and thus it is not covered by the backward compatibility.
30+
*
31+
* @internal
32+
*
33+
* @extends OptionParser<array<string|bool|int|float|null>>
34+
*/
35+
final class LabelsOptionParser extends OptionParser
36+
{
37+
/**
38+
* @param string $valueAsString
39+
*
40+
* @return string|bool|int|float|null
41+
*/
42+
private static function parseValue(string $valueAsString)
43+
{
44+
if ($valueAsString === 'true') {
45+
return true;
46+
}
47+
if ($valueAsString === 'false') {
48+
return false;
49+
}
50+
51+
if (filter_var($valueAsString, FILTER_VALIDATE_INT) !== false) {
52+
return intval($valueAsString);
53+
}
54+
55+
if (filter_var($valueAsString, FILTER_VALIDATE_FLOAT) !== false) {
56+
return floatval($valueAsString);
57+
}
58+
59+
if ($valueAsString === 'null') {
60+
return null;
61+
}
62+
63+
return Tracer::limitKeywordString($valueAsString);
64+
}
65+
66+
/**
67+
* @param string $rawValue
68+
*
69+
* @return array<string|bool|int|float|null>
70+
*/
71+
public function parse(string $rawValue): array
72+
{
73+
// Value format:
74+
// key=value[,key=value[,...]]
75+
76+
$result = [];
77+
foreach ((new KeyValuePairsOptionParser())->parse($rawValue) as $key => $valueAsString) {
78+
$result[is_string($key) ? Tracer::limitKeywordString($key) : $key] = self::parseValue($valueAsString);
79+
}
80+
return $result;
81+
}
82+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* Licensed to Elasticsearch B.V. under one or more contributor
5+
* license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright
7+
* ownership. Elasticsearch B.V. licenses this file to you under
8+
* the Apache License, Version 2.0 (the "License"); you may
9+
* not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace Elastic\Apm\Impl\Config;
25+
26+
/**
27+
* Code in this file is part of implementation internals and thus it is not covered by the backward compatibility.
28+
*
29+
* @internal
30+
*
31+
* @extends NullableOptionMetadata<array<string|bool|int|float|null>>
32+
*
33+
* @noinspection PhpUnused
34+
*/
35+
final class NullableLabelsOptionMetadata extends NullableOptionMetadata
36+
{
37+
public function __construct()
38+
{
39+
parent::__construct(new LabelsOptionParser());
40+
}
41+
}

agent/php/ElasticApm/Impl/Config/OptionNames.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ final class OptionNames
4747
public const DISABLE_SEND = 'disable_send';
4848
public const ENABLED = 'enabled';
4949
public const ENVIRONMENT = 'environment';
50+
public const GLOBAL_LABELS = 'global_labels';
5051
public const HOSTNAME = 'hostname';
5152
public const INTERNAL_CHECKS_LEVEL = 'internal_checks_level';
5253
public const LOG_LEVEL = 'log_level';

agent/php/ElasticApm/Impl/Config/Snapshot.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ final class Snapshot implements LoggableInterface
137137
/** @var ?string */
138138
private $environment;
139139

140+
/** @var ?array<string|bool|int|float|null> */
141+
private $globalLabels;
142+
140143
/** @var ?string */
141144
private $hostname;
142145

@@ -309,6 +312,14 @@ public function environment(): ?string
309312
return $this->environment;
310313
}
311314

315+
/**
316+
* @return ?array<string|bool|int|float|null>
317+
*/
318+
public function globalLabels(): ?array
319+
{
320+
return $this->globalLabels;
321+
}
322+
312323
public function hostname(): ?string
313324
{
314325
return $this->hostname;

0 commit comments

Comments
 (0)