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

Add MySQL/MariaDB transport #708

Merged
merged 3 commits into from Nov 8, 2019
Merged

Conversation

theproductiveprogrammer
Copy link
Contributor

@theproductiveprogrammer theproductiveprogrammer commented Sep 11, 2019

Hi - I've added a transport for MySQL/MariaDB which can extract fields from anywhere in the log stream and map them to database columns. It can also save the entire stream as a JSON field in MySQL. I found this useful for my latest project using the wonderful pino logger.
You can check the release here: https://www.npmjs.com/package/pino-mysql

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this is pretty amazing!

Copy link
Member

@davidmarkclements davidmarkclements left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the transport looks amazing, just one nit in the markdown

@davidmarkclements
Copy link
Member

side note for the transport readme: as a general rule I'd avoid encouraging use of npx - not that I've never used it, it's just encouraging remote execution as a general concept could reduce trust perception for your module

Co-Authored-By: David Mark Clements <david.mark.clements@gmail.com>
Co-Authored-By: David Mark Clements <david.mark.clements@gmail.com>
@theproductiveprogrammer
Copy link
Contributor Author

the transport looks amazing, just one nit in the markdown

Agreed @davidmarkclements - have accepted your changes

@theproductiveprogrammer
Copy link
Contributor Author

side note for the transport readme: as a general rule I'd avoid encouraging use of npx - not that I've never used it, it's just encouraging remote execution as a general concept could reduce trust perception for your module

Ah - that didn't strike me. I've updated my README - thanks @davidmarkclements

@jsumners
Copy link
Member

jsumners commented Sep 12, 2019

Wouldn't you at least want to suggest this schema?

create table logs (
  id int(10) unsigned not null auto_increment primary key,
  created timestamp default current_timestamp,
  log json,

  index created (created)
)

And maybe an index on JSON? Maybe also show some generated columns to index specific values in JSON.

Copy link
Member

@davidmarkclements davidmarkclements left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

@davidmarkclements
Copy link
Member

once @jsumners feedback is addressed and resolved we're good to merge 👍

@theproductiveprogrammer
Copy link
Contributor Author

Wouldn't you at least want to suggest this schema?

create table logs (
  id int(10) unsigned not null auto_increment primary key,
  created timestamp default current_timestamp,
  log json,

  index created (created)
)

And maybe an index on JSON? Maybe also show some generated columns to index specific values in JSON.

I've provided a couple of minimal DB schema's in the README and it also contains some examples of extracting fields from the log.

@jsumners
Copy link
Member

There is no blockage from me on this PR. I'll just point out that you can save cycles in your transport by defining a column like:

req_url varchar generated always as ( json_unquote(json_extract(log, '$.req.url')) ) stored

Basically, let the database engine take care of extracting the field if it exists.

@theproductiveprogrammer
Copy link
Contributor Author

@jsumners I didn't know MySQL could do that. Thanks! That's very cool. I've added your suggestion to the README as well.

@github-actions
Copy link

github-actions bot commented Feb 3, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants