@@ -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 | } |
@@ -15,28 +15,28 @@ |
||
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(HttpRequestCollector::class, function ($app) { |
|
27 | + $this->app->singleton(HttpRequestCollector::class, function($app) { |
|
28 | 28 | return new HttpRequestCollector($app['config']->get('prometheus')); |
29 | 29 | }); |
30 | - $this->app->singleton(SwooleProcessCollector::class, function ($app) { |
|
30 | + $this->app->singleton(SwooleProcessCollector::class, function($app) { |
|
31 | 31 | return new SwooleProcessCollector($app['config']->get('prometheus')); |
32 | 32 | }); |
33 | - $this->app->singleton(SwooleStatsCollector::class, function ($app) { |
|
33 | + $this->app->singleton(SwooleStatsCollector::class, function($app) { |
|
34 | 34 | return new SwooleStatsCollector($app['config']->get('prometheus')); |
35 | 35 | }); |
36 | - $this->app->singleton(SystemCollector::class, function ($app) { |
|
36 | + $this->app->singleton(SystemCollector::class, function($app) { |
|
37 | 37 | return new SystemCollector($app['config']->get('prometheus')); |
38 | 38 | }); |
39 | - $this->app->singleton(Exporter::class, function ($app) { |
|
39 | + $this->app->singleton(Exporter::class, function($app) { |
|
40 | 40 | return new Exporter($app['config']->get('prometheus')); |
41 | 41 | }); |
42 | 42 | } |
@@ -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'); |