Skip to content

Commit f25edeb

Browse files
committed
more fixes for 1.2.0
1 parent 0e634e2 commit f25edeb

File tree

6 files changed

+232
-258
lines changed

6 files changed

+232
-258
lines changed

dashboard/index.php

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,36 @@
66
use flight\apm\presenter\PresenterFactory;
77

88
$paths = [
9-
__DIR__.'/../vendor/autoload.php',
10-
__DIR__.'/../autoload.php',
11-
__DIR__.'/../../autoload.php',
12-
__DIR__.'/../../../autoload.php',
9+
__DIR__ . '/../vendor/autoload.php',
10+
__DIR__ . '/../autoload.php',
11+
__DIR__ . '/../../autoload.php',
12+
__DIR__ . '/../../../autoload.php',
1313
];
1414
$finalPath = '';
1515
foreach ($paths as $path) {
16-
if (file_exists($path) === true) {
17-
$finalPath = $path;
18-
require $path;
19-
break;
20-
}
16+
if (file_exists($path) === true) {
17+
$finalPath = $path;
18+
require $path;
19+
break;
20+
}
2121
}
2222
if (empty($finalPath)) {
23-
throw new Exception('Could not find autoload.php');
23+
throw new Exception('Could not find autoload.php');
2424
}
25-
26-
$appRootPath = dirname($finalPath).'/../';
25+
$appRootPath = dirname($finalPath) . '/../';
2726

2827
$app = Flight::app();
29-
$app->set('flight.views.path', __DIR__.'/views');
3028

31-
if(file_exists($appRootPath.'/app/config/config.php') === true) {
32-
$config = require($appRootPath.'/app/config/config.php');
33-
$runwayConfig = $config['runway'] ?? [];
34-
}
29+
if (file_exists($appRootPath . '/app/config/config.php') === true) {
30+
$config = require($appRootPath . '/app/config/config.php');
31+
$runwayConfig = $config['runway'] ?? [];
32+
}
33+
34+
// This needs to come after the config is loaded so it's forced
35+
$app->set('flight.views.path', __DIR__ . '/views');
3536

