Skip to content

Commit 838be3e

Browse files
authored
Merge pull request #4 from umbrellio/del-extra-tags
Deleting unnecessary labels
2 parents a652c74 + 1e27ccf commit 838be3e

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ This middleware has to be last one in your routes. Use Laravel's feature
8585

8686
> **Influx**
8787
>
88-
> Records have follow format: `app_prefix.response_time,urlName=domain.com/path1 val=1608201916"`, where `url` is tag's
88+
> Records have follow format: `app_prefix.response_time,action=ExampleController@index val=1608201916"`, where `url` is tag's
8989
> name, and val is field's name.
9090
9191
> **Prometheus**
9292
>
9393
> - Buckets can be configured in config
94-
> - Metrics have follow format: app_prefix_response_time_bucket{namespace="app-nc",urlName="/",le="1"} 1
94+
> - Metrics have follow format: app_prefix_response_time_bucket{namespace="app-nc",action="ExampleController@index",le="1"} 1
9595
9696
You can change measurement name instead of 'response_time' in config at `trackers` block. All trackers have this
9797
opportunity.
@@ -157,13 +157,12 @@ class GuzzleClientServiceProvider extends ServiceProvider
157157
>
158158
> Format of writing will
159159
>
160-
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`
160+
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`
161161

162162
> **Prometheus**
163163
>
164164
> - Buckets can be configured in config
165-
> - Metrics have follow format: app_prefix_external_api_response_bucket{namespace="app-ns",host="domain.com"
166-
,status=200,urlName="/",le="2"} 1
165+
> - Metrics have follow format: app_prefix_external_api_response_bucket{namespace="app-ns",host="domain.com",status=200,le="2"} 1
167166
168167
You can configure last three tags in `metrics` option, if you don't need something. Beside of this tags you can specify
169168
any fields from handlerStats attribute in GuzzleHttp\TransferStats object.

src/Trackers/ExternalApiResponse/GuzzleClientOnStatsCallbackCreator.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use GuzzleHttp\TransferStats;
99
use Psr\Http\Message\ResponseInterface;
1010
use Umbrellio\EventTracker\Services\Adapters\BaseAdapter;
11+
use Umbrellio\EventTracker\Services\Adapters\PrometheusHistogramAdapter;
1112

1213
class GuzzleClientOnStatsCallbackCreator
1314
{
@@ -43,18 +44,17 @@ private function saveStats(TransferStats $stats): void
4344
$metrics = $this->summator->flush();
4445
}
4546

46-
$tags = array_merge(
47-
[
48-
'host' => $stats->getRequest()
49-
->getUri()
50-
->getHost(),
51-
'urlName' => (string) $stats->getRequest()
52-
->getUri(),
53-
'status' => optional($stats->getResponse())
54-
->getStatusCode() ?? self::DEFAULT_STATUS_CODE,
55-
],
56-
$metrics
57-
);
47+
$tags = [
48+
'host' => $stats->getRequest()
49+
->getUri()
50+
->getHost(),
51+
'status' => optional($stats->getResponse())
52+
->getStatusCode() ?? self::DEFAULT_STATUS_CODE,
53+
];
54+
55+
if (!$this->adapter instanceof PrometheusHistogramAdapter) {
56+
$tags = array_merge($tags, $metrics);
57+
}
5858

5959
$this->adapter->write($this->config['measurement'], $metrics[$this->config['main_metric']], $tags);
6060
}

src/Trackers/ResponseTime/ResponseTimeTrackerMiddleware.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ public function handle($request, $next)
2727
public function terminate(Request $request, Response $response): void
2828
{
2929
$responseTime = $this->calculateResponseTime();
30+
$route = $request->route();
3031

3132
$this->adapter->write($this->metricConfig['measurement'], $responseTime, [
32-
'urlName' => $request->path(),
33+
'action' => $route ? $route->getActionName() : '',
3334
]);
3435
}
3536

tests/Feature/Trackers/ExternalApiResponse/GuzzleClientOnStatsCallbackCreatorTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function dontWriteEveryRequestIfRedirect(): void
3939
$eventTracker->expects($this->once())
4040
->method('write')
4141
->with('external_api_response', 2, [
42-
'urlName' => 'https://domain.com/1/edit',
4342
'host' => 'domain.com',
4443
'status' => 200,
4544
'total_time' => 2,

tests/Unit/Trackers/ResponseTime/ResponseTimeTrackerMiddlewareTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function correctWrite(): void
2424
$eventAdapter->expects($this->once())
2525
->method('write')
2626
->with($measurement, $this->greaterThan(0), [
27-
'urlName' => 'domain.com/test',
27+
'action' => '',
2828
]);
2929

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

0 commit comments

Comments
 (0)