pdphilip / laravel-opensearch

An OpenSearch implementation of Laravel's Eloquent ORM
MIT License
16 stars 1 forks source link

[Fixed] The `query_log` configuration doesn't seem to be working #4

Closed m-kas closed 3 weeks ago

m-kas commented 1 month ago

Hello, great job on this library, it made it a lot easier for me when I had to quickly integrate the OS. Much appreciated.

🙋 Do these configuration settings from database connection even work?

    'query_log'    => [
        'index'      => false,  // Or provide a name for the logging index ex: 'laravel_query_logs'
        'error_only' => true,   // If false, then all queries are logged if the query_log index is set
    ],

Despite providing the name of the index that exists, nothing is logged into it.

I also searched the source code of your library and found no references to these configuration variables anywhere.

pdphilip commented 1 month ago

Hey @m-kas, this was an alpha feature from the elasticsearch version of this package quite some time ago. I can't remember why I abandoned this feature. I think in part that logging every query was impractical but logging the errors still makes sense. I'll revisit this and let you know.

Just looking for the errors right?

m-kas commented 1 month ago

If possible, logging all queries, not just errors, would be great. If not, at least errors 🙏

Thanks in advance, best!

Edit:

I might add a short explanation why I needed to log all queries:

Generally, I had the need to change existing models from MySQL to OS, because MySQL was becoming inefficient, and I perform various aggregation calculations on a large data set.

And the change with your library to OpenSearch went smoothly, but unfortunately some operations became 4x longer than on MySQL (even with a much smaller amount of data). That's why I wanted to debug and track exactly what queries are being executed and check if there is something wrong with my code or what I can improve.

pdphilip commented 3 weeks ago

Hi @m-kas, I have fixed this up now, however you'll need to upgrade to the latest version of the package (v2.0.2) and change some settings in your database.php file as follows:

// database.php
'opensearch' => [
  'driver'          => 'opensearch',
  //......
  //......
  //......
  'error_log_index' => env('OS_ERROR_INDEX', false),
],

If you set OS_ERROR_INDEX in your .env then that will be the index that the errors are written to. This will be useful when keeping track of index errors throughout your app.

Keep track of all queries was not a viable option as it inundated the tracking index, however, if you want to see what's happening under the hood, the latest release has a toDsl() method that you can use to see how the query builder is being parsed, docs: https://opensearch.pdphilip.com/os-specific#to-dsl

All the best