Skip to content

Commit 4459cb4

Browse files
authored
Channel isEnabled() Default
* Updated channel notification isEnabled() to default to false. * Updated readme for config section. * Updated config to pull from ENV when available.
1 parent e7641ba commit 4459cb4

File tree

4 files changed

+60
-31
lines changed

4 files changed

+60
-31
lines changed

README.md

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,47 +43,71 @@ Adjust the configuration file to suite your application.
4343

4444
```php
4545
[
46-
'enabled' => true, // Do you want to capture queries?
47-
'token' => env('QUERY_WATCH_TOKEN', 'change_me'), // Token used for Authenticating Private Broadcast Channel
46+
// Do you want to capture queries?
47+
'enabled' => env('QUERY_WATCH_ENABLED', true),
48+
49+
// Token used for Authenticating Private Broadcast Channel
50+
'token' => env('QUERY_WATCH_TOKEN', 'change_me'),
4851
'scope' => [
4952
'time_exceeds_ms' => [
50-
'enabled' => true, // Do you want to capture everything or only slow queries?
51-
'threshold' => 500, // The number of milliseconds it took to execute the query.
53+
// Do you want to capture everything or only slow queries?
54+
'enabled' => env('QUERY_WATCH_SCOPE_TIME_ENABLED', true),
55+
56+
// The number of milliseconds it took to execute the query.
57+
'threshold' => env('QUERY_WATCH_SCOPE_TIME_THRESHOLD', 500),
5258
],
5359
'context' => [
5460
'auth_user' => [
55-
'enabled' => true, // Do you want to know context of the authenticated user when query is captured?
56-
'ttl' => 300, // How long do you want the session_id/authenticated user cached for?
57-
// without this cache, your application will infinite loop because it will capture
58-
// the user query and loop.
59-
// See closed Issue #1 for context.
61+
// Do you want to know context of the authenticated user when query is captured?
62+
'enabled' => env('QUERY_WATCH_SCOPE_CONTEXT_AUTH_ENABLED', true),
63+
64+
// How long do you want the session_id/authenticated user cached for?
65+
// without this cache, your application will infinite loop because it will capture
66+
// the user query and loop.
67+
// See closed Issue #1 for context.
68+
'ttl' => env('QUERY_WATCH_SCOPE_CONTEXT_AUTH_TTL', 300),
6069
],
6170
'trigger' => [
62-
'enabled' => true, // Do you want to know what triggered the query?
63-
// i.e Console command or Request
71+
// Do you want to know what triggered the query?
72+
// i.e Console command or Request
73+
'enabled' => env('QUERY_WATCH_SCOPE_TRIGGER_ENABLED', true),
6474
],
6575
],
6676
'ignorable_tables' => [
67-
'jobs' // Do you want to capture queries on specific tables?
68-
// If you are utilizing the database queue driver, you need to
69-
// ignore the jobs table or you'll get infinite capture loops.
77+
// Do you want to capture queries on specific tables?
78+
// If you are utilizing the database queue driver, you need to
79+
// ignore the jobs table, or you'll potentially get infinite capture loops.
80+
'jobs'
7081
],
7182
'ignorable_statements' => [
72-
'create' // Do you want to ignore specific SQL statements?
83+
// Do you want to ignore specific SQL statements?
84+
'create'
7385
]
7486
],
75-
'listener' => [ // Channel notifications are queued
76-
'connection' => 'sync', // Define what connection to use.
77-
'queue' => 'default', // Define what queue to use
78-
'delay' => null, // Do you want to delay the notifications at all?
87+
'listener' => [
88+
// Channel notifications are queued
89+
// Define what connection to use.
90+
'connection' => 'sync',
91+
92+
// Define what queue to use
93+
'queue' => 'default',
94+
95+
// Do you want to delay the notifications at all?
96+
'delay' => null,
7997
],
8098
'channels' => [ // Where to send notifications?
8199
'discord' => [
82-
'enabled' => false, // Do you want discord webhook notifications?
100+
// Do you want discord webhook notifications?
101+
'enabled' => env('QUERY_WATCH_CHANNEL_DISCORD_ENABLED', false),
102+
103+
// Discord Web-hook URL
83104
'hook' => env('DISCORD_HOOK', 'please_fill_me_in'),
84105
],
85106
'slack' => [
86-
'enabled' => false, // Do you want Slack webhook notifications?
107+
// Do you want Slack webhook notifications?
108+
'enabled' => env('QUERY_WATCH_CHANNEL_SLACK_ENABLED', false),
109+
110+
// Slack Web-hook URL
87111
'hook' => env('SLACK_HOOK', 'please_fill_me_in'),
88112
],
89113
]
@@ -143,6 +167,7 @@ Once you have done this, you can enable Discord Notifications in the configurati
143167

144168
- [Notification Channels Wiki](https://github.com/YorCreative/Laravel-Query-Watcher/wiki/Notification-Channels)
145169
- [Screenshots](https://github.com/YorCreative/Laravel-Query-Watcher/wiki/Screenshots)
170+
146171
## Testing
147172

148173
```bash

config/querywatcher.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<?php
22

33
return [
4-
'enabled' => true,
4+
'enabled' => env('QUERY_WATCH_ENABLED', true),
55
'token' => env('QUERY_WATCH_TOKEN', 'change_me'),
66
'scope' => [
77
'time_exceeds_ms' => [
8-
'enabled' => false,
9-
'threshold' => 2,
8+
'enabled' => env('QUERY_WATCH_SCOPE_TIME_ENABLED', false),
9+
'threshold' => env('QUERY_WATCH_SCOPE_TIME_THRESHOLD', 500),
1010
],
1111
'context' => [
1212
'auth_user' => [
13-
'enabled' => true,
14-
'ttl' => 300,
13+
'enabled' => env('QUERY_WATCH_SCOPE_CONTEXT_AUTH_ENABLED', true),
14+
'ttl' => env('QUERY_WATCH_SCOPE_CONTEXT_AUTH_TTL', 300),
1515
],
1616
'trigger' => [
17-
'enabled' => true,
17+
'enabled' => env('QUERY_WATCH_SCOPE_TRIGGER_ENABLED', true),
1818
],
1919
],
2020
'ignorable_tables' => [
@@ -31,11 +31,11 @@
3131
],
3232
'channels' => [
3333
'discord' => [
34-
'enabled' => false,
34+
'enabled' => env('QUERY_WATCH_CHANNEL_DISCORD_ENABLED', false),
3535
'hook' => env('DISCORD_HOOK', 'placeholder'),
3636
],
3737
'slack' => [
38-
'enabled' => false,
38+
'enabled' => env('QUERY_WATCH_CHANNEL_SLACK_ENABLED', false),
3939
'hook' => env('SLACK_HOOK', 'placeholder'),
4040
],
4141
],

src/Strategies/NotificationStrategy/Channels/Discord.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class Discord implements NotificationChannelInterface
1313
*/
1414
public function isEnabled(): bool
1515
{
16-
return config('querywatcher.channels.discord.enabled');
16+
return is_bool(config('querywatcher.channels.discord.enabled'))
17+
? config('querywatcher.channels.discord.enabled')
18+
: false;
1719
}
1820

1921
/**

src/Strategies/NotificationStrategy/Channels/Slack.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class Slack implements NotificationChannelInterface
1313
*/
1414
public function isEnabled(): bool
1515
{
16-
return config('querywatcher.channels.slack.enabled');
16+
return is_bool(config('querywatcher.channels.slack.enabled'))
17+
? config('querywatcher.channels.slack.enabled')
18+
: false;
1719
}
1820

1921
/**

0 commit comments

Comments
 (0)