Home  >  Article  >  Backend Development  >  Remove metric unable to run kubernetes operator controller

Remove metric unable to run kubernetes operator controller

WBOY
WBOYforward
2024-02-10 14:33:08914browse

删除无法运行 kubernetes 操作员控制器的指标

php editor Yuzai introduced: When using the kubernetes operator controller, we sometimes encounter the situation of deleting indicators that cannot be run. This can lead to runtime errors and inconsistencies. To resolve this issue, we need to take some steps to remove these non-functioning indicators. This article will provide detailed solutions to help you successfully delete unrunning kubernetes operator controller metrics. Let’s take a look!

Question content

I have been working on my operator where I have some custom indicators setting values ​​and it works fine (registering and displaying indicator values). The problem is that indicator deletion is not happening. I tried to declare a separate function to remove the indicator.

My operator is starting a stateful set and service, but after deleting my cr, the subresources are deleted but the metrics don't get any updates/removals.

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 declaring the predicate using deletefunc but without success, my indicator still cannot be deleted.

Thanks for any help or pointers.

Solution

I was able to implement this functionality, deleting the indicator simply uses the delete function to call the custom indicator based on the completed resource operation.

FYI, it is possible to call delete on a custom indicator, you can call the function after completing the work on the custom resource.

https://pkg.go.dev/github .com/prometheus/client_golang/prometheus#MetricVec.DeleteLabelValues

The above is the detailed content of Remove metric unable to run kubernetes operator controller. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete