@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $server[$headerServerMapping[$key]] = $value; |
52 | 52 | } else { |
53 | 53 | $key = str_replace('-', '_', $key); |
54 | - $server['http_' . $key] = $value; |
|
54 | + $server['http_'.$key] = $value; |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | $server = array_change_key_case($server, CASE_UPPER); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | && isset($_SERVER['QUERY_STRING']) |
66 | 66 | && $_SERVER['QUERY_STRING'] !== '' |
67 | 67 | ) { |
68 | - $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
68 | + $_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING']; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Fix argv & argc |
@@ -19,17 +19,17 @@ |
||
19 | 19 | return false; |
20 | 20 | } |
21 | 21 | |
22 | - $fileTypes = isset($config['file_types']) ? (array)$config['file_types'] : []; |
|
22 | + $fileTypes = isset($config['file_types']) ? (array) $config['file_types'] : []; |
|
23 | 23 | if (empty($fileTypes)) { |
24 | 24 | $this->warning('No file types to watch by inotify'); |
25 | 25 | return false; |
26 | 26 | } |
27 | 27 | |
28 | - $callback = function () use ($config, $laravelConf) { |
|
28 | + $callback = function() use ($config, $laravelConf) { |
|
29 | 29 | $log = !empty($config['log']); |
30 | 30 | $this->setProcessTitle(sprintf('%s laravels: inotify process', $config['process_prefix'])); |
31 | 31 | $inotify = new Inotify($config['watch_path'], IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVE, |
32 | - function ($event) use ($log, $laravelConf) { |
|
32 | + function($event) use ($log, $laravelConf) { |
|
33 | 33 | Portal::runLaravelSCommand($laravelConf['root_path'], 'reload'); |
34 | 34 | if ($log) { |
35 | 35 | $action = 'file:'; |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | public function addCustomProcesses(Server $swoole, $processPrefix, array $processes, array $laravelConfig) |
13 | 13 | { |
14 | - $pidfile = dirname($swoole->setting['pid_file']) . '/' . $this->customProcessPidFile; |
|
14 | + $pidfile = dirname($swoole->setting['pid_file']).'/'.$this->customProcessPidFile; |
|
15 | 15 | if (file_exists($pidfile)) { |
16 | 16 | unlink($pidfile); |
17 | 17 | } |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | continue; |
27 | 27 | } |
28 | 28 | $processClass = $item['class']; |
29 | - $restartInterval = isset($item['restart_interval']) ? (int)$item['restart_interval'] : 5; |
|
30 | - $callback = function (Process $worker) use ($pidfile, $swoole, $processPrefix, $processClass, $restartInterval, $name, $laravelConfig) { |
|
31 | - file_put_contents($pidfile, $worker->pid . "\n", FILE_APPEND | LOCK_EX); |
|
29 | + $restartInterval = isset($item['restart_interval']) ? (int) $item['restart_interval'] : 5; |
|
30 | + $callback = function(Process $worker) use ($pidfile, $swoole, $processPrefix, $processClass, $restartInterval, $name, $laravelConfig) { |
|
31 | + file_put_contents($pidfile, $worker->pid."\n", FILE_APPEND | LOCK_EX); |
|
32 | 32 | $this->initLaravel($laravelConfig, $swoole); |
33 | 33 | if (!isset(class_implements($processClass)[CustomProcessInterface::class])) { |
34 | 34 | throw new \InvalidArgumentException( |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | /**@var CustomProcessInterface $processClass */ |
43 | 43 | $this->setProcessTitle(sprintf('%s laravels: %s process', $processPrefix, $name)); |
44 | 44 | |
45 | - Process::signal(SIGUSR1, function ($signo) use ($name, $processClass, $worker, $pidfile, $swoole) { |
|
45 | + Process::signal(SIGUSR1, function($signo) use ($name, $processClass, $worker, $pidfile, $swoole) { |
|
46 | 46 | $this->info(sprintf('Reloading %s process[PID=%d].', $name, $worker->pid)); |
47 | 47 | $processClass::onReload($swoole, $worker); |
48 | 48 | }); |
49 | 49 | |
50 | 50 | if (method_exists($processClass, 'onStop')) { |
51 | - Process::signal(SIGTERM, function ($signo) use ($name, $processClass, $worker, $pidfile, $swoole) { |
|
51 | + Process::signal(SIGTERM, function($signo) use ($name, $processClass, $worker, $pidfile, $swoole) { |
|
52 | 52 | $this->info(sprintf('Stopping %s process[PID=%d].', $name, $worker->pid)); |
53 | 53 | $processClass::onStop($swoole, $worker); |
54 | 54 | }); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | for ($i = 0; $i < $item['num']; $i++) { |
73 | 73 | $process = $this->makeProcess($callback, $item); |
74 | 74 | $swoole->addProcess($process); |
75 | - $processList[$name . $i] = $process; |
|
75 | + $processList[$name.$i] = $process; |
|
76 | 76 | } |
77 | 77 | } else { // For single process |
78 | 78 | $process = $this->makeProcess($callback, $item); |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | $this->clientIp = current(swoole_get_local_ip()) ?: gethostname(); |
42 | 42 | } |
43 | 43 | if (isset($settings['pull_timeout'])) { |
44 | - $this->pullTimeout = (int)$settings['pull_timeout']; |
|
44 | + $this->pullTimeout = (int) $settings['pull_timeout']; |
|
45 | 45 | } |
46 | 46 | if (isset($settings['backup_old_env'])) { |
47 | - $this->backupOldEnv = (bool)$settings['backup_old_env']; |
|
47 | + $this->backupOldEnv = (bool) $settings['backup_old_env']; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | $settings = [ |
74 | 74 | 'server' => getenv('APOLLO_SERVER'), |
75 | 75 | 'app_id' => getenv('APOLLO_APP_ID'), |
76 | - 'cluster' => ($cluster = (string)getenv('APOLLO_CLUSTER')) !== '' ? $cluster : null, |
|
77 | - 'namespaces' => ($namespaces = (string)getenv('APOLLO_NAMESPACES')) !== '' ? explode(',', $namespaces) : null, |
|
78 | - 'client_ip' => ($clientIp = (string)getenv('APOLLO_CLIENT_IP')) !== '' ? $clientIp : null, |
|
79 | - 'pull_timeout' => ($pullTimeout = (int)getenv('APOLLO_PULL_TIMEOUT')) > 0 ? $pullTimeout : null, |
|
80 | - 'backup_old_env' => ($backupOldEnv = (bool)getenv('APOLLO_BACKUP_OLD_ENV')) ? $backupOldEnv : null, |
|
76 | + 'cluster' => ($cluster = (string) getenv('APOLLO_CLUSTER')) !== '' ? $cluster : null, |
|
77 | + 'namespaces' => ($namespaces = (string) getenv('APOLLO_NAMESPACES')) !== '' ? explode(',', $namespaces) : null, |
|
78 | + 'client_ip' => ($clientIp = (string) getenv('APOLLO_CLIENT_IP')) !== '' ? $clientIp : null, |
|
79 | + 'pull_timeout' => ($pullTimeout = (int) getenv('APOLLO_PULL_TIMEOUT')) > 0 ? $pullTimeout : null, |
|
80 | + 'backup_old_env' => ($backupOldEnv = (bool) getenv('APOLLO_BACKUP_OLD_ENV')) ? $backupOldEnv : null, |
|
81 | 81 | ]; |
82 | 82 | return new static($settings); |
83 | 83 | } |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | 'cluster' => isset($options['apollo-cluster']) && $options['apollo-cluster'] !== '' ? $options['apollo-cluster'] : null, |
94 | 94 | 'namespaces' => !empty($options['apollo-namespaces']) ? $options['apollo-namespaces'] : null, |
95 | 95 | 'client_ip' => isset($options['apollo-client-ip']) && $options['apollo-client-ip'] !== '' ? $options['apollo-client-ip'] : null, |
96 | - 'pull_timeout' => isset($options['apollo-pull-timeout']) ? (int)$options['apollo-pull-timeout'] : null, |
|
97 | - 'backup_old_env' => isset($options['apollo-backup-old-env']) ? (bool)$options['apollo-backup-old-env'] : null, |
|
96 | + 'pull_timeout' => isset($options['apollo-pull-timeout']) ? (int) $options['apollo-pull-timeout'] : null, |
|
97 | + 'backup_old_env' => isset($options['apollo-backup-old-env']) ? (bool) $options['apollo-backup-old-env'] : null, |
|
98 | 98 | ]; |
99 | 99 | return new static($settings); |
100 | 100 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $configs = []; |
117 | 117 | $uri = sprintf('%s/configs/%s/%s/', $this->server, $this->appId, $this->cluster); |
118 | 118 | foreach ($namespaces as $namespace) { |
119 | - $url = $uri . $namespace . '?' . http_build_query([ |
|
119 | + $url = $uri.$namespace.'?'.http_build_query([ |
|
120 | 120 | 'releaseKey' => $withReleaseKey && isset($this->releaseKeys[$namespace]) ? $this->releaseKeys[$namespace] : null, |
121 | 121 | 'ip' => $this->clientIp, |
122 | 122 | ]); |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | $all = $this->pullAll(false, $options); |
147 | 147 | if (count($all) !== count($this->namespaces)) { |
148 | 148 | $lackNamespaces = array_diff($this->namespaces, array_keys($all)); |
149 | - throw new \RuntimeException('Missing Apollo configurations for namespaces ' . implode(',', $lackNamespaces)); |
|
149 | + throw new \RuntimeException('Missing Apollo configurations for namespaces '.implode(',', $lackNamespaces)); |
|
150 | 150 | } |
151 | 151 | $configs = []; |
152 | 152 | foreach ($all as $namespace => $config) { |
153 | - $configs[] = '# Namespace: ' . $config['namespaceName']; |
|
153 | + $configs[] = '# Namespace: '.$config['namespaceName']; |
|
154 | 154 | ksort($config['configurations']); |
155 | 155 | foreach ($config['configurations'] as $key => $value) { |
156 | 156 | $configs[] = sprintf('%s=%s', $key, $value); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | throw new \RuntimeException('Empty Apollo configuration list'); |
161 | 161 | } |
162 | 162 | if ($this->backupOldEnv && file_exists($filepath)) { |
163 | - rename($filepath, $filepath . '.' . date('YmdHis')); |
|
163 | + rename($filepath, $filepath.'.'.date('YmdHis')); |
|
164 | 164 | } |
165 | 165 | $fileContent = implode(PHP_EOL, $configs); |
166 | 166 | if (Context::inCoroutine()) { |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | if (!empty($this->notifications) && current($this->notifications)['notificationId'] !== -1) { // Ignore the first pull |
201 | 201 | $callback($notifications); |
202 | 202 | } |
203 | - array_walk($notifications, function (&$notification) { |
|
203 | + array_walk($notifications, function(&$notification) { |
|
204 | 204 | unset($notification['messages']); |
205 | 205 | }); |
206 | 206 | $this->notifications = array_merge($this->notifications, array_column($notifications, null, 'namespaceName')); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | 'value' => $apcSmaInfo['avail_mem'], |
31 | 31 | ], |
32 | 32 | ]; |
33 | - foreach (new \APCuIterator('/^' . $this->config['apcu_key_prefix'] . $this->config['apcu_key_separator'] . '/') as $item) { |
|
33 | + foreach (new \APCuIterator('/^'.$this->config['apcu_key_prefix'].$this->config['apcu_key_separator'].'/') as $item) { |
|
34 | 34 | $parts = explode($this->config['apcu_key_separator'], $item['key']); |
35 | 35 | parse_str($parts[3], $labels); |
36 | 36 | if (is_array($item['value'])) { |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | $metrics = $this->getMetrics(); |
63 | 63 | $lines = []; |
64 | 64 | foreach ($metrics as $metric) { |
65 | - $lines[] = "# HELP " . $metric['name'] . " {$metric['help']}"; |
|
66 | - $lines[] = "# TYPE " . $metric['name'] . " {$metric['type']}"; |
|
65 | + $lines[] = "# HELP ".$metric['name']." {$metric['help']}"; |
|
66 | + $lines[] = "# TYPE ".$metric['name']." {$metric['type']}"; |
|
67 | 67 | |
68 | 68 | $metricLabels = isset($metric['labels']) ? $metric['labels'] : []; |
69 | 69 | $labels = ['{']; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | $labels[] = '}'; |
75 | 75 | $labelStr = implode('', $labels); |
76 | - $lines[] = $metric['name'] . "$labelStr {$metric['value']}"; |
|
76 | + $lines[] = $metric['name']."$labelStr {$metric['value']}"; |
|
77 | 77 | } |
78 | 78 | return implode("\n", $lines); |
79 | 79 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | 'class' => static::class, |
22 | 22 | 'redirect' => false, |
23 | 23 | 'pipe' => 0, |
24 | - 'enable' => (bool)config('prometheus.enable', true), |
|
24 | + 'enable' => (bool) config('prometheus.enable', true), |
|
25 | 25 | ], |
26 | 26 | ]; |
27 | 27 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $taskWorkerNum = isset($swoole->setting['task_worker_num']) ? $swoole->setting['task_worker_num'] : 0; |
39 | 39 | $totalNum = $workerNum + $taskWorkerNum - 1; |
40 | 40 | $workerIds = range(0, $totalNum); |
41 | - $runJob = function () use ($swoole, $workerIds, $processCollector, $swooleStatsCollector, $systemCollector) { |
|
41 | + $runJob = function() use ($swoole, $workerIds, $processCollector, $swooleStatsCollector, $systemCollector) { |
|
42 | 42 | // Collect the metrics of Swoole stats() |
43 | 43 | $swooleStatsCollector->collect(); |
44 | 44 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | 'class' => static::class, |
22 | 22 | 'redirect' => false, |
23 | 23 | 'pipe' => 0, |
24 | - 'enable' => (bool)getenv('ENABLE_APOLLO'), |
|
24 | + 'enable' => (bool) getenv('ENABLE_APOLLO'), |
|
25 | 25 | ], |
26 | 26 | ]; |
27 | 27 | } |
@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | { |
31 | 31 | $filename = base_path('.env'); |
32 | 32 | if (isset($_ENV['_ENV'])) { |
33 | - $filename .= '.' . $_ENV['_ENV']; |
|
33 | + $filename .= '.'.$_ENV['_ENV']; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | self::$apollo = Client::createFromEnv(); |
37 | - self::$apollo->startWatchNotification(function (array $notifications) use ($process, $filename) { |
|
37 | + self::$apollo->startWatchNotification(function(array $notifications) use ($process, $filename) { |
|
38 | 38 | $configs = self::$apollo->pullAllAndSave($filename); |
39 | 39 | app('log')->info('[ApolloProcess] Pull all configurations', $configs); |
40 | 40 | Portal::runLaravelSCommand(base_path(), 'reload'); |
@@ -15,31 +15,31 @@ |
||
15 | 15 | public function boot() |
16 | 16 | { |
17 | 17 | $this->publishes([ |
18 | - __DIR__ . '/../../../config/prometheus.php' => base_path('config/prometheus.php'), |
|
18 | + __DIR__.'/../../../config/prometheus.php' => base_path('config/prometheus.php'), |
|
19 | 19 | ]); |
20 | 20 | } |
21 | 21 | |
22 | 22 | public function register() |
23 | 23 | { |
24 | 24 | $this->mergeConfigFrom( |
25 | - __DIR__ . '/../../../config/prometheus.php', 'prometheus' |
|
25 | + __DIR__.'/../../../config/prometheus.php', 'prometheus' |
|
26 | 26 | ); |
27 | - $this->app->singleton(RequestMiddleware::class, function ($app) { |
|
27 | + $this->app->singleton(RequestMiddleware::class, function($app) { |
|
28 | 28 | return new RequestMiddleware($app->make(HttpRequestCollector::class)); |
29 | 29 | }); |
30 | - $this->app->singleton(HttpRequestCollector::class, function ($app) { |
|
30 | + $this->app->singleton(HttpRequestCollector::class, function($app) { |
|
31 | 31 | return new HttpRequestCollector($app['config']->get('prometheus')); |
32 | 32 | }); |
33 | - $this->app->singleton(SwooleProcessCollector::class, function ($app) { |
|
33 | + $this->app->singleton(SwooleProcessCollector::class, function($app) { |
|
34 | 34 | return new SwooleProcessCollector($app['config']->get('prometheus')); |
35 | 35 | }); |
36 | - $this->app->singleton(SwooleStatsCollector::class, function ($app) { |
|
36 | + $this->app->singleton(SwooleStatsCollector::class, function($app) { |
|
37 | 37 | return new SwooleStatsCollector($app['config']->get('prometheus')); |
38 | 38 | }); |
39 | - $this->app->singleton(SystemCollector::class, function ($app) { |
|
39 | + $this->app->singleton(SystemCollector::class, function($app) { |
|
40 | 40 | return new SystemCollector($app['config']->get('prometheus')); |
41 | 41 | }); |
42 | - $this->app->singleton(Exporter::class, function ($app) { |
|
42 | + $this->app->singleton(Exporter::class, function($app) { |
|
43 | 43 | return new Exporter($app['config']->get('prometheus')); |
44 | 44 | }); |
45 | 45 | } |
@@ -20,26 +20,26 @@ discard block |
||
20 | 20 | if ($routes instanceof \Illuminate\Routing\RouteCollection) { // Laravel |
21 | 21 | foreach ($routes->getRoutes() as $route) { |
22 | 22 | $method = $route->methods()[0]; |
23 | - $uri = '/' . ltrim($route->uri(), '/'); |
|
24 | - $this->routes[$method . $uri] = $uri; |
|
23 | + $uri = '/'.ltrim($route->uri(), '/'); |
|
24 | + $this->routes[$method.$uri] = $uri; |
|
25 | 25 | |
26 | 26 | $action = $route->getAction(); |
27 | 27 | if (is_string($action['uses'])) { // Uses |
28 | - $this->routesByUses[$method . $action['uses']] = $uri; |
|
28 | + $this->routesByUses[$method.$action['uses']] = $uri; |
|
29 | 29 | } elseif ($action['uses'] instanceof Closure) { // Closure |
30 | 30 | $objectId = spl_object_hash($action['uses']); |
31 | - $this->routesByClosure[$method . $objectId] = $uri; |
|
31 | + $this->routesByClosure[$method.$objectId] = $uri; |
|
32 | 32 | } |
33 | 33 | } |
34 | 34 | } elseif (is_array($routes)) { // Lumen |
35 | 35 | $this->routes = $routes; |
36 | 36 | foreach ($routes as $route) { |
37 | 37 | if (isset($route['action']['uses'])) { // Uses |
38 | - $this->routesByUses[$route['method'] . $route['action']['uses']] = $route['uri']; |
|
38 | + $this->routesByUses[$route['method'].$route['action']['uses']] = $route['uri']; |
|
39 | 39 | } |
40 | 40 | if (isset($route['action'][0]) && $route['action'][0] instanceof Closure) { // Closure |
41 | 41 | $objectId = spl_object_hash($route['action'][0]); |
42 | - $this->routesByClosure[$route['method'] . $objectId] = $route['uri']; |
|
42 | + $this->routesByClosure[$route['method'].$objectId] = $route['uri']; |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | { |
83 | 83 | $method = $request->getMethod(); |
84 | 84 | $uri = $request->getPathInfo(); |
85 | - $key = $method . $uri; |
|
85 | + $key = $method.$uri; |
|
86 | 86 | if (isset($this->routes[$key])) { |
87 | 87 | return $uri; |
88 | 88 | } |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | $uri = $route->uri(); |
93 | 93 | } elseif (is_array($route)) { // Lumen |
94 | 94 | if (isset($route[1]['uses'])) { |
95 | - $key = $method . $route[1]['uses']; |
|
95 | + $key = $method.$route[1]['uses']; |
|
96 | 96 | if (isset($this->routesByUses[$key])) { |
97 | 97 | $uri = $this->routesByUses[$key]; |
98 | 98 | } |
99 | 99 | } elseif (isset($route[1][0]) && $route[1][0] instanceof Closure) { |
100 | - $key = $method . spl_object_hash($route[1][0]); |
|
100 | + $key = $method.spl_object_hash($route[1][0]); |
|
101 | 101 | if (isset($this->routesByClosure[$key])) { |
102 | 102 | $uri = $this->routesByClosure[$key]; |
103 | 103 | } |