prometheus: Lots of "discovery manager scrape" errors message while reading local json files after 2.46.0 upgrade
What did you do?
We have an external process that generate json target files regularly (every 10 min) from different sources. Those files are local to the Prometheus process and are overridden every 10 min.
This have been working flawlessly since a couple of year and I never saw anything complaining on the prometheus logs.
After upgrading from 2.44.0 to 2.46.0 I started to see logs entry about The process cannot access the file because it is being used by another process. And as we refresh the files very often (and we do have multiple files) it fill the log and make it harder to see
What did you expect to see?
Similar behavior of the file reading discovery manager scrape process
What did you see instead? Under which circumstances?
Lots of log entry complaining about the file being used by another process
One of my concerns is that the is two possibilities:
- Prometheus have always had those “used by another process” errors but didn’t log them
- Something has changed that cause those new errors
The risk for us is to lose targets from time to time if Prometheus is not happy with the read process and fill the logs with useless messages (we do know those files are been rewritten regularly)
Missing a read one time should probably not be an error but a warning no?
Edit: I tried using the --enable-feature=new-service-discovery-manager flag but the issue persist
System information
Windows 2019
Prometheus version
2.46.0
Prometheus configuration file
- job_name: 'job1'
file_sd_configs:
- files:
- './prometheus.file_sd.targets.file1.json'
- './prometheus.file_sd.targets.file2.json'
Alertmanager version
No response
Alertmanager configuration file
No response
Logs
ts=2023-08-09T09:47:57.889Z caller=file.go:343 level=error component="discovery manager scrape" discovery=file config=prometheus msg="Error reading file" path=P:\Prometheus\prometheus.file_sd.targets.file1.json err="open P:\\Prometheus\\prometheus.file_sd.targets.file1.json: The process cannot access the file because it is being used by another process."
ts=2023-08-09T09:47:57.905Z caller=file.go:343 level=error component="discovery manager scrape" discovery=file config=alertmanager msg="Error reading file" path=P:\Prometheus\prometheus.file_sd.targets.file2.json err="open P:\\Prometheus\\prometheus.file_sd.targets.file2.json: The process cannot access the file because it is being used by another process."
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (8 by maintainers)
This is not an atomic operation (on the targets file), however fast the copy is (this is happening over SMB, so it’s gonna be slow in term of IO).
The open FD can now encompass a file being deleted as well. IIRC this is exactly the missing FILE_SHARE_DELETE permission missing from the open operation.
Copy the old file for backup, move the new file into a temp in the Prometheus server and then atomically move the file, overwriting the old one feels like a better approach here.