syself / cluster-api-provider-hetzner

Cluster API Provider Hetzner :rocket: The best way to manage Kubernetes clusters on Hetzner, fully declarative, Kubernetes-native and with self-healing capabilities
https://caph.syself.com
Apache License 2.0
619 stars 58 forks source link

:seedling: added --debug-hcloud-api-calls #1332

Closed guettli closed 3 months ago

guettli commented 3 months ago

What this PR does / why we need it:

Sometimes we want to see all calls to the hcloud api (to debug rate-limiting issues).

You can test the client on its own with this file in a new directory:

package main

import (
    "context"
    "fmt"
    "log/slog"
    "os"

    "github.com/go-logr/logr"
    hcloudclient "github.com/syself/cluster-api-provider-hetzner/pkg/services/hcloud/client"
)

func main() {
    c := hcloudclient.NewFactory().NewClient(os.Getenv("HCLOUD_TOKEN"))
    fmt.Println(c.ListServerTypes(logr.NewContextWithSlogLogger(context.Background(), slog.New(slog.NewTextHandler(os.Stdout, nil)))))
}

above code is for checking our logs.

Now checking that we did not break the metrics:

❯ k -n caph-system port-forward caph-controller-manager-5b68dcd5c9-jmngs 8080:8080
❯ curl http://localhost:8080/metrics > metrics.json

metrics.json

guettli commented 3 months ago

@janiskemper I extracted the "WithEventFilter" related changes to the new PR: https://github.com/syself/cluster-api-provider-hetzner/pull/1355/files