Skip to content

Commit

Permalink
metrics: initialize metrics for several existing metrics.
Browse files Browse the repository at this point in the history
Using previous commits, initializes metrics to zero for various existing metrics.

Signed-off-by: Tom Hadlaw <[email protected]>
  • Loading branch information
tommyp1ckles authored and lmb committed Nov 21, 2023
1 parent 6659745 commit 245f634
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 12 deletions.
2 changes: 2 additions & 0 deletions pkg/metrics/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ func NewValues(vs ...string) Values {
return vals
}

// Labels is a slice of labels that represents a label set for a vector type
// metric.
type Labels []Label

func (lbls Labels) labelNames() []string {
Expand Down
102 changes: 90 additions & 12 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cilium/cilium/api/v1/models"
"github.com/cilium/cilium/pkg/metrics/metric"
"github.com/cilium/cilium/pkg/promise"
"github.com/cilium/cilium/pkg/source"
"github.com/cilium/cilium/pkg/time"
"github.com/cilium/cilium/pkg/version"
)
Expand Down Expand Up @@ -96,12 +97,22 @@ const (

// Labels

// LabelValueFalse is the string value for true metric label values.
LabelValueTrue = "true"

// LabelValueFalse is the string value for false metric label values.
LabelValueFalse = "false"

// LabelValueOutcomeSuccess is used as a successful outcome of an operation
LabelValueOutcomeSuccess = "success"

// LabelValueOutcomeFail is used as an unsuccessful outcome of an operation
LabelValueOutcomeFail = "fail"

// LabelValueOutcomeFailure is used as an unsuccessful outcome of an operation.
// NOTE: This should only be used for existing metrics, new metrics should use LabelValueOutcomeFail.
LabelValueOutcomeFailure = "failure"

// LabelDropReason is used to describe reason for dropping a packets/bytes
LabelDropReason = "reason"

Expand Down Expand Up @@ -145,6 +156,8 @@ const (
// LabelPolicySource is the label used to see the enforcement status
LabelPolicySource = "source"

LabelSource = "source"

// LabelScope is the label used to defined multiples scopes in the same
// metric. For example, one counter may measure a metric over the scope of
// the entire event (scope=global), or just part of an event
Expand Down Expand Up @@ -224,6 +237,12 @@ const (
LabelLocationRemoteIntraCluster = "remote_intra_cluster"
LabelLocationRemoteInterCluster = "remote_inter_cluster"

// Rule label is a label for a L7 rule name.
LabelL7Rule = "rule"

// LabelL7ProxyType is the label for denoting a L7 proxy type.
LabelL7ProxyType = "proxy_type"

// LabelType is the label for type in general (e.g. endpoint, node)
LabelType = "type"
LabelPeerEndpoint = "endpoint"
Expand All @@ -238,6 +257,9 @@ const (
)

var (
// LabelValuesBool is metric label value set for boolean type.
LabelValuesBool = metric.NewValues(LabelValueTrue, LabelValueFalse)

// Namespace is used to scope metrics from cilium. It is prepended to metric
// names and separated with a '_'
Namespace = CiliumAgentNamespace
Expand Down Expand Up @@ -718,13 +740,18 @@ func NewLegacyMetrics() *LegacyMetrics {
Help: "Duration of processed API calls labeled by path, method and return code.",
}, []string{LabelPath, LabelMethod, LabelAPIReturnCode}),

EndpointRegenerationTotal: metric.NewCounterVec(metric.CounterOpts{
EndpointRegenerationTotal: metric.NewCounterVecWithLabels(metric.CounterOpts{
ConfigName: Namespace + "_endpoint_regenerations_total",

Namespace: Namespace,
Name: "endpoint_regenerations_total",
Help: "Count of all endpoint regenerations that have completed, tagged by outcome",
}, []string{"outcome"}),
}, metric.Labels{
{
Name: LabelOutcome,
Values: metric.NewValues(LabelValueOutcomeSuccess, LabelValueOutcomeFailure),
},
}),

EndpointStateCount: metric.NewGaugeVec(metric.GaugeOpts{
ConfigName: Namespace + "_endpoint_state",
Expand Down Expand Up @@ -771,13 +798,18 @@ func NewLegacyMetrics() *LegacyMetrics {
Help: "Highest policy revision number in the agent",
}),

PolicyChangeTotal: metric.NewCounterVec(metric.CounterOpts{
PolicyChangeTotal: metric.NewCounterVecWithLabels(metric.CounterOpts{
ConfigName: Namespace + "_policy_change_total",

Namespace: Namespace,
Name: "policy_change_total",
Help: "Number of policy changes by outcome",
}, []string{"outcome"}),
}, metric.Labels{
{
Name: LabelOutcome,
Values: metric.NewValues(LabelValueOutcomeSuccess, LabelValueOutcomeFailure),
},
}),

PolicyEndpointStatus: metric.NewGaugeVec(metric.GaugeOpts{
ConfigName: Namespace + "_policy_endpoint_enforcement_status",
Expand All @@ -787,13 +819,18 @@ func NewLegacyMetrics() *LegacyMetrics {
Help: "Number of endpoints labeled by policy enforcement status",
}, []string{LabelPolicyEnforcement}),

PolicyImplementationDelay: metric.NewHistogramVec(metric.HistogramOpts{
PolicyImplementationDelay: metric.NewHistogramVecWithLabels(metric.HistogramOpts{
ConfigName: Namespace + "_policy_implementation_delay",

Namespace: Namespace,
Name: "policy_implementation_delay",
Help: "Time between a policy change and it being fully deployed into the datapath",
}, []string{LabelPolicySource}),
}, metric.Labels{
{
Name: LabelPolicySource,
Values: metric.NewValues(string(source.Kubernetes), string(source.CustomResource), string(source.LocalAPI)),
},
}),

CIDRGroupsReferenced: metric.NewGauge(metric.GaugeOpts{
ConfigName: Namespace + "cidrgroups_referenced",
Expand Down Expand Up @@ -844,12 +881,21 @@ func NewLegacyMetrics() *LegacyMetrics {
Help: "Number of redirects installed for endpoints, labeled by protocol",
}, []string{LabelProtocolL7}),

ProxyPolicyL7Total: metric.NewCounterVec(metric.CounterOpts{
ProxyPolicyL7Total: metric.NewCounterVecWithLabels(metric.CounterOpts{
ConfigName: Namespace + "_policy_l7_total",
Namespace: Namespace,
Name: "policy_l7_total",
Help: "Number of total proxy requests handled",
}, []string{"rule", "proxy_type"}),
}, metric.Labels{
{
Name: LabelL7Rule,
Values: metric.NewValues("received", "forwarded", "denied", "parse_errors"),
},
{
Name: LabelL7ProxyType,
Values: metric.NewValues("fqdn", "envoy"),
},
}),

ProxyUpstreamTime: metric.NewHistogramVec(metric.HistogramOpts{
ConfigName: Namespace + "_proxy_upstream_reply_seconds",
Expand Down Expand Up @@ -965,19 +1011,51 @@ func NewLegacyMetrics() *LegacyMetrics {
Help: "Number of times that Cilium has started a subprocess, labeled by subsystem",
}, []string{LabelSubsystem}),

KubernetesEventProcessed: metric.NewCounterVec(metric.CounterOpts{
KubernetesEventProcessed: metric.NewCounterVecWithLabels(metric.CounterOpts{
ConfigName: Namespace + "_kubernetes_events_total",
Namespace: Namespace,
Name: "kubernetes_events_total",
Help: "Number of Kubernetes events processed labeled by scope, action and execution result",
}, []string{LabelScope, LabelAction, LabelStatus}),
},
metric.Labels{
{
Name: LabelScope,
Values: metric.NewValues("CiliumNetworkPolicy", "CiliumClusterwideNetworkPolicy", "NetworkPolicy"),
},
{
Name: LabelAction,
Values: metric.NewValues("update", "delete"),
},
{
Name: LabelStatus,
Values: metric.NewValues("success", "failed"),
},
},
),

KubernetesEventReceived: metric.NewCounterVec(metric.CounterOpts{
KubernetesEventReceived: metric.NewCounterVecWithLabels(metric.CounterOpts{
ConfigName: Namespace + "_kubernetes_events_received_total",
Namespace: Namespace,
Name: "kubernetes_events_received_total",
Help: "Number of Kubernetes events received labeled by scope, action, valid data and equalness",
}, []string{LabelScope, LabelAction, "valid", "equal"}),
}, metric.Labels{
{
Name: LabelScope,
Values: metric.NewValues("CiliumNetworkPolicy", "CiliumClusterwideNetworkPolicy", "NetworkPolicy"),
},
{
Name: LabelAction,
Values: metric.NewValues("update", "delete"),
},
{
Name: "valid",
Values: LabelValuesBool,
},
{
Name: "equal",
Values: LabelValuesBool,
},
}),

KubernetesAPIInteractions: metric.NewHistogramVec(metric.HistogramOpts{
ConfigName: Namespace + "_" + SubsystemK8sClient + "_api_latency_time_seconds",
Expand Down

0 comments on commit 245f634

Please sign in to comment.