Skip to content

Incorrectly formatted json in results data column #310

@alexjustesen

Description

@alexjustesen

Describe the bug
The output of a speedtest is being store in results.data in the incorrect format. The field contains escaping characters \ and new lines \n which breaks Laravel's model casting from working correctly.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the dashboard
  2. Click on "Queue Speedtest" and wait for it to run
  3. Open a database IDE and browse the table results
  4. See incorrectly formatted json

Expected behavior
Modify app/Jobs/ExecSpeedtest.php to correctly store the results received by the speedtest-cli.

Result::create([
    //...
   'data' => $output, // <- change this
   'data' => $results, // <- to this and let Laravel convert the array automatically.
]);

Screenshots
The last row of this screenshot has the correct data format when using the decoded $output value from $results.
image

Additional Context
This has been the root cause of a lot of the other issues and the model attribute casting not working. The issue keeps cropping up when passing data to InfluxDB.

Things that will break

  • InfluxDb integration
  • Dashboard charts
  • Results table
  • Legacy APIs
  • tbd...

Databases to test

  • sqlite
  • mysql/mariadb
  • postgresql

Steps to fix the issue

Option 1 - iterate through each record and re-encode it.

DB::table('results')->chunkById(100, function ($result) {
    foreach ($results as $result) {
        $data = json_decode($result->data);

        DB::table('results')
            ->where('id', $result->id)
            ->update(['data' => $data]);
    }
});

Option x - tbd...

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions