Skip to content

Commit 7077874

Browse files
vmprobe: support service and pod
1 parent fcb9e74 commit 7077874

File tree

13 files changed

+856
-249
lines changed

13 files changed

+856
-249
lines changed

api/operator/v1beta1/vmprobe_types.go

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ func (cr *VMProbeSpec) UnmarshalJSON(src []byte) error {
6767
type VMProbeTargets struct {
6868
// StaticConfig defines static targets which are considers for probing.
6969
StaticConfig *VMProbeTargetStaticConfig `json:"staticConfig,omitempty"`
70-
// Ingress defines the set of dynamically discovered ingress objects which hosts are considered for probing.
71-
Ingress *ProbeTargetIngress `json:"ingress,omitempty"`
70+
// K8s defines k8s targets, which are considered for probing.
71+
K8s []*VMProbeTargetK8s `json:"k8s,omitempty"`
72+
// Ingress defines the set of dynamically discovered Ingress objects which hosts are considered for probing.
73+
// Deprecated: use k8s configs instead
74+
Ingress *VMProbeTargetK8s `json:"ingress,omitempty"`
7275
}
7376

7477
// VMProbeTargetStaticConfig defines the set of static targets considered for probing.
@@ -82,17 +85,33 @@ type VMProbeTargetStaticConfig struct {
8285
RelabelConfigs []*RelabelConfig `json:"relabelingConfigs,omitempty"`
8386
}
8487

85-
// ProbeTargetIngress defines the set of Ingress objects considered for probing.
88+
// VMProbeTargetK8s defines the set of k8s objects considered for probing.
8689
// +k8s:openapi-gen=true
87-
type ProbeTargetIngress struct {
88-
// Select Ingress objects by labels.
90+
type VMProbeTargetK8s struct {
91+
// Role defines k8s role name
92+
// +kubebuilder:validation:Enum=service;ingress;pod
93+
Role string `json:"role,omitempty"`
94+
// Select k8s objects by labels.
8995
Selector metav1.LabelSelector `json:"selector,omitempty"`
90-
// Select Ingress objects by namespace.
96+
// Select k8s objects by namespace.
9197
NamespaceSelector NamespaceSelector `json:"namespaceSelector,omitempty"`
9298
// RelabelConfigs to apply to samples during service discovery.
9399
RelabelConfigs []*RelabelConfig `json:"relabelingConfigs,omitempty"`
94100
}
95101

102+
func (t *VMProbeTargetK8s) validate(prefix string) error {
103+
if t == nil {
104+
return nil
105+
}
106+
if _, err := metav1.LabelSelectorAsSelector(&t.Selector); err != nil {
107+
return fmt.Errorf("invalid %s.selector: %w", prefix, err)
108+
}
109+
if err := checkRelabelConfigs(t.RelabelConfigs); err != nil {
110+
return fmt.Errorf("invalid %s.relabelingConfigs: %w", prefix, err)
111+
}
112+
return nil
113+
}
114+
96115
// VMProberSpec contains specification parameters for the Prober used for probing.
97116
// +k8s:openapi-gen=true
98117
type VMProberSpec struct {
@@ -154,15 +173,15 @@ func (cr *VMProbe) Validate() error {
154173
if err := checkRelabelConfigs(cr.Spec.MetricRelabelConfigs); err != nil {
155174
return fmt.Errorf("invalid metricRelabelConfigs: %w", err)
156175
}
157-
switch {
158-
case cr.Spec.Targets.Ingress != nil:
159-
if _, err := metav1.LabelSelectorAsSelector(&cr.Spec.Targets.Ingress.Selector); err != nil {
160-
return fmt.Errorf("invalid spec.targets.ingress.selector syntax: %w", err)
161-
}
162-
if err := checkRelabelConfigs(cr.Spec.Targets.Ingress.RelabelConfigs); err != nil {
163-
return fmt.Errorf("invalid ingress.relabelingConfigs: %w", err)
176+
for i, t := range cr.Spec.Targets.K8s {
177+
if err := t.validate(fmt.Sprintf("spec.targets.k8s[%d]", i)); err != nil {
178+
return err
164179
}
165-
case cr.Spec.Targets.StaticConfig != nil:
180+
}
181+
if err := cr.Spec.Targets.Ingress.validate("spec.targets.ingress"); err != nil {
182+
return err
183+
}
184+
if cr.Spec.Targets.StaticConfig != nil {
166185
if err := checkRelabelConfigs(cr.Spec.Targets.StaticConfig.RelabelConfigs); err != nil {
167186
return fmt.Errorf("invalid staticConfig.relabelingConfigs: %w", err)
168187
}

api/operator/v1beta1/zz_generated.deepcopy.go

Lines changed: 40 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/overlay/crd.yaml

Lines changed: 165 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34002,11 +34002,12 @@ spec:
3400234002
targets to be probed using the prober.
3400334003
properties:
3400434004
ingress:
34005-
description: Ingress defines the set of dynamically discovered
34006-
ingress objects which hosts are considered for probing.
34005+
description: |-
34006+
Ingress defines the set of dynamically discovered Ingress objects which hosts are considered for probing.
34007+
Deprecated: use k8s configs instead
3400734008
properties:
3400834009
namespaceSelector:
34009-
description: Select Ingress objects by namespace.
34010+
description: Select k8s objects by namespace.
3401034011
properties:
3401134012
any:
3401234013
description: |-
@@ -34096,8 +34097,15 @@ spec:
3409634097
type: string
3409734098
type: object
3409834099
type: array
34100+
role:
34101+
description: Role defines k8s role name
34102+
enum:
34103+
- service
34104+
- ingress
34105+
- pod
34106+
type: string
3409934107
selector:
34100-
description: Select Ingress objects by labels.
34108+
description: Select k8s objects by labels.
3410134109
properties:
3410234110
matchExpressions:
3410334111
description: matchExpressions is a list of label selector
@@ -34143,6 +34151,159 @@ spec:
3414334151
type: object
3414434152
x-kubernetes-map-type: atomic
3414534153
type: object
34154+
k8s:
34155+
description: K8s defines k8s targets, which are considered for
34156+
probing.
34157+
items:
34158+
description: VMProbeTargetK8s defines the set of k8s objects
34159+
considered for probing.
34160+
properties:
34161+
namespaceSelector:
34162+
description: Select k8s objects by namespace.
34163+
properties:
34164+
any:
34165+
description: |-
34166+
Boolean describing whether all namespaces are selected in contrast to a
34167+
list restricting them.
34168+
type: boolean
34169+
matchNames:
34170+
description: List of namespace names.
34171+
items:
34172+
type: string
34173+
type: array
34174+
type: object
34175+
relabelingConfigs:
34176+
description: RelabelConfigs to apply to samples during service
34177+
discovery.
34178+
items:
34179+
description: |-
34180+
RelabelConfig allows dynamic rewriting of the label set
34181+
More info: https://docs.victoriametrics.com/victoriametrics/#relabeling
34182+
properties:
34183+
action:
34184+
description: Action to perform based on regex matching.
34185+
Default is 'replace'
34186+
type: string
34187+
if:
34188+
description: 'If represents metricsQL match expression
34189+
(or list of expressions): ''{__name__=~"foo_.*"}'''
34190+
x-kubernetes-preserve-unknown-fields: true
34191+
labels:
34192+
additionalProperties:
34193+
type: string
34194+
description: 'Labels is used together with Match for
34195+
`action: graphite`'
34196+
type: object
34197+
match:
34198+
description: 'Match is used together with Labels for
34199+
`action: graphite`'
34200+
type: string
34201+
modulus:
34202+
description: Modulus to take of the hash of the source
34203+
label values.
34204+
format: int64
34205+
type: integer
34206+
regex:
34207+
description: |-
34208+
Regular expression against which the extracted value is matched. Default is '(.*)'
34209+
victoriaMetrics supports multiline regex joined with |
34210+
https://docs.victoriametrics.com/victoriametrics/vmagent/#relabeling-enhancements
34211+
x-kubernetes-preserve-unknown-fields: true
34212+
replacement:
34213+
description: |-
34214+
Replacement value against which a regex replace is performed if the
34215+
regular expression matches. Regex capture groups are available. Default is '$1'
34216+
type: string
34217+
separator:
34218+
description: Separator placed between concatenated
34219+
source label values. default is ';'.
34220+
type: string
34221+
source_labels:
34222+
description: |-
34223+
UnderScoreSourceLabels - additional form of source labels source_labels
34224+
for compatibility with original relabel config.
34225+
if set both sourceLabels and source_labels, sourceLabels has priority.
34226+
for details https://github.com/VictoriaMetrics/operator/issues/131
34227+
items:
34228+
type: string
34229+
type: array
34230+
sourceLabels:
34231+
description: |-
34232+
The source labels select values from existing labels. Their content is concatenated
34233+
using the configured separator and matched against the configured regular expression
34234+
for the replace, keep, and drop actions.
34235+
items:
34236+
type: string
34237+
type: array
34238+
target_label:
34239+
description: |-
34240+
UnderScoreTargetLabel - additional form of target label - target_label
34241+
for compatibility with original relabel config.
34242+
if set both targetLabel and target_label, targetLabel has priority.
34243+
for details https://github.com/VictoriaMetrics/operator/issues/131
34244+
type: string
34245+
targetLabel:
34246+
description: |-
34247+
Label to which the resulting value is written in a replace action.
34248+
It is mandatory for replace actions. Regex capture groups are available.
34249+
type: string
34250+
type: object
34251+
type: array
34252+
role:
34253+
description: Role defines k8s role name
34254+
enum:
34255+
- service
34256+
- ingress
34257+
- pod
34258+
type: string
34259+
selector:
34260+
description: Select k8s objects by labels.
34261+
properties:
34262+
matchExpressions:
34263+
description: matchExpressions is a list of label selector
34264+
requirements. The requirements are ANDed.
34265+
items:
34266+
description: |-
34267+
A label selector requirement is a selector that contains values, a key, and an operator that
34268+
relates the key and values.
34269+
properties:
34270+
key:
34271+
description: key is the label key that the selector
34272+
applies to.
34273+
type: string
34274+
operator:
34275+
description: |-
34276+
operator represents a key's relationship to a set of values.
34277+
Valid operators are In, NotIn, Exists and DoesNotExist.
34278+
type: string
34279+
values:
34280+
description: |-
34281+
values is an array of string values. If the operator is In or NotIn,
34282+
the values array must be non-empty. If the operator is Exists or DoesNotExist,
34283+
the values array must be empty. This array is replaced during a strategic
34284+
merge patch.
34285+
items:
34286+
type: string
34287+
type: array
34288+
x-kubernetes-list-type: atomic
34289+
required:
34290+
- key
34291+
- operator
34292+
type: object
34293+
type: array
34294+
x-kubernetes-list-type: atomic
34295+
matchLabels:
34296+
additionalProperties:
34297+
type: string
34298+
description: |-
34299+
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
34300+
map is equivalent to an element of matchExpressions, whose key field is "key", the
34301+
operator is "In", and the values array contains only "value". The requirements are ANDed.
34302+
type: object
34303+
type: object
34304+
x-kubernetes-map-type: atomic
34305+
type: object
34306+
type: array
3414634307
staticConfig:
3414734308
description: StaticConfig defines static targets which are considers
3414834309
for probing.

config/examples/vmprobe-k8s.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: operator.victoriametrics.com/v1beta1
2+
kind: VMProbe
3+
metadata:
4+
name: k8s-probe
5+
spec:
6+
jobName: k8s-probe
7+
vmProberSpec:
8+
# by default scheme http, and path is /probe
9+
url: prometheus-blackbox-exporter.default.svc:9115
10+
module: http_2xx
11+
targets:
12+
k8s:
13+
- role: ingress
14+
selector:
15+
matchLabels:
16+
app: victoria-metrics-single
17+
- role: service
18+
selector:
19+
matchLabels:
20+
app: victoria-metrics-agent
21+
interval: 2s

0 commit comments

Comments
 (0)