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

ordering_criteria does not work for filelog receiver #32792

Closed
zekai-rai opened this issue May 1, 2024 · 9 comments · Fixed by #32820
Closed

ordering_criteria does not work for filelog receiver #32792

zekai-rai opened this issue May 1, 2024 · 9 comments · Fixed by #32820
Labels
bug Something isn't working documentation Improvements or additions to documentation receiver/filelog

Comments

@zekai-rai
Copy link

Component(s)

receiver/filelog

What happened?

Description

After setting ordering_criteria with mtime, I observed that files are always processed in the descending order of the mtime, regardless whether ascending is true or false.

I need this for both filelog receiver and otlpjsonfile receiver and tested both.

Steps to Reproduce

Configure the receiver this way, and add file one by one so that they have different last modified timestamps.

otlpjsonfile/metrics:
    include: [ /mount/shared-events/test_metrics/data_*.json ]
    start_at: "beginning" # set to "end" if delete_after_read is set to false
    poll_interval: 5s
    fingerprint_size: 5kb
    delete_after_read: true # If true, each log file will be read and then immediately deleted
    #storage: file_storage
    ordering_criteria:
      sort_by: 
        sort_type: mtime
        ascending: true

Expected Result

With sort_type: mtime and ascending: true, I expected files to be processed in the ascending order of the modified time.

Actual Result

Files are always processed in the descending order.

Collector version

v0.98

Environment information

Environment

OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

otlpjsonfile/metrics:
    include: [ /mount/shared-events/test_metrics/data_*.json ]
    start_at: "beginning" 
    poll_interval: 5s
    fingerprint_size: 5kb
    delete_after_read: true # If true, each log file will be read and then immediately deleted
    #storage: file_storage
    ordering_criteria:
      sort_by: 
        sort_type: mtime
        ascending: true

Log output

No response

Additional context

No response

@zekai-rai zekai-rai added bug Something isn't working needs triage New item requiring triage labels May 1, 2024
Copy link
Contributor

github-actions bot commented May 1, 2024

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@JaredTan95
Copy link
Member

Can you post sample data for data *.json?

@zekai-rai
Copy link
Author

Can you post sample data for data *.json?

The file is large, I can probably delete some content and paste here. What are you looking for? I will make sure to keep the information you are looking for.

@zekai-rai zekai-rai changed the title does not work for filelog receiver ordering_criteria does not work for filelog receiver May 1, 2024
@crobert-1
Copy link
Member

crobert-1 commented May 1, 2024

Hello @zekai-rai, it looks like you need to enable a feature gate for this to work properly, it's named filelog.mtimeSortType. Here's the implementation, and here's the feature gate in code.

Sorry for the confusion here, this should be documented more clearly 👍

@crobert-1 crobert-1 added documentation Improvements or additions to documentation and removed bug Something isn't working needs triage New item requiring triage labels May 1, 2024
@BinaryFissionGames
Copy link
Contributor

The mtime sort option doesn't respect the ascending option currently, it looks like it's been configured correctly.

(if you try and configure sort by mtime and don't have the feature gate enabled, the collector will not start

if !mtimeSortTypeFeatureGate.IsEnabled() {
return nil, fmt.Errorf("the %q feature gate must be enabled to use %q sort type", mtimeSortTypeFeatureGate.ID(), sortTypeMtime)
}
)

I think when I wrote the mtime sorting I didn't consider that you'd ever want to do an ascending sort, but when paired with the delete_on_read functionality, it could totally make sense to do, depending on your set up.

I also agree the docs could be more clear with regards to the feature gate.

@crobert-1 crobert-1 added the bug Something isn't working label May 1, 2024
@zekai-rai
Copy link
Author

zekai-rai commented May 1, 2024

The document isn't that unclear regarding the feature gate. Without the feature gate, it gave me an error explaining the setting, so I was able to run it.

@BinaryFissionGames, is descending order because newer files are assumed more important? Our use case here is that our downstream requires submitting records in order. Is this something you would consider adding?

Btw, a basic educational question, does otlpjsonfile receiver inherit this receiver? These setting are not documented there but are available.

@BinaryFissionGames
Copy link
Contributor

The descending order was just due to the main use-case being considered, which you can read in the original issue for it (it was mainly performance motivated)
#27812

I'd like to ask for @djaglowski 's opinion, but I think it's reasonable to support an ascending mtime sort.

@djaglowski
Copy link
Member

I think the use case for ascending makes sense, given that files are being deleted as they are consumed.

djaglowski pushed a commit that referenced this issue May 2, 2024
… mtime (#32820)

**Description:** <Describe what has changed.>
* Allow ascending sort when sorting by mtime

**Link to tracking Issue:** Closes #32792

**Testing:**
* Unit tests
@zekai-rai
Copy link
Author

@djaglowski and @BinaryFissionGames , thank you for adding this. Much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation receiver/filelog
Projects
None yet
5 participants