Skip to content

Commit

Permalink
Add initial release README
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjohnkane committed Feb 15, 2020
1 parent 8872396 commit f0742e5
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 33 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
@@ -1,7 +1,10 @@
# Changelog

All notable changes to `rename-me` will be documented in this file
All notable changes to `SlowQueryNotifer` will be documented in this file

## 1.0.0 - 201X-XX-XX
## 1.0.0 - 2020-02-18

- initial release
- Initial release
- Get an email if you violate the threshold
- Configure the threshold in your app service provider
- Enable/disable in your environment file
95 changes: 79 additions & 16 deletions README.md
@@ -1,22 +1,85 @@
# Deliverables
# Slow Query Notifier for Laravel

## Install & Config
- Set threshold in code
- Set email address in code
[![Latest Version on Packagist](https://img.shields.io/packagist/v/thomasjohnkane/slow-query-notifier.svg?style=flat-square)](https://packagist.org/packages/thomasjohnkane/slow-query-notifier)
[![Build Status](https://img.shields.io/travis/thomasjohnkane/slow-query-notifier/master.svg?style=flat-square)](https://travis-ci.org/thomasjohnkane/slow-query-notifier)
[![Quality Score](https://img.shields.io/scrutinizer/g/thomasjohnkane/slow-query-notifier.svg?style=flat-square)](https://scrutinizer-ci.com/g/thomasjohnkane/slow-query-notifier)
[![Total Downloads](https://img.shields.io/packagist/dt/thomasjohnkane/slow-query-notifier.svg?style=flat-square)](https://packagist.org/packages/thomasjohnkane/slow-query-notifier)

## Threshold Notifications
- Run test command via command line to get test notification
- Receive notification when threshold is met
- Handle queuing (graceful)
Get notified if your app ever runs an objectively slow database call.

## Error handling
- Handle errors silently (catch statement, logging)
## Installation

# Steps
- [X] Install orchestra testbench (Laravel Collective)
- [X] Build tests
- [ ] Benchmark performance impact (seed data with package, and without...laravel start time diff??)
- [ ] Branding/marketing planning with Caleb
- [ ] Update Readme
You can install the package via composer:

```bash
composer require thomasjohnkane/slow-query-notifier
```
## Usage
### Set an email address
```bash
// app/Providers/AppServiceProvider.php

use SlowQueryNotifier\SlowQueryNotifierFacade as SlowQueryNotifier;

public function boot()
{
SlowQueryNotifier::toEmail('admin@example.com');
}
```
## Test it works
```bash
php artisan sqn:test
```
This command will test two things:

- We can detect slow queries in your app
- We can send an email to you if a slow query runs

# Configuration

In general, we setup all of the configuration for you with sensible defaults. However, you can change the default settings if you'd like. To learn why we chose these defaults, <a href="#">read the blog post</a>.

## Threshold

The default is 99ms. Set a different `threshold` in milliseconds in your configuration:
```bash
SlowQueryNotifier::threshold(200)->toEmail('admin@example.com');
```
### Enable/Disable

The package is enabled by default. Set this value to `false` in your `.env` to bypass the listener.
```bash
SLOW_QUERY_NOTIFIER_ENABLED=false
```
### Testing

``` bash
phpunit
```

### Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

If you discover any security related issues, please email thomasjohnkane@gmail.com instead of using the issue tracker.

## Credits

- [Thomas Kane](https://github.com/thomasjohnkane)
- Thanks to Marcel Pociot for the original inspiration
- Thanks to Caleb Porzio for the guidance
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

## Laravel Package Boilerplate

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).
12 changes: 0 additions & 12 deletions build/report.junit.xml

This file was deleted.

17 changes: 16 additions & 1 deletion src/SlowQueryNotification.php
Expand Up @@ -3,6 +3,7 @@
namespace SlowQueryNotifier;

use Illuminate\Bus\Queueable;
use \Illuminate\Support\HtmlString;
use Illuminate\Support\Facades\Log;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand All @@ -13,6 +14,13 @@ class SlowQueryNotification extends Notification implements ShouldQueue
{
use Queueable;

protected $query;

public function __construct($query)
{
$this->query = $query;
}

public function via($notifiable)
{
return ['mail'];
Expand All @@ -21,6 +29,13 @@ public function via($notifiable)
public function toMail($notifiable): MailMessage
{
return (new MailMessage)
->subject('Query Threshold Exceeded');
->subject('Query Threshold Exceeded')
->greeting('We found a slow query:')
->line('Threshold: '.app(SlowQueryNotifier::class)->getThreshold().' ms')
->line('Time: '.$this->query->time.' ms')
->line(new HtmlString('<hr />'))
->line(new HtmlString('<code style="margin-top: 16px; color: white; background: #2d3748; border-radius: 6px; padding: 10px; display: block;">'.$this->query->sql.'<code>'))
->line(new HtmlString('<hr />'))
->salutation(new HtmlString('Yours Truley,<br />Slow Query Notifier'));
}
}
2 changes: 1 addition & 1 deletion src/SlowQueryNotifier.php
Expand Up @@ -42,7 +42,7 @@ public function checkQuery($query) {
if ($query->time > $this->threshold) {
try {
Notification::route('mail', $this->email)
->notify(new SlowQueryNotification());
->notify(new SlowQueryNotification($query));
} catch (\Exception $e) {
if ($this->throwsExceptions) {
throw $e;
Expand Down

0 comments on commit f0742e5

Please sign in to comment.