Skip to content

Commit

Permalink
Merge pull request #4 from umbrellio/del-extra-tags
Browse files Browse the repository at this point in the history
Deleting unnecessary labels
  • Loading branch information
lazeevv authored Feb 14, 2023
2 parents a652c74 + 1e27ccf commit 838be3e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ This middleware has to be last one in your routes. Use Laravel's feature

> **Influx**
>
> Records have follow format: `app_prefix.response_time,urlName=domain.com/path1 val=1608201916"`, where `url` is tag's
> Records have follow format: `app_prefix.response_time,action=ExampleController@index val=1608201916"`, where `url` is tag's
> name, and val is field's name.
> **Prometheus**
>
> - Buckets can be configured in config
> - Metrics have follow format: app_prefix_response_time_bucket{namespace="app-nc",urlName="/",le="1"} 1
> - Metrics have follow format: app_prefix_response_time_bucket{namespace="app-nc",action="ExampleController@index",le="1"} 1
You can change measurement name instead of 'response_time' in config at `trackers` block. All trackers have this
opportunity.
Expand Down Expand Up @@ -157,13 +157,12 @@ class GuzzleClientServiceProvider extends ServiceProvider
>
> Format of writing will
>
be: `app_prefix.external_api_response,urlName=https://api.domain.com/endpoint/edit,host=api.domain.com,status=200,total_time=1.0,connect_time=0.5,namelookup_time=0.5 val=1.0`
be: `app_prefix.external_api_response,host=api.domain.com,status=200,total_time=1.0,connect_time=0.5,namelookup_time=0.5 val=1.0`

> **Prometheus**
>
> - Buckets can be configured in config
> - Metrics have follow format: app_prefix_external_api_response_bucket{namespace="app-ns",host="domain.com"
,status=200,urlName="/",le="2"} 1
> - Metrics have follow format: app_prefix_external_api_response_bucket{namespace="app-ns",host="domain.com",status=200,le="2"} 1
You can configure last three tags in `metrics` option, if you don't need something. Beside of this tags you can specify
any fields from handlerStats attribute in GuzzleHttp\TransferStats object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use GuzzleHttp\TransferStats;
use Psr\Http\Message\ResponseInterface;
use Umbrellio\EventTracker\Services\Adapters\BaseAdapter;
use Umbrellio\EventTracker\Services\Adapters\PrometheusHistogramAdapter;

class GuzzleClientOnStatsCallbackCreator
{
Expand Down Expand Up @@ -43,18 +44,17 @@ private function saveStats(TransferStats $stats): void
$metrics = $this->summator->flush();
}

$tags = array_merge(
[
'host' => $stats->getRequest()
->getUri()
->getHost(),
'urlName' => (string) $stats->getRequest()
->getUri(),
'status' => optional($stats->getResponse())
->getStatusCode() ?? self::DEFAULT_STATUS_CODE,
],
$metrics
);
$tags = [
'host' => $stats->getRequest()
->getUri()
->getHost(),
'status' => optional($stats->getResponse())
->getStatusCode() ?? self::DEFAULT_STATUS_CODE,
];

if (!$this->adapter instanceof PrometheusHistogramAdapter) {
$tags = array_merge($tags, $metrics);
}

$this->adapter->write($this->config['measurement'], $metrics[$this->config['main_metric']], $tags);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Trackers/ResponseTime/ResponseTimeTrackerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public function handle($request, $next)
public function terminate(Request $request, Response $response): void
{
$responseTime = $this->calculateResponseTime();
$route = $request->route();

$this->adapter->write($this->metricConfig['measurement'], $responseTime, [
'urlName' => $request->path(),
'action' => $route ? $route->getActionName() : '',
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function dontWriteEveryRequestIfRedirect(): void
$eventTracker->expects($this->once())
->method('write')
->with('external_api_response', 2, [
'urlName' => 'https://domain.com/1/edit',
'host' => 'domain.com',
'status' => 200,
'total_time' => 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function correctWrite(): void
$eventAdapter->expects($this->once())
->method('write')
->with($measurement, $this->greaterThan(0), [
'urlName' => 'domain.com/test',
'action' => '',
]);

$middleware = new ResponseTimeTrackerMiddleware($eventAdapter, compact('measurement'));
Expand Down

0 comments on commit 838be3e

Please sign in to comment.