英文:
Deletion of metrics not working kubernetes operator controller
问题
我一直在处理我的运算符,其中一些自定义指标设置了值,这方面工作得很好(注册和显示指标值)。问题是指标删除没有发生。我尝试声明一个单独的函数来删除指标。
我的运算符正在启动有状态集和服务,但在删除我的CR时,子资源被删除,但指标没有更新/删除。
func (r *cr) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
......
......
if errors.IsNotFound(err) {
l.Info("CR not found so maybe deleted")
l.Info("Deleting CR metric Instance")
DeleteMetric(instance, true)
return ctrl.Result{}, nil
}
func DeleteMetric(cr *CR, condition bool) {
l := logf.Log.WithName("CR Metric deletion")
l.Info("Deleting metric for CR", "instance", cr.Name, "from namespace", cr.Namespace)
if condition {
custom_metric_name.Delete(prometheus.Labels{
"name": cr.Name,
"namespace": cr.Namespace,
})
}
}
我还尝试使用DeleteFunc
声明谓词,但没有成功,我的指标仍然无法删除。
感谢任何帮助或指导。
英文:
I have been working on my operator where I have some of the custom metric setting the values and that works fine (registration and displaying the metric value). The problem is that metric deletion isn't happening. I tried to declare a separate function that delete the metric.
My operator is spinning up statefulset and service but upon deletion of my CR the child resources gets removed but metric doesn't get any update/deletion.
func (r *cr) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
......
......
if errors.IsNotFound(err) {
l.Info("CR not found so maybe deleted")
l.Info("Deleting CR metric Instance")
DeleteMetric(instance, true)
return ctrl.Result{}, nil
}
func DeleteMetric(cr *CR, condition bool) {
l := logf.Log.WithName("CR Metric deletion")
l.Info("Deleting metric for CR", "instance", cr.Name, "from namespace", cr.Namespace)
if condition {
custom_metric_name.Delete(prometheus.Labels{
"name": cr.Name,
"namespace": cr.Namespace,
})
}
}
I also tried to declare predicate with DeleteFunc
but no luck and my metrics still can't be deleted.
Appreciate any help or pointers.
答案1
得分: 0
我能够让这个工作起来,删除指标只需根据资源的完成操作调用自定义指标的删除函数。
参考调用自定义指标的删除函数,当你的自定义资源完成工作时,你可以调用该函数。
https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#MetricVec.DeleteLabelValues
英文:
I am able to get this working, deletion of metric happens to be simply by calling the custom metric with the delete function based on the finished operation of resource.
For reference calling delete on the custom metric would work and you can call the function when the work is done on your custom resource.
https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#MetricVec.DeleteLabelValues
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论