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 NamedPipe input operator #28841

Merged
merged 5 commits into from
Nov 15, 2023

Conversation

sinkingpoint
Copy link
Contributor

Description:

This is a namedpipe input operator, which will read from a named pipe and send the data to the pipeline. It pretty closely mimics the file input operator, but with a few differences.

In particular, named pipes have an interesting property that they receive EOFs when a writer closes the pipe, but that doesn't mean that the pipe is closed. To solve this issue, we crib from existing tail -f implementations and use an inotify watcher to detect whenever the pipe receives new data, and then read it using the standard bufio.Scanner reader.

Link to tracking Issue: #27234

Testing:

We add a couple of tests for the new operator. The first tests simply the creation of the named pipe - checking that it's created as a pipe, with the right permissions. The second goes further by inserting logs over several different Opens into the pipe, testing that the logs are read, and that the operator is able to handle the named pipe behavior of skipping over EOFs.

Documentation:

None, at the moment

/cc @djaglowski

@sinkingpoint sinkingpoint requested a review from a team November 1, 2023 03:04
Copy link

linux-foundation-easycla bot commented Nov 1, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Member

@songy23 songy23 left a comment

Choose a reason for hiding this comment

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

Please add a changelog

Copy link
Member

@djaglowski djaglowski left a comment

Choose a reason for hiding this comment

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

Overall looks about right to me.

pkg/stanza/operator/input/namedpipe/namedpipe.go Outdated Show resolved Hide resolved
pkg/stanza/operator/input/namedpipe/namedpipe.go Outdated Show resolved Hide resolved
This is a namedpipe input operator, which will read from a named pipe
and send the data to the pipeline. It pretty closely mimicks the file input operator,
but with a few differences.

In particular, named pipes have an interesting property that they receive
EOFs when a writer closes the pipe, but that _doesn't_ mean that the pipe
is closed. To solve this issue, we crib from existing `tail -f` implementations
and use an inotify watcher to detect whenever the pipe receives new data, and
then read it using the standard `bufio.Scanner` reader.

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
This allows the user to configure the maximum size of a log line, rather
than always using the default.

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
@sinkingpoint
Copy link
Contributor Author

Rebased and added licenses

Here we add a couple of tests to cover more cases of named pipe creation.
In particular:

 - A test to check that if a file already exists (i.e. not a named pipe),
   fail the operator creation.
 - A test to check that if a _pipe_ already exists, pass the operator
   construction because we can just use the existing pipe.

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
Signed-off-by: sinkingpoint <colin@quirl.co.nz>
@sinkingpoint
Copy link
Contributor Author

So many checks 😅

@sinkingpoint
Copy link
Contributor Author

@djaglowski is there a make command I can run that runs all of these? Feels like I'm playing cat and mouse a bit

@djaglowski
Copy link
Member

djaglowski commented Nov 14, 2023

Unfortuantely there's not a catchall because so much is only encoded in github actions. make all is pretty thorough but takes quite a while to run.

I should mention, if your changes are pretty well isolated to one or two modules, you can run make -C pkg/stanza common to get decent coverage pretty quickly.

@djaglowski djaglowski added the ready to merge Code review completed; ready to merge by maintainers label Nov 14, 2023
@djaglowski djaglowski merged commit 4e8e527 into open-telemetry:main Nov 15, 2023
88 checks passed
@github-actions github-actions bot added this to the next release milestone Nov 15, 2023
RoryCrispin pushed a commit to ClickHouse/opentelemetry-collector-contrib that referenced this pull request Nov 24, 2023
**Description:** 

This is a namedpipe input operator, which will read from a named pipe
and send the data to the pipeline. It pretty closely mimics the file
input operator, but with a few differences.

In particular, named pipes have an interesting property that they
receive EOFs when a writer closes the pipe, but that _doesn't_ mean that
the pipe is closed. To solve this issue, we crib from existing `tail -f`
implementations and use an inotify watcher to detect whenever the pipe
receives new data, and then read it using the standard `bufio.Scanner`
reader.

**Link to tracking Issue:** open-telemetry#27234

**Testing:**

We add a couple of tests for the new operator. The first tests simply
the creation of the named pipe - checking that it's created as a pipe,
with the right permissions. The second goes further by inserting logs
over several different `Open`s into the pipe, testing that the logs are
read, and that the operator is able to handle the named pipe behavior of
skipping over EOFs.

**Documentation:**

None, at the moment

/cc @djaglowski

---------

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
djaglowski pushed a commit that referenced this pull request Dec 13, 2023
**Description:**

This adds a new receiver that reads from a named pipe, using the
previously created namedpipeinput stanza operator (#28841). Because that
operator does the majority of the work, this is mostly boilerplate + a
few tests to confirm that it works e2e.

Link to tracking Issue: #27234

**Testing:**

Added a few tests, loading the config, and actually creating a receiver
to verify that it can read logs from the pipe.

**Documentation:**

None, yet.

/cc @djaglowski - where should I add docs for this if any?
cparkins pushed a commit to AmadeusITGroup/opentelemetry-collector-contrib that referenced this pull request Jan 10, 2024
**Description:**

This adds a new receiver that reads from a named pipe, using the
previously created namedpipeinput stanza operator (open-telemetry#28841). Because that
operator does the majority of the work, this is mostly boilerplate + a
few tests to confirm that it works e2e.

Link to tracking Issue: open-telemetry#27234

**Testing:**

Added a few tests, loading the config, and actually creating a receiver
to verify that it can read logs from the pipe.

**Documentation:**

None, yet.

/cc @djaglowski - where should I add docs for this if any?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg/stanza ready to merge Code review completed; ready to merge by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants