Skip to content

Commit 2578c57

Browse files
Merge pull request #1 from tech-djoin/development
Development
2 parents 6245cc2 + 2800a74 commit 2578c57

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

.github/workflows/tests.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Tests
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
test:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
os: [ ubuntu-latest ]
12+
php: [ 7.4 ]
13+
dependency-version: [ prefer-lowest, prefer-stable ]
14+
redis-version: [ 6 ]
15+
16+
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
17+
18+
env:
19+
# The hostname used to communicate with the Redis service container
20+
REDIS_HOST: redis
21+
# The default Redis port
22+
REDIS_PORT: 6379
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v2
26+
27+
- name: Cache dependencies
28+
uses: actions/cache@v2
29+
with:
30+
path: ~/.composer/cache/files
31+
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
32+
33+
- name: Setup PHP
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: ${{ matrix.php }}
37+
extensions: redis, apcu
38+
ini-values: apc.enable_cli='On',apc.shm_size = 256M
39+
coverage: none
40+
41+
- name: Install dependencies
42+
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
43+
- name: Start Redis
44+
uses: supercharge/redis-github-action@1.1.0
45+
with:
46+
redis-version: ${{ matrix.redis-version }}
47+
# - name: Execute tests
48+
# run: ./vendor/bin/pest

config/docker-compose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3.8'
2+
3+
services:
4+
prometheus:
5+
container_name: prometheus
6+
image: prom/prometheus:latest
7+
ports:
8+
- 9090:9090
9+
volumes:
10+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
11+
command:
12+
- '--config.file=/etc/prometheus/prometheus.yml'
13+
- '--storage.tsdb.path=/prometheus'
14+
- '--web.console.libraries=/etc/prometheus/console_libraries'
15+
- '--web.console.templates=/etc/prometheus/consoles'
16+
- '--web.enable-lifecycle'
17+
networks:
18+
- net-prometheus
19+
20+
grafana:
21+
container_name: grafana
22+
image: grafana/grafana:latest
23+
ports:
24+
- 3000:3000
25+
depends_on:
26+
- prometheus
27+
networks:
28+
- net-prometheus
29+
30+
31+
networks:
32+
net-prometheus:

config/prometheus.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
global:
2+
scrape_interval: 15s
3+
evaluation_interval: 15s
4+
5+
6+
scrape_configs:
7+
- job_name: 'job_name'
8+
metrics_path: '/metrics'
9+
scrape_interval: 5s
10+
static_configs:
11+
- targets: ['localhost:8080']

src/Middleware/MetricCollector.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public function handle(Request $request, Closure $next)
3838

3939
$response = $next($request);
4040

41+
// Skip metric collect
42+
if($this->isBlackListPath($request->route()->uri)) return $next($request);
43+
4144
// Increase the number of http requests by 1 for label uri
4245
$this->http_request_counter->incBy(1 , [$request->route()->uri]);
4346

@@ -48,4 +51,18 @@ private function isEnabled(): bool
4851
{
4952
return config('prometheus.enabled');
5053
}
54+
55+
private function isBlackListPath($path): bool
56+
{
57+
$blackList = [
58+
'metrics/{secret?}'
59+
];
60+
61+
foreach ($blackList as $list) {
62+
// Pattern matching
63+
if(fnmatch($list, $path)) return true;
64+
}
65+
66+
return false;
67+
}
5168
}

src/PrometheusServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public function boot()
2525
$this->publishes([
2626
__DIR__.'/../config/prometheus.php' => config_path('prometheus.php'),
2727
], 'config');
28+
$this->publishes([
29+
__DIR__.'/../config/prometheus.yml' => \base_path('prometheus.yml.bak'),
30+
]);
31+
$this->publishes([
32+
__DIR__.'/../config/docker-compose.yml' => \base_path('docker-compose.yml.bak'),
33+
]);
2834
}
2935

3036
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');

0 commit comments

Comments
 (0)