Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fix InfluxDB Data Export & Add Test / Export History jobs #1802

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c1fcf77
first commit
svenvg93 Aug 5, 2024
2cf1042
Merge branch 'main' into add-average-2
svenvg93 Aug 6, 2024
1fb06af
Commit it
svenvg93 Aug 8, 2024
7825256
lint
svenvg93 Aug 8, 2024
7f1e903
update-all-charts
svenvg93 Aug 9, 2024
0073e6a
push_local_git
svenvg93 Aug 12, 2024
2122142
add-timepicker
svenvg93 Aug 12, 2024
4d7e8b2
Merge branch 'alexjustesen:main' into dashboard-remake
svenvg93 Aug 12, 2024
05b0091
add-some-predefined-ranges
svenvg93 Aug 13, 2024
afcf6b3
remove whiteline
svenvg93 Aug 13, 2024
756b324
Add_env_for_chart_start
svenvg93 Aug 15, 2024
1c4a92c
change-env-and_time-ranges
svenvg93 Aug 15, 2024
249340e
change_average_to_orange
svenvg93 Aug 21, 2024
b2ff25b
Merge pull request #2 from svenvg93/add-failed-and-thresholds
svenvg93 Aug 21, 2024
68389f1
Revert "Add failed and thresholds"
svenvg93 Aug 21, 2024
5e90f96
Merge pull request #3 from svenvg93/revert-2-add-failed-and-thresholds
svenvg93 Aug 21, 2024
56c7741
phase_1
svenvg93 Sep 11, 2024
bc951ba
Add_labels
svenvg93 Sep 11, 2024
aa4d8db
fix it
svenvg93 Sep 12, 2024
5d41c35
commit
svenvg93 Sep 12, 2024
cc1994b
commit
svenvg93 Sep 12, 2024
dd4c536
add_migration
svenvg93 Sep 13, 2024
291552d
lint
svenvg93 Sep 13, 2024
1c33420
tabs
svenvg93 Sep 23, 2024
2d1c155
Add Test and Export old Results
svenvg93 Oct 6, 2024
376535f
Add Scheduled and Status
svenvg93 Oct 6, 2024
9ea306a
Fix lint
svenvg93 Oct 6, 2024
71f67c5
Merge branch 'main' into feat/add-prometheus
svenvg93 Oct 6, 2024
16379fe
first commit
svenvg93 Aug 5, 2024
da528e0
Commit it
svenvg93 Aug 8, 2024
feec1eb
lint
svenvg93 Aug 8, 2024
555d643
update-all-charts
svenvg93 Aug 9, 2024
e979e7f
push_local_git
svenvg93 Aug 12, 2024
8adaf1d
add-timepicker
svenvg93 Aug 12, 2024
4d82245
add-some-predefined-ranges
svenvg93 Aug 13, 2024
6d64680
remove whiteline
svenvg93 Aug 13, 2024
95e03a2
Add_env_for_chart_start
svenvg93 Aug 15, 2024
66ff0b5
change-env-and_time-ranges
svenvg93 Aug 15, 2024
151b7d4
change_average_to_orange
svenvg93 Aug 21, 2024
75fa28a
Revert "Add failed and thresholds"
svenvg93 Aug 21, 2024
eff4432
phase_1
svenvg93 Sep 11, 2024
3971cf4
Add_labels
svenvg93 Sep 11, 2024
925e2d0
fix it
svenvg93 Sep 12, 2024
301acde
commit
svenvg93 Sep 12, 2024
3a4c41b
commit
svenvg93 Sep 12, 2024
cd141bc
add_migration
svenvg93 Sep 13, 2024
bc8c9e4
lint
svenvg93 Sep 13, 2024
653f2d9
tabs
svenvg93 Sep 23, 2024
4037e21
Add Test and Export old Results
svenvg93 Oct 6, 2024
1704df0
Add Scheduled and Status
svenvg93 Oct 6, 2024
345e52b
Fix lint
svenvg93 Oct 6, 2024
064e345
why
svenvg93 Oct 6, 2024
2d83819
Merge branch 'main' into feat/add-prometheus
svenvg93 Oct 10, 2024
f53d8cb
Fix lint
svenvg93 Oct 10, 2024
0810191
Merge branch 'main' into feat/add-prometheus
svenvg93 Nov 14, 2024
cdc140b
Merge branch 'alexjustesen:main' into feat/add-prometheus
svenvg93 Nov 20, 2024
0f3a929
Change name
svenvg93 Nov 20, 2024
2aefb1b
First commit
svenvg93 Nov 20, 2024
8acf678
remove prometheus from composer
svenvg93 Nov 20, 2024
96524e8
Rename InfluxDB settings
svenvg93 Nov 21, 2024
d57d769
Merge branch 'alexjustesen:main' into feat/add-influxdb2
svenvg93 Nov 23, 2024
cdf8d71
remove warning
svenvg93 Nov 23, 2024
9a7d907
Merge branch 'feat/add-influxdb2' of https://github.com/svenvg93/spee…
svenvg93 Nov 23, 2024
fb6a6ec
Merge branch 'alexjustesen:main' into feat/add-influxdb2
svenvg93 Nov 24, 2024
53d6ace
Make it part of the process
svenvg93 Nov 24, 2024
5af38b9
Move to Actions
svenvg93 Nov 27, 2024
e99dcc1
Fix conflits
svenvg93 Nov 27, 2024
f9b45b9
Merge branch 'main' into feat/add-influxdb2
svenvg93 Nov 27, 2024
6266371
Fix lint
svenvg93 Nov 27, 2024
b3a0e61
Merge branch 'feat/add-influxdb2' of https://github.com/svenvg93/spee…
svenvg93 Nov 27, 2024
0755a7f
Merge branch 'alexjustesen:main' into feat/add-influxdb2
svenvg93 Nov 27, 2024
7732204
Merge branch 'main' into feat/add-influxdb2
svenvg93 Dec 1, 2024
e6861e2
Merge branch 'main' into feat/add-influxdb2
alexjustesen Dec 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions .phpstorm.meta.php