36-
if(empty($runwayConfig) && file_exists($appRootPath.'/.runway-config.json') === true) {
37-
$runwayConfig = json_decode(file_get_contents($appRootPath.'/.runway-config.json'), true);
37+
if (empty($runwayConfig) && file_exists($appRootPath . '/.runway-config.json') === true) {
38+
$runwayConfig = json_decode(file_get_contents($appRootPath . '/.runway-config.json'), true);
3839
}
3940
$presenter = PresenterFactory::create($runwayConfig);
4041

@@ -47,31 +48,31 @@ function calculateThreshold($range) {
4748
return gmdate('Y-m-d H:i:s', strtotime($map[$range] ?? '-1 hour'));
4849
}
4950

50-
$app->route('GET /apm/dashboard', function() use ($app) {
51+
$app->route('GET /apm/dashboard', function () use ($app) {
5152
$app->render('dashboard');
5253
});
5354

5455
// Modified to only return widget data (no requests or pagination)
55-
$app->route('GET /apm/data/dashboard', function() use ($app, $presenter) {
56+
$app->route('GET /apm/data/dashboard', function () use ($app, $presenter) {
5657
$range = Flight::request()->query['range'] ?? 'last_hour';
5758
$threshold = calculateThreshold($range);
58-
$data = $presenter->getDashboardData($threshold);
59+
$data = $presenter->getDashboardData($threshold);
5960
$app->json($data);
6061
});
6162

6263
// New endpoint specifically for request log data with enhanced custom events search
63-
$app->route('GET /apm/data/requests', function() use ($app, $presenter) {
64+
$app->route('GET /apm/data/requests', function () use ($app, $presenter) {
6465
$range = Flight::request()->query['range'] ?? 'last_hour';
65-
$threshold = calculateThreshold($range);
66+
$threshold = calculateThreshold($range);
6667
$page = max(1, (int) (Flight::request()->query['page'] ?? 1));
6768
$perPage = 50;
6869
$search = Flight::request()->query['search'] ?? '';
69-
$data = $presenter->getRequestsData($threshold, $page, $perPage, $search);
70-
$app->json($data);
70+
$data = $presenter->getRequestsData($threshold, $page, $perPage, $search);
71+
$app->json($data);
7172
});
7273

7374
// New endpoint to retrieve available event keys for filtering
74-
$app->route('GET /apm/data/event-keys', function() use ($app, $presenter) {
75+
$app->route('GET /apm/data/event-keys', function () use ($app, $presenter) {
7576
$range = Flight::request()->query['range'] ?? 'last_hour';
7677
$threshold = calculateThreshold($range);
7778
$eventKeys = $presenter->getEventKeys($threshold);

src/apm/presenter/PresenterCommonTrait.php

Lines changed: 60 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,87 +4,81 @@
44

55
namespace flight\apm\presenter;
66

7-
trait PresenterCommonTrait
8-
{
9-
/**
10-
* Calculate percentile from an array of values
7+
trait PresenterCommonTrait {
8+
/**
9+
* Calculate percentile from an array of values
1110
*
1211
* @param array $data - The array of values
1312
* @param int $percentile - The percentile to calculate
1413
* @return float
15-
*/
16-
protected function calculatePercentile(array $data, int $percentile): float
17-
{
18-
if (empty($data)) return 0;
19-
sort($data);
20-
$index = ($percentile / 100) * (count($data) - 1);
21-
$lower = floor($index);
22-
$upper = ceil($index);
23-
if ($lower == $upper) return $data[$lower];
24-
$fraction = $index - $lower;
25-
return $data[$lower] + $fraction * ($data[$upper] - $data[$lower]);
26-
}
14+
*/
15+
protected function calculatePercentile(array $data, int $percentile): float {
16+
if (empty($data)) return 0;
17+
sort($data);
18+
$index = ($percentile / 100) * (count($data) - 1);
19+
$lower = floor($index);
20+
$upper = ceil($index);
21+
if ($lower == $upper) return $data[$lower];
22+
$fraction = $index - $lower;
23+
return $data[$lower] + $fraction * ($data[$upper] - $data[$lower]);
24+
}
2725

28-
/**
29-
* Check if the database has JSON functions
26+
/**
27+
* Check if the database has JSON functions
3028
*
3129
* @return bool
32-
*/
33-
protected function databaseSupportsJson(): bool
34-
{
35-
try {
36-
$this->db->query("SELECT json_extract('', '$')");
37-
return true;
38-
} catch (\Exception $e) {
39-
return false;
40-
}
41-
}
30+
*/
31+
protected function databaseSupportsJson(): bool {
32+
try {
33+
$this->pdoWrapper->query("SELECT json_extract('', '$')");
34+
return true;
35+
} catch (\Exception $e) {
36+
return false;
37+
}
38+
}
4239

43-
/**
44-
* Check if IP addresses should be masked
40+
/**
41+
* Check if IP addresses should be masked
4542
*
4643
* @return bool
47-
*/
48-
protected function shouldMaskIpAddresses(): bool
49-
{
50-
return $this->config['apm']['mask_ip_addresses'] ?? false;
51-
}
44+
*/
45+
protected function shouldMaskIpAddresses(): bool {
46+
return $this->config['apm']['mask_ip_addresses'] ?? false;
47+
}
5248

53-
/**
54-
* Mask an IP address
49+
/**
50+
* Mask an IP address
5551
*
5652
* @param string $ip - The IP address to mask
5753
* @return string - The masked IP address
58-
*/
59-
protected function maskIpAddress(string $ip): string
60-
{
61-
$ipCharacter = strpos($ip, '.') !== false ? '.' : ':';
62-
$parts = explode($ipCharacter, $ip);
63-
if (count($parts) === 4) {
64-
$parts[3] = str_repeat('x', strlen($parts[3]));
65-
}
66-
if (count($parts) > 4) {
67-
$parts[count($parts) - 1] = str_repeat('x', strlen($parts[count($parts) - 1]));
68-
}
69-
return implode('.', $parts);
70-
}
54+
*/
55+
protected function maskIpAddress(string $ip): string {
56+
$ipCharacter = strpos($ip, '.') !== false ? '.' : ':';
57+
$parts = explode($ipCharacter, $ip);
58+
if (count($parts) === 4) {
59+
$parts[3] = str_repeat('x', strlen($parts[3]));
60+
}
61+
if (count($parts) > 4) {
62+
$parts[count($parts) - 1] = str_repeat('x', strlen($parts[count($parts) - 1]));
63+
}
64+
return implode('.', $parts);
65+
}
7166

72-
/**
73-
* Get operator options for event value filtering
67+
/**
68+
* Get operator options for event value filtering
7469
*
7570
* @return array<int, array<string, string>>
76-
*/
77-
public function getEventValueOperators(): array
78-
{
79-
return [
80-
['id' => 'contains', 'name' => 'Contains', 'desc' => 'Value contains the text (case-insensitive)'],
81-
['id' => 'exact', 'name' => 'Equals', 'desc' => 'Value exactly matches the text'],
82-
['id' => 'starts_with', 'name' => 'Starts with', 'desc' => 'Value starts with the text'],
83-
['id' => 'ends_with', 'name' => 'Ends with', 'desc' => 'Value ends with the text'],
84-
['id' => 'greater_than', 'name' => '>', 'desc' => 'Value is greater than (numeric comparison)'],
85-
['id' => 'less_than', 'name' => '<', 'desc' => 'Value is less than (numeric comparison)'],
86-
['id' => 'greater_than_equal', 'name' => '>=', 'desc' => 'Value is greater than or equal to (numeric comparison)'],
87-
['id' => 'less_than_equal', 'name' => '<=', 'desc' => 'Value is less than or equal to (numeric comparison)'],
88-
];
89-
}
71+
*/
72+
public function getEventValueOperators(): array {
73+
return [
74+
['id' => 'contains', 'name' => 'Contains', 'desc' => 'Value contains the text (case-insensitive)'],
75+
['id' => 'exact', 'name' => 'Equals', 'desc' => 'Value exactly matches the text'],
76+
['id' => 'starts_with', 'name' => 'Starts with', 'desc' => 'Value starts with the text'],
77+
['id' => 'ends_with', 'name' => 'Ends with', 'desc' => 'Value ends with the text'],
78+
['id' => 'greater_than', 'name' => '>', 'desc' => 'Value is greater than (numeric comparison)'],
79+
['id' => 'less_than', 'name' => '<', 'desc' => 'Value is less than (numeric comparison)'],
80+
['id' => 'greater_than_equal', 'name' => '>=', 'desc' => 'Value is greater than or equal to (numeric comparison)'],
81+
['id' => 'less_than_equal', 'name' => '<=', 'desc' => 'Value is less than or equal to (numeric comparison)'],
82+
];
83+
}
9084
}

src/commands/ConfigMigrateCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use flight\commands\AbstractBaseCommand;
88
use Ahc\Cli\IO\Interactor;
9-
use PDO;
10-
use PDOException;
119

1210
class ConfigMigrateCommand extends AbstractBaseCommand
1311
{
@@ -45,7 +43,7 @@ public function execute()
4543

4644
$runwayConfig = json_decode(file_get_contents($configFile), true) ?? [];
4745

48-
$config = $this->config['runway'] ?? [];
46+
$config['runway'] = $this->config['runway'] ?? [];
4947

5048
// Merge them together, with .runway-config.json taking precedence
5149
$config['runway'] = array_merge($config['runway'], $runwayConfig);

0 commit comments

Comments
 (0)