Skip to content

Commit

Permalink
Merge pull request #5 from acya-skulskaya/master
Browse files Browse the repository at this point in the history
add Pyroscope Auth Token option

---------

Co-authored-by: Анастасия Скульская <[email protected]>
  • Loading branch information
xtrime-ru and Анастасия Скульская authored Aug 18, 2023
2 parents 0ebaadd + 02ff778 commit e44352c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Options:
-s, --pyroscope=STRING Url of the pyroscope server.
Example: https://your-pyroscope-sever.com
-auth, --pyroscopeAuthToken=STRING
Pyroscope Auth Token.
Example: psx-BWlqy_dW1Wxg6oBjuCWD28HxGCkB1Jfzt-jjtqHzrkzI
-a, --app=STRING Name of app.
All samples will be saved under given app name.
Example: app
Expand Down
10 changes: 9 additions & 1 deletion app/Commands/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ protected function configure(): void {
InputOption::VALUE_REQUIRED,
'Url of the pyroscope server. Example: https://your-pyroscope-sever.com'
),
new InputOption(
'pyroscopeAuthToken',
'auth',
InputOption::VALUE_OPTIONAL,
'Pyroscope Auth Token. Example: psx-BWlqy_dW1Wxg6oBjuCWD28HxGCkB1Jfzt-jjtqHzrkzI'
),
new InputOption(
'app',
'a',
Expand Down Expand Up @@ -116,6 +122,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
throw new InvalidArgumentException('sendSampleFutureLimit must be positive value');
}

$pyroscopeAuthToken = (string)$input->getOption('pyroscopeAuthToken');

$tags = [];
foreach ((array) $input->getOption('tags') as $tag) {
if (strpos($tag, '=') === false) {
Expand All @@ -140,7 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$processor = new Processor(
$interval,
$batch,
new Sender($pyroscope, $app, $rateHz, $tags),
new Sender($pyroscope, $app, $rateHz, $tags, $pyroscopeAuthToken),
array_values(array_filter($plugins)),
$sendSampleFutureLimit,
$concurrentRequestLimit,
Expand Down
4 changes: 4 additions & 0 deletions app/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(
private readonly string $appName,
private readonly int $rateHz,
private readonly array $tags,
private readonly string $authToken = '',
) {
$this->client = (new HttpClientBuilder())
->retry(0)
Expand All @@ -34,6 +35,9 @@ public function sendSample(Sample $sample): bool {
$request->setTlsHandshakeTimeout(5 * 60);
$request->setTransferTimeout(60 * 60);
$request->setInactivityTimeout(60 * 60);
if (!empty($this->authToken)) {
$request->addHeader('Authorization', 'Bearer ' . $this->authToken);
}
$response = $this->client->request($request);
if ($response->getStatus() === 200) {
return true;
Expand Down

0 comments on commit e44352c

Please sign in to comment.