-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[pkg/stanza] Add monitoring metrics for open and harvested files in fileconsumer #31544
Conversation
90e25c4
to
013941a
Compare
a51c88b
to
bb8d0f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind splitting this into two PRs - one to pass in component.TelemetrySettings
, the other to add the metrics?
df7ecbd
to
00e930a
Compare
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Still WiP. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Still WiP |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
ade99b7
to
6059fe4
Compare
pkg/stanza/fileconsumer/config.go
Outdated
meter := set.MeterProvider.Meter("otelcol/fileconsumer") | ||
|
||
openedFiles, err := meter.Int64UpDownCounter( | ||
"fileconsumer"+"/"+"open_files", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this broken up because there was an intention to use constants?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, but good point. I will make those constants!
pkg/stanza/fileconsumer/file.go
Outdated
@@ -105,6 +110,7 @@ func (m *Manager) startPoller(ctx context.Context) { | |||
|
|||
// poll checks all the watched paths for new entries | |||
func (m *Manager) poll(ctx context.Context) { | |||
m.reportMetrics(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to increment whenever we open a file and decrement whenever we close one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that would doable inside the Tracker
. Specifically inside the Add(reader *reader.Reader)
and ClosePreviousFiles()
methods. Is that what you had in mind?
In that case, the metric should be called otelcol_tracker_open_files
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name can stay the same. IMO users don't need to be exposed to the internal package structure. Sticking with fileconsumer seems specific enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to increment whenever we open a file and decrement whenever we close one?
So, files are opened by the Manager
but are closed by the Manager
and the Tracker
as well from what I can see.
Also inside the Manager
's operations there are multiple places where files are re-opened and then their readers are closed again like at https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/v0.100.0/pkg/stanza/fileconsumer/file.go#L203 or https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/v0.100.0/pkg/stanza/fileconsumer/file.go#L222.
Based on this I thought that it makes sense to simplify and only increment the openFiles
counter only when we create a fresh reader at https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/v0.100.0/pkg/stanza/fileconsumer/file.go#L225-L232.
Incrementing in previous steps and then possibly decrementing after a couple of instrunctions didn't make a lot of sense to me but let me know what you think :).
8010c71
to
cdff3b2
Compare
Hi @ChrsMark, one quick question, are the new metrics shown at |
They are shown on the |
cdff3b2
to
e576ec9
Compare
@@ -106,6 +131,7 @@ func (t *fileTracker) ClosePreviousFiles() { | |||
|
|||
for r, _ := t.previousPollFiles.Pop(); r != nil; r, _ = t.previousPollFiles.Pop() { | |||
t.knownFiles[0].Add(r.Close()) | |||
t.openFiles.Add(context.TODO(), -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really the only opening or closing of files we do in the tracker, so it does feel quite awkward to have the tracker manage the meter. Instead, what if we just return the number of files closed from this method? We're closing them one after another, so decrementing after each one or all at once seems equivalent in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case we would need to either have the EndConsume()
to return the number of files closed as well. or to move the ClosePreviousFiles()
outside of it. I'm leaning towards the latter.
It seems that the calling order of the ClosePreviousFiles()
is different on Windows so we cannot decouple it from the EndConsume()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latter won't work because the order of operations is different depending on OS.
I think we could get rid of OS dependent behavior for closing files if we implement #32037.
Otherwise, I'm fine with returning the count from EndConsume
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had missed that EndConsume
of noStateTracker
closes files directly so we need to have it returning the number of files closed anyway.
32f8e54
to
52aeef2
Compare
Signed-off-by: ChrsMark <chrismarkou92@gmail.com>
35d922f
to
a94b94f
Compare
Signed-off-by: ChrsMark <chrismarkou92@gmail.com>
a94b94f
to
cff6b64
Compare
@@ -73,7 +77,7 @@ func (m *Manager) Stop() error { | |||
m.cancel = nil | |||
} | |||
m.wg.Wait() | |||
m.tracker.ClosePreviousFiles() | |||
m.openFiles.Add(context.TODO(), int64(0-m.tracker.ClosePreviousFiles())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you willing to look into what it takes to pass the context through?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken we could pass down the ctx
from the Shutdown
of the stanza receiver when we stop the internal pipeline at
pipelineErr := r.pipe.Stop() |
Then if we pass the ctx
on every single operator's Stop()
we can make it available to the Stop()
of the Manager
/fileconsumer at
return i.fileConsumer.Stop() |
file_input
operator.
This would be doable I think but would be a breaking change for the Pipeline
interface and the Operator
interface (plus the Manager
).
Hence, I'm not sure if that's worth doing it unless we find value in doing so anyways and not just for the meter's need?
Blocked on #31618
Description:
This PR adds support for filelog receiver to emit observable metrics about its current state: how many files are opened, and harvested.
Link to tracking Issue: #31256
Testing:
How to test this manually
make otelcontribcol && ./bin/otelcontribcol_linux_amd64 --config ~/otelcol/monitoring_telemetry/config.yaml
Documentation:
Added a respective section in Filelog receiver's docs.