Large diffs are not rendered by default.

456 changes: 237 additions & 219 deletions _ide_helper.php

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions app/Actions/InfluxDBv2/SendAllResultsToInfluxDB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Actions\InfluxDBv2;

use App\Jobs\InfluxDBv2\WriteSpeedtestResult;
use App\Models\Result;
use App\Settings\DataIntegrationSettings;
use Filament\Notifications\Notification;
use Lorisleiva\Actions\Concerns\AsAction;

class SendAllResultsToInfluxDB
{
use AsAction;

/**
* Execute the action.
*/
public function handle(): void
{
// Resolve the settings within the action
$settings = app(DataIntegrationSettings::class);

// Get the count of all Result records
$totalResults = Result::count();

if ($totalResults === 0) {
// Notify that there are no results to export
Notification::make()
->title('No Results to Export')
->body('There are no speed test results available to send to InfluxDB.')
->warning()
->send();

return;
}

// Notify that the export is starting
Notification::make()
->title('Export Started')
->body("Found {$totalResults} results to be sent to InfluxDB. Export process has started.")
->info()
->send();

// Fetch all results
$results = Result::all();

// Dispatch the job for each result
foreach ($results as $result) {
WriteSpeedtestResult::dispatch($result);
}
}
}
46 changes: 46 additions & 0 deletions app/Actions/InfluxDBv2/TestInfluxDB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Actions\InfluxDBv2;

use App\Jobs\InfluxDBv2\WriteSpeedtestResult;
use App\Models\Result;
use App\Settings\DataIntegrationSettings;
use Filament\Notifications\Notification;
use Lorisleiva\Actions\Concerns\AsAction;

class TestInfluxDB
{
use AsAction;

/**
* Execute the action.
*/
public function handle(): void
{
// Resolve the settings within the action
$settings = app(DataIntegrationSettings::class);

$influxdb = [
'enabled' => $settings->influxdb_v2_enabled,
'url' => $settings?->influxdb_v2_url,
'org' => $settings?->influxdb_v2_org,
'bucket' => $settings?->influxdb_v2_bucket,
'token' => $settings?->influxdb_v2_token,
];

if ($influxdb['enabled'] == true) {
// Create a test result if InfluxDB is enabled
$result = Result::factory()->create();

// Dispatch the job to write the result to InfluxDB
dispatch(new WriteSpeedtestResult($result, $settings));
}

// Optional: Notification
Notification::make()
->title('Success')
->body('A test log has been sent to InfluxDB. Check if the data is received!')
->success()
->send();
}
}
42 changes: 0 additions & 42 deletions app/Console/Commands/TestInfluxDB.php

This file was deleted.

