Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions pkg/apiproxy/ytsaurus.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (

ytv1 "github.com/ytsaurus/ytsaurus-k8s-operator/api/v1"
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/consts"
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/labeller"
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/metrics"
)

type Ytsaurus struct {
Expand Down Expand Up @@ -202,23 +204,21 @@ func buildComponentsSummary(components []ytv1.Component) string {
}
var componentNames []string
for _, comp := range components {
// TODO: we better use labeller here after support deployment names in it.
name := getComponentName(comp)
name := getLabelerComponentName(comp)
componentNames = append(componentNames, name)
}
return "{" + strings.Join(componentNames, " ") + "}"
}

func getComponentName(component ytv1.Component) string {
// TODO: we better use labeller here after support deployment names in it.
name := consts.GetShortName(component.Type)
if name == "" {
name = strings.ToLower(string(component.Type))
}
if component.Name != "" {
name += fmt.Sprintf("-%s", component.Name)
}
return name
func getComponentLabeler(component ytv1.Component) *labeller.Labeller {
l := (&labeller.Labeller{}).ForComponent(component.Type, component.Name)
return l
}

func getLabelerComponentName(component ytv1.Component) string {
l := getComponentLabeler(component)
l.UseShortNames = true
return l.GetComponentShortName()
}

// UpdateOnDeleteComponentsSummary updates the UpdatingComponentsSummary with waiting time information
Expand All @@ -235,14 +235,16 @@ func (c *Ytsaurus) UpdateOnDeleteComponentsSummary(ctx context.Context, waitingO
condition := meta.FindStatusCondition(c.GetResource().Status.UpdateStatus.Conditions, waitingOnDeleteConditionType)

if condition != nil && condition.Status == "True" {
componentName := getComponentName(component)
componentName := getLabelerComponentName(component)
if includeWaitinDuration {
waitingDuration := time.Since(condition.LastTransitionTime.Time)
summaryParts = append(summaryParts, fmt.Sprintf("{%s (waiting %s)}",
componentName,
waitingDuration.Truncate(time.Second).String()))
metrics.ObserveOnDeleteWait(c.GetResource().Name, c.GetResource().Namespace, componentName, &condition.LastTransitionTime)
} else {
summaryParts = append(summaryParts, fmt.Sprintf("{%s}", componentName))
metrics.ObserveOnDeleteWait(c.GetResource().Name, c.GetResource().Namespace, componentName, nil)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/labeller/labeller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (l *Labeller) GetInstanceGroup() string {
return l.InstanceGroup
}

func (l *Labeller) GetComponentShortName() string {
return l.getName(consts.GetShortName(l.ComponentType), "")
}

func (l *Labeller) GetServerStatefulSetName() string {
return l.getName(consts.ComponentStatefulSetPrefix(l.ComponentType), "")
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/metrics/update_strategy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package metrics

import (
"time"

"github.com/prometheus/client_golang/prometheus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"
)

//nolint:gochecknoglobals // Prometheus metrics are package-level for registration and reuse.
var strategyOnDeleteWatingTimeSeconds = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "ytop",
Subsystem: "strategy_on_delete",
Name: "waiting_time_seconds",
Help: "Seconds a component has been waiting in OnDelete mode since the mode started.",
},
[]string{"cluster", "cluster_namespace", "component_name"},
)

func init() {
ctrlmetrics.Registry.MustRegister(strategyOnDeleteWatingTimeSeconds)
}

func ObserveOnDeleteWait(cluster, cluster_namespace, component_name string, startedAt *metav1.Time) {
lbl := []string{cluster, cluster_namespace, component_name}
if startedAt == nil || startedAt.IsZero() {
strategyOnDeleteWatingTimeSeconds.DeleteLabelValues(lbl...)
return
}
strategyOnDeleteWatingTimeSeconds.WithLabelValues(lbl...).Set(time.Since(startedAt.Time).Seconds())
}
Loading