Perhaps you didn't write the file atomically. If you start appending to the file, and Prometheus notices you've changed it, it may read it before you've finished writing.
You should: 1. Write out a new file, e.g. target.json.new 2. fsync it (os.File.Sync) 3. rename target.json.new to target.json On Tuesday 12 December 2023 at 13:11:53 UTC akshay sharma wrote: > Hi, > > I have an application running, which is accepting the post request to add > targets in the path /etc/prometheus/config/target.json. > > Currently, I'm posting 2-3 targets using curl to the application which in > turn adds to the Prometheus path, post is happening in a time difference of > 2-3 minutes. > > In Prometheus UI, I could see it is adding only one target or can see only > one target in service discovery, but I have added 3 targets. > > could see some errors in Prometheus: > > ts=2023-12-12T10:27:15.936Z caller=file.go:343 level=error > component="discovery manager scrape" discovery=file config=ne-federation > msg="Error reading file" path=/etc/prometheus/config/targets.json > err="unexpected end of JSON input" > ts=2023-12-12T10:35:50.707Z caller=file.go:343 level=error > component="discovery manager scrape" discovery=file config=ne-federation > msg="Error reading file" path=/etc/prometheus/config/argets.json > err="unexpected end of JSON input" > > I checked the JSON file using JSON validator, it's perfectly valid. > > can you please help with what could be the issue? > -- You received this message because you are subscribed to the Google Groups "Prometheus Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/336e5fb6-cf8f-4ce0-a60e-0543907b7142n%40googlegroups.com.