1 change: 1 addition & 0 deletions app/Enums/ResultService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
enum ResultService: string implements HasLabel
{
case Ookla = 'ookla';
case faker = 'faker';

public function getLabel(): ?string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@

namespace App\Filament\Pages\Settings;

use App\Settings\InfluxDbSettings;
use App\Actions\InfluxDBv2\SendAllResultsToInfluxDB;
use App\Actions\InfluxDBv2\TestInfluxDB;
use App\Settings\DataIntegrationSettings;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Pages\SettingsPage;

class InfluxDbPage extends SettingsPage
class DataIntegrationPage extends SettingsPage
{
protected static ?string $navigationIcon = 'heroicon-o-circle-stack';

protected static ?string $navigationGroup = 'Settings';

protected static ?int $navigationSort = 2;

protected static ?string $title = 'InfluxDB';
protected static ?string $title = 'Data Integration';

protected static ?string $navigationLabel = 'InfluxDB';
protected static ?string $navigationLabel = 'Data Integration';

protected static string $settings = InfluxDbSettings::class;
protected static string $settings = DataIntegrationSettings::class;

public static function canAccess(): bool
{
Expand All @@ -37,56 +39,72 @@ public function form(Form $form): Form
->schema([
Forms\Components\Grid::make([
'default' => 1,
'md' => 3,
])
->schema([
Forms\Components\Section::make('InfluxDB v2 Settings')
Forms\Components\Section::make('InfluxDB v2')
->description('When enabled, all new Speedtest results will also be sent to InfluxDB.')
->schema([
Forms\Components\Toggle::make('v2_enabled')
Forms\Components\Toggle::make('influxdb_v2_enabled')
->label('Enable')
->reactive()
->columnSpan(2),
Forms\Components\Grid::make([
'default' => 1,
'md' => 3,
])
->hidden(fn (Forms\Get $get) => $get('v2_enabled') !== true)
->columnSpanFull(),
Forms\Components\Grid::make(['default' => 1, 'md' => 3])
->hidden(fn (Forms\Get $get) => $get('influxdb_v2_enabled') !== true)
->schema([
Forms\Components\TextInput::make('v2_url')
Forms\Components\TextInput::make('influxdb_v2_url')
->label('URL')
->placeholder('http://your-influxdb-instance')
->maxLength(255)
->required(fn (Forms\Get $get) => $get('v2_enabled') == true)
->columnSpanFull(),
Forms\Components\Checkbox::make('v2_verify_ssl')
->label('Verify SSL')
->columnSpanFull(),
Forms\Components\TextInput::make('v2_org')
->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true)
->columnSpan(['md' => 1]),
Forms\Components\TextInput::make('influxdb_v2_org')
->label('Org')
->maxLength(255)
->required(fn (Forms\Get $get) => $get('v2_enabled') == true)
->columnSpan(['md' => 2]),
Forms\Components\TextInput::make('v2_bucket')
->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true)
->columnSpan(['md' => 1]),
Forms\Components\TextInput::make('influxdb_v2_bucket')
->placeholder('speedtest-tracker')
->label('Bucket')
->maxLength(255)
->required(fn (Forms\Get $get) => $get('v2_enabled') == true)
->columnSpan(['md' => 1]),
Forms\Components\TextInput::make('v2_token')
->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true)
->columnSpan(['md' => 2]),
Forms\Components\TextInput::make('influxdb_v2_token')
->label('Token')
->maxLength(255)
->password()
->required(fn (Forms\Get $get) => $get('v2_enabled') == true)
->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true)
->disableAutocomplete()
->columnSpan(['md' => 2]),
Forms\Components\Checkbox::make('influxdb_v2_verify_ssl')
->label('Verify SSL')
->columnSpanFull(),
// Button to send old data to InfluxDB
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('Export current results')
->label('Export current results')
->action(fn () => app(SendAllResultsToInfluxDB::class)->handle())
->color('primary')
->icon('heroicon-o-cloud-arrow-up')
->visible(fn (): bool => app(DataIntegrationSettings::class)->influxdb_v2_enabled),
]),
// Button to test InfluxDB connection
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('Test InfluxDB connection')
->label('Test InfluxDB connection')
->action(fn () => app(TestInfluxDB::class)->handle())
->color('primary')
->icon('heroicon-o-check-circle')
->visible(fn (): bool => app(DataIntegrationSettings::class)->influxdb_v2_enabled),
]),
]),
])
->compact()
->columns([
'default' => 1,
'md' => 2,
]),
])
->columnSpan('full'),
]),
]);
}
}
71 changes: 0 additions & 71 deletions app/Jobs/InfluxDBv2/WriteCompletedSpeedtest.php

This file was deleted.

Loading