Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up[Custom_sd] Impossible to remove targets from the discovery #4573
Comments
This comment has been minimized.
This comment has been minimized.
This is exactly what needs to be done and this is what integrated SD mechanisms do. See the file SD for instance: prometheus/discovery/file/file.go Lines 334 to 348 in 40517dc |
simonpasquier
added
kind/question
component/service discovery
labels
Sep 4, 2018
This comment has been minimized.
This comment has been minimized.
|
Thanks for replying. Does it mean that the custom_sd.json file will grow indefinitely everytime a source disappears ? Something like that : [
{
"targets": [],
"labels": {}
},
{
"targets": [],
"labels": {}
},
{
"targets": [],
"labels": {}
},
[......]
{
"targets": [
"192.168.1.12:9090"
],
"labels": {
"__address__": "192.168.1.12:9090",
"__meta_application": "FOO",
"__meta_source": "source1"
}
}
]Would it be possible to create a function to unregister a source in the manager? |
This comment has been minimized.
This comment has been minimized.
|
Indeed it might create several items with empty target lists if |
simonpasquier
added
kind/bug
priority/P3
and removed
kind/question
labels
Sep 5, 2018
Nexucis
referenced this issue
Sep 5, 2018
Merged
[ServiceDiscovery] Unregister source when the target is empty #4575
This comment has been minimized.
This comment has been minimized.
|
I'm not saying that the manager is wrong. I'm just saying, since the manager is responsible to keep in memory the different target retrieved, it should be the responsibility of the manager to unregister the target. And it's with this logic that I create a light pull request to "fix" the bug. :) |
Nexucis commentedSep 4, 2018
Bug Report
What did you do?
Write code to implement custom service discovery;
What did you expect to see?
I expect that the targets that don't exist are removed in the custom_sd.json.
What did you see instead? Under which circumstances?
When a target is removed in the custom discovery, there is no way to remove the targetGroup in the updated channel
Environment
System information:
Prometheus version:
2.3.2
GO Version :
Demo
I write a short demo to reproduce the bug
The data.yaml file is "a service" that giving me all the targets that should be scraped.
When the code is running change the source in the file "data.yaml" like the following step :
We have this custom_sd.json :
[ { "targets": [ "localhost:1954" ], "labels": { "__address__": "localhost:1954", "__meta_application": "PYM", "__meta_source": "source2" } } ]And I have this file as result :
[ { "targets": [ "localhost:1954" ], "labels": { "__address__": "localhost:1954", "__meta_application": "PYM", "__meta_source": "source2" } }, { "targets": [ "192.168.1.12:9090" ], "labels": { "__address__": "192.168.1.12:9090", "__meta_application": "FOO", "__meta_source": "source1" } } ]Instead of having this one :
[ { "targets": [ "192.168.1.12:9090" ], "labels": { "__address__": "192.168.1.12:9090", "__meta_application": "FOO", "__meta_source": "source1" } } ]Crappy Workaround:
The only way that I found to remove the target in the file is to send an update of the targetGroup.source with all the other parameter to nil. But it's creating an empty target group as below
[ { "targets": [], "labels": {} }, { "targets": [ "192.168.1.12:9090" ], "labels": { "__address__": "192.168.1.12:9090", "__meta_application": "FOO", "__meta_source": "source1" } } ]