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

pino.transport() #1003

Merged
merged 66 commits into from
Jul 3, 2021
Merged

pino.transport() #1003

merged 66 commits into from
Jul 3, 2021

Conversation

mcollina
Copy link
Member

@mcollina mcollina commented Apr 7, 2021

This add pino.transport() based on thread-stream.

In theory, this supersedes #937 as we internalize the pinole part.

Supports Node v12.20.0 onwards.

Things that are missing:

  • Docs
  • transport example/boilerplate
  • Support for transport packages
  • Support for pure function transports (is this actually needed?)
  • More tests
  • pino-specific benchmarks
  • test support for transport packages on windows

lib/transport.js Show resolved Hide resolved
lib/transport.js Show resolved Hide resolved
@jsumners
Copy link
Member

jsumners commented Apr 7, 2021

  • Support for pure function transports (is this actually needed?)

I think so.

lib/transport.js Outdated Show resolved Hide resolved
lib/transport.js Outdated Show resolved Hide resolved
lib/transport.js Outdated Show resolved Hide resolved
lib/transport.js Outdated Show resolved Hide resolved
@mcollina
Copy link
Member Author

mcollina commented Apr 7, 2021

  • Support for pure function transports (is this actually needed?)

I think so.

Why is that so? I'm not really understanding the need of it.
Processing one log line at a time is far from fast and it will generate a significant build-up in memory.

@jsumners
Copy link
Member

jsumners commented Apr 7, 2021

Processing one log line at a time is far from fast

I suppose I didn't quite follow what was meant by the item.

@mcollina
Copy link
Member Author

mcollina commented Apr 7, 2021

pinole expects a transport to be a pure function: https://github.com/pinojs/pinole/blob/f347c04d4a6c61e05e6ac821e510548aab928458/lib/worker.mjs#L18-L28.
Then it uses await to process every incoming chunk of data one at a time.

You can also see this at https://github.com/pinojs/pino/pull/937/files#diff-b230460830160b31f0c5495a4524feaf9cbc4adba704dbeae6ef3485c45d5b5d

@mcollina mcollina mentioned this pull request Apr 7, 2021
@mcollina mcollina added the v7 label Apr 7, 2021
package.json Outdated Show resolved Hide resolved
lib/transport.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
)
const transport = pino.transport({
targets: [{
level: 'info',
Copy link
Member

Choose a reason for hiding this comment

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

how does this work with custom levels?

Copy link
Member

Choose a reason for hiding this comment

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

can the level option be supported as a top level option as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

how does this work with custom levels?

I literally have no clue, I'm not convinced it would work as it is. I would recommend to document that it does not work with custom levels right now.

@mcollina mcollina marked this pull request as ready for review July 2, 2021 22:29
@mcollina
Copy link
Member Author

mcollina commented Jul 2, 2021

@jsumners I think this is ready to go. Could you take a look so we can ship it?

@kibertoad
Copy link
Contributor

@mcollina please ping me to revise types after this lands

docs/api.md Outdated Show resolved Hide resolved
docs/api.md Outdated Show resolved Hide resolved
docs/api.md Outdated Show resolved Hide resolved
docs/transports.md Outdated Show resolved Hide resolved
docs/transports.md Outdated Show resolved Hide resolved
@@ -905,6 +906,98 @@ A `pino.destination` instance can also be used to reopen closed files
* See [Reopening log files](/docs/help.md#reopening)
* See [Asynchronous Logging ⇗](/docs/asynchronous.md)

<a id="pino-transport"></a>
### `pino.transport(options) => ThreadStream`
Copy link
Member

Choose a reason for hiding this comment

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

There should be a callout here, and in the transports specific docs, to notify the reader about CPU core count. Ideally, a core for the main app + a core per worker thread (transport) should be available.

const { once } = require('events')

module.exports = async function (opts) {
// TODO remove the transform
Copy link
Member

Choose a reason for hiding this comment

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

TODO?

}
})

// TODO figure out why sync: false does not work here
Copy link
Member

Choose a reason for hiding this comment

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

TODO?

Comment on lines 19 to 21
// TODO figure out why sync: false does not work here
// TODO remove the istanbul ignore, add a test using a
// child_process
Copy link
Member

Choose a reason for hiding this comment

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

TODO?

Comment on lines +19 to +21

if (workerOpts.autoEnd !== false) {
// TODO possibly use FinalizationGroup to automatically remove
Copy link
Member

Choose a reason for hiding this comment

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

TODO?

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to not resolve this here. There is a space for a tiny little utility for doing exactly this, however it's better developed in isolation. It's more a note for improvements in the future.

This means we are leaking memory if a transport is not closed. I think it's ok.

mcollina and others added 6 commits July 3, 2021 10:06
Co-authored-by: James Sumners <[email protected]>
Co-authored-by: James Sumners <[email protected]>
Co-authored-by: James Sumners <[email protected]>
Co-authored-by: James Sumners <[email protected]>
Co-authored-by: James Sumners <[email protected]>
@mcollina
Copy link
Member Author

mcollina commented Jul 3, 2021

I've addressed most comments @jsumners

@mcollina mcollina merged commit 849f65a into next Jul 3, 2021
@mcollina
Copy link
Member Author

mcollina commented Jul 3, 2021

@kibertoad could you please send a PR to update the types?

@kibertoad
Copy link
Contributor

@mcollina I take it api is final and I can add types?

@kibertoad
Copy link
Contributor

on it!

@mcollina
Copy link
Member Author

mcollina commented Jul 3, 2021

Yes it should be. It might change further in the -rc cycle once we gather feedback, but we are at a point where it's better to give this in the hands of users.

@kibertoad
Copy link
Contributor

kibertoad commented Jul 3, 2021

@mcollina Are you sure that multiple transport example in docs/api.md is correct?

When I'm trying this:

const transports = pino.transport([
    {
        level: 'info',
        target: '#pino/pretty',
        options: { some: 'options for', the: 'transport' }
    },
    {
        level: 'trace',
        target: '#pino/file',
        options: { destination: './' }
    }
])

It explodes on if (isAbsolute(origin) || origin.indexOf('file://') === 0) {, because target is not set.

@mcollina
Copy link
Member Author

mcollina commented Jul 4, 2021

good spot: #1049

@jsumners jsumners deleted the transport branch November 20, 2021 18:04
@github-actions
Copy link

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 Nov 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants