1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 03:38:43 +00:00

feat: Support portNumber in addition of port name for PodMonitor CRD ()

---------

Signed-off-by: dongjiang <dongjiang1989@126.com>
This commit is contained in:
dongjiang 2024-11-29 21:12:17 +08:00 committed by GitHub
parent bb4514e0d5
commit 20cc1a0125
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 426 additions and 51 deletions

19
Documentation/api.md generated
View file

@ -10235,8 +10235,21 @@ string
</em>
</td>
<td>
<p>Name of the Pod port which this endpoint refers to.</p>
<p>It takes precedence over <code>targetPort</code>.</p>
<em>(Optional)</em>
<p>The <code>Pod</code> port name which exposes the endpoint.</p>
<p>It takes precedence over the <code>portNumber</code> and <code>targetPort</code> fields.</p>
</td>
</tr>
<tr>
<td>
<code>portNumber</code><br/>
<em>
int32
</em>
</td>
<td>
<em>(Optional)</em>
<p>The <code>Pod</code> port number which exposes the endpoint.</p>
</td>
</tr>
<tr>
@ -10251,7 +10264,7 @@ k8s.io/apimachinery/pkg/util/intstr.IntOrString
<td>
<p>Name or number of the target port of the <code>Pod</code> object behind the Service, the
port must be specified with container port property.</p>
<p>Deprecated: use &lsquo;port&rsquo; instead.</p>
<p>Deprecated: use &lsquo;port&rsquo; or &lsquo;portNumber&rsquo; instead.</p>
</td>
</tr>
<tr>

12
bundle.yaml generated
View file

@ -19434,10 +19434,16 @@ spec:
type: string
port:
description: |-
Name of the Pod port which this endpoint refers to.
The `Pod` port name which exposes the endpoint.
It takes precedence over `targetPort`.
It takes precedence over the `portNumber` and `targetPort` fields.
type: string
portNumber:
description: The `Pod` port number which exposes the endpoint.
format: int32
maximum: 65535
minimum: 1
type: integer
proxyUrl:
description: |-
`proxyURL` configures the HTTP Proxy URL (e.g.
@ -19566,7 +19572,7 @@ spec:
Name or number of the target port of the `Pod` object behind the Service, the
port must be specified with container port property.
Deprecated: use 'port' instead.
Deprecated: use 'port' or 'portNumber' instead.
x-kubernetes-int-or-string: true
tlsConfig:
description: TLS configuration to use when scraping the target.

View file

@ -758,10 +758,16 @@ spec:
type: string
port:
description: |-
Name of the Pod port which this endpoint refers to.
The `Pod` port name which exposes the endpoint.
It takes precedence over `targetPort`.
It takes precedence over the `portNumber` and `targetPort` fields.
type: string
portNumber:
description: The `Pod` port number which exposes the endpoint.
format: int32
maximum: 65535
minimum: 1
type: integer
proxyUrl:
description: |-
`proxyURL` configures the HTTP Proxy URL (e.g.
@ -890,7 +896,7 @@ spec:
Name or number of the target port of the `Pod` object behind the Service, the
port must be specified with container port property.
Deprecated: use 'port' instead.
Deprecated: use 'port' or 'portNumber' instead.
x-kubernetes-int-or-string: true
tlsConfig:
description: TLS configuration to use when scraping the target.

View file

@ -759,10 +759,16 @@ spec:
type: string
port:
description: |-
Name of the Pod port which this endpoint refers to.
The `Pod` port name which exposes the endpoint.
It takes precedence over `targetPort`.
It takes precedence over the `portNumber` and `targetPort` fields.
type: string
portNumber:
description: The `Pod` port number which exposes the endpoint.
format: int32
maximum: 65535
minimum: 1
type: integer
proxyUrl:
description: |-
`proxyURL` configures the HTTP Proxy URL (e.g.
@ -891,7 +897,7 @@ spec:
Name or number of the target port of the `Pod` object behind the Service, the
port must be specified with container port property.
Deprecated: use 'port' instead.
Deprecated: use 'port' or 'portNumber' instead.
x-kubernetes-int-or-string: true
tlsConfig:
description: TLS configuration to use when scraping the target.

View file

@ -650,9 +650,16 @@
"type": "string"
},
"port": {
"description": "Name of the Pod port which this endpoint refers to.\n\nIt takes precedence over `targetPort`.",
"description": "The `Pod` port name which exposes the endpoint.\n\nIt takes precedence over the `portNumber` and `targetPort` fields.",
"type": "string"
},
"portNumber": {
"description": "The `Pod` port number which exposes the endpoint.",
"format": "int32",
"maximum": 65535,
"minimum": 1,
"type": "integer"
},
"proxyUrl": {
"description": "`proxyURL` configures the HTTP Proxy URL (e.g.\n\"http://proxyserver:2195\") to go through when scraping the target.",
"type": "string"
@ -748,7 +755,7 @@
"type": "string"
}
],
"description": "Name or number of the target port of the `Pod` object behind the Service, the\nport must be specified with container port property.\n\nDeprecated: use 'port' instead.",
"description": "Name or number of the target port of the `Pod` object behind the Service, the\nport must be specified with container port property.\n\nDeprecated: use 'port' or 'portNumber' instead.",
"x-kubernetes-int-or-string": true
},
"tlsConfig": {

View file

@ -183,15 +183,22 @@ func (l *PodMonitorList) DeepCopyObject() runtime.Object {
//
// +k8s:openapi-gen=true
type PodMetricsEndpoint struct {
// Name of the Pod port which this endpoint refers to.
// The `Pod` port name which exposes the endpoint.
//
// It takes precedence over `targetPort`.
Port string `json:"port,omitempty"`
// It takes precedence over the `portNumber` and `targetPort` fields.
// +optional
Port *string `json:"port,omitempty"`
// The `Pod` port number which exposes the endpoint.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
// +optional
PortNumber *int32 `json:"portNumber,omitempty"`
// Name or number of the target port of the `Pod` object behind the Service, the
// port must be specified with container port property.
//
// Deprecated: use 'port' instead.
// Deprecated: use 'port' or 'portNumber' instead.
TargetPort *intstr.IntOrString `json:"targetPort,omitempty"`
// HTTP path from which to scrape for metrics.

View file

@ -36,7 +36,7 @@ func TestMarshallPodMonitor(t *testing.T) {
},
PodMetricsEndpoints: []PodMetricsEndpoint{
{
Port: "metric",
Port: func(v string) *string { return &v }("metric"),
},
},
},

View file

@ -1641,6 +1641,16 @@ func (in *PodDNSConfigOption) DeepCopy() *PodDNSConfigOption {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *PodMetricsEndpoint) DeepCopyInto(out *PodMetricsEndpoint) {
*out = *in
if in.Port != nil {
in, out := &in.Port, &out.Port
*out = new(string)
**out = **in
}
if in.PortNumber != nil {
in, out := &in.PortNumber, &out.PortNumber
*out = new(int32)
**out = **in
}
if in.TargetPort != nil {
in, out := &in.TargetPort, &out.TargetPort
*out = new(intstr.IntOrString)

View file

@ -26,6 +26,7 @@ import (
// with apply.
type PodMetricsEndpointApplyConfiguration struct {
Port *string `json:"port,omitempty"`
PortNumber *int32 `json:"portNumber,omitempty"`
TargetPort *intstr.IntOrString `json:"targetPort,omitempty"`
Path *string `json:"path,omitempty"`
Scheme *string `json:"scheme,omitempty"`
@ -62,6 +63,14 @@ func (b *PodMetricsEndpointApplyConfiguration) WithPort(value string) *PodMetric
return b
}
// WithPortNumber sets the PortNumber field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the PortNumber field is set to the value of the last call.
func (b *PodMetricsEndpointApplyConfiguration) WithPortNumber(value int32) *PodMetricsEndpointApplyConfiguration {
b.PortNumber = &value
return b
}
// WithTargetPort sets the TargetPort field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the TargetPort field is set to the value of the last call.

View file

@ -1280,14 +1280,20 @@ func (cg *ConfigGenerator) generatePodMonitorConfig(
}
// Filter targets based on correct port for the endpoint.
if ep.Port != "" {
if ptr.Deref(ep.Port, "") != "" {
relabelings = append(relabelings, yaml.MapSlice{
{Key: "action", Value: "keep"},
{Key: "source_labels", Value: []string{"__meta_kubernetes_pod_container_port_name"}},
{Key: "regex", Value: ep.Port},
{Key: "regex", Value: *ep.Port},
})
} else if ptr.Deref(ep.PortNumber, 0) != 0 {
relabelings = append(relabelings, yaml.MapSlice{
{Key: "action", Value: "keep"},
{Key: "source_labels", Value: []string{"__meta_kubernetes_pod_container_port_number"}},
{Key: "regex", Value: *ep.PortNumber},
})
} else if ep.TargetPort != nil { //nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
cg.logger.Warn("'targetPort' is deprecated, use 'port' instead.")
cg.logger.Warn("'targetPort' is deprecated, use 'port' or 'portNumber' instead.")
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
if ep.TargetPort.StrVal != "" {
relabelings = append(relabelings, yaml.MapSlice{
@ -1299,7 +1305,7 @@ func (cg *ConfigGenerator) generatePodMonitorConfig(
relabelings = append(relabelings, yaml.MapSlice{
{Key: "action", Value: "keep"},
{Key: "source_labels", Value: []string{"__meta_kubernetes_pod_container_port_number"}},
{Key: "regex", Value: ep.TargetPort.String()},
{Key: "regex", Value: ep.TargetPort.IntValue()},
})
}
}
@ -1350,10 +1356,10 @@ func (cg *ConfigGenerator) generatePodMonitorConfig(
})
}
if ep.Port != "" {
if ptr.Deref(ep.Port, "") != "" {
relabelings = append(relabelings, yaml.MapSlice{
{Key: "target_label", Value: "endpoint"},
{Key: "replacement", Value: ep.Port},
{Key: "replacement", Value: *ep.Port},
})
} else if ep.TargetPort != nil && ep.TargetPort.String() != "" { //nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
relabelings = append(relabelings, yaml.MapSlice{
@ -1785,7 +1791,7 @@ func (cg *ConfigGenerator) generateServiceMonitorConfig(
relabelings = append(relabelings, yaml.MapSlice{
{Key: "action", Value: "keep"},
{Key: "source_labels", Value: []string{"__meta_kubernetes_pod_container_port_number"}},
{Key: "regex", Value: ep.TargetPort.String()},
{Key: "regex", Value: ep.TargetPort.IntValue()},
})
}
}

View file

@ -1720,7 +1720,7 @@ func TestEnforcedNamespaceLabelPodMonitor(t *testing.T) {
PodTargetLabels: []string{"example", "env"},
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
MetricRelabelConfigs: []monitoringv1.RelabelConfig{
{
@ -1787,7 +1787,7 @@ func TestEnforcedNamespaceLabelOnExcludedPodMonitor(t *testing.T) {
PodTargetLabels: []string{"example", "env"},
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
MetricRelabelConfigs: []monitoringv1.RelabelConfig{
{
@ -2045,7 +2045,7 @@ func TestSettingHonorTimestampsInPodMonitor(t *testing.T) {
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
HonorTimestamps: ptr.To(false),
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
},
},
@ -2119,7 +2119,7 @@ func TestSettingTrackTimestampsStalenessInPodMonitor(t *testing.T) {
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
TrackTimestampsStaleness: ptr.To(false),
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
},
},
@ -2312,7 +2312,7 @@ func TestSettingScrapeProtocolsInPodMonitor(t *testing.T) {
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
TrackTimestampsStaleness: ptr.To(false),
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
},
},
@ -2373,7 +2373,7 @@ func TestSettingScrapeFallbackProtocolInPodMonitor(t *testing.T) {
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
TrackTimestampsStaleness: ptr.To(false),
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
},
},
@ -2686,7 +2686,7 @@ func TestEndpointOAuth2(t *testing.T) {
Spec: monitoringv1.PodMonitorSpec{
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
OAuth2: &oauth2,
},
},
@ -2803,7 +2803,7 @@ func TestPodTargetLabelsFromPodMonitor(t *testing.T) {
PodTargetLabels: []string{"example", "env"},
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
},
},
@ -2843,7 +2843,7 @@ func TestPodTargetLabelsFromPodMonitorAndGlobal(t *testing.T) {
PodTargetLabels: []string{"local"},
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
},
},
@ -3143,7 +3143,7 @@ func makePodMonitors() map[string]*monitoringv1.PodMonitor {
},
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
},
},
@ -3167,7 +3167,7 @@ func makePodMonitors() map[string]*monitoringv1.PodMonitor {
},
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
},
},
@ -3191,7 +3191,7 @@ func makePodMonitors() map[string]*monitoringv1.PodMonitor {
},
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
Path: "/federate",
Params: map[string][]string{"metrics[]": {"{__name__=~\"job:.*\"}"}},
@ -3217,7 +3217,7 @@ func makePodMonitors() map[string]*monitoringv1.PodMonitor {
},
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
MetricRelabelConfigs: []monitoringv1.RelabelConfig{
{
@ -3253,7 +3253,7 @@ func makePodMonitors() map[string]*monitoringv1.PodMonitor {
},
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
RelabelConfigs: []monitoringv1.RelabelConfig{
{
@ -4592,7 +4592,7 @@ func TestLabelNameLengthLimits(t *testing.T) {
Spec: monitoringv1.PodMonitorSpec{
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
},
},
@ -5148,7 +5148,7 @@ func TestPodMonitorEndpointFollowRedirects(t *testing.T) {
Spec: monitoringv1.PodMonitorSpec{
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
FollowRedirects: ptr.To(tc.followRedirects),
},
@ -5269,7 +5269,7 @@ func TestPodMonitorPhaseFilter(t *testing.T) {
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
FilterRunning: ptr.To(false),
Port: "test",
Port: ptr.To("test"),
},
},
},
@ -5329,7 +5329,7 @@ func TestPodMonitorEndpointEnableHttp2(t *testing.T) {
Spec: monitoringv1.PodMonitorSpec{
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
EnableHttp2: ptr.To(tc.enableHTTP2),
},
@ -9323,7 +9323,7 @@ func defaultPodMonitor() *monitoringv1.PodMonitor {
},
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
},
},
@ -9654,6 +9654,67 @@ func TestPodMonitorScrapeClassWithDefaultTLS(t *testing.T) {
}
}
func TestPodMonitorPortNumber(t *testing.T) {
testCases := []struct {
name string
port string
portNumber int32
targetPort intstr.IntOrString
golden string
}{
{
name: "PodMonitor with Pod Name",
golden: "podMonitorObjectWithPodName.golden",
port: "podname",
portNumber: 1024,
targetPort: intstr.FromString("10240"),
},
{
name: "PodMonitor with Pod Port Number",
golden: "podMonitorObjectWithPortNumber.golden",
portNumber: 1024,
targetPort: intstr.FromString("10240"),
},
{
name: "PodMonitor with TargetPort Int",
golden: "podMonitorObjectWithTargetPortInt.golden",
targetPort: intstr.FromInt(10240),
},
{
name: "PodMonitor with TargetPort string",
golden: "podMonitorObjectWithTargetPortString.golden",
targetPort: intstr.FromString("10240"),
},
}
for _, tc := range testCases {
p := defaultPrometheus()
podMonitor := defaultPodMonitor()
podMonitor.Spec.PodMetricsEndpoints[0].Port = ptr.To(tc.port)
podMonitor.Spec.PodMetricsEndpoints[0].PortNumber = ptr.To(tc.portNumber)
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
podMonitor.Spec.PodMetricsEndpoints[0].TargetPort = ptr.To(tc.targetPort)
cg := mustNewConfigGenerator(t, p)
cfg, err := cg.GenerateServerConfiguration(
p,
nil,
map[string]*monitoringv1.PodMonitor{"monitor": podMonitor},
nil,
nil,
&assets.StoreBuilder{},
nil,
nil,
nil,
nil,
)
require.NoError(t, err)
golden.Assert(t, string(cfg), tc.golden)
}
}
func TestNewConfigGeneratorWithMultipleDefaultScrapeClass(t *testing.T) {
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelWarn,

View file

@ -0,0 +1,61 @@
global:
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs:
- job_name: podMonitor/default/defaultPodMonitor/0
honor_labels: false
kubernetes_sd_configs:
- role: pod
namespaces:
names:
- default
scrape_interval: 30s
relabel_configs:
- source_labels:
- job
target_label: __tmp_prometheus_job_name
- action: drop
source_labels:
- __meta_kubernetes_pod_phase
regex: (Failed|Succeeded)
- action: keep
source_labels:
- __meta_kubernetes_pod_label_group
- __meta_kubernetes_pod_labelpresent_group
regex: (group1);true
- action: keep
source_labels:
- __meta_kubernetes_pod_container_port_name
regex: podname
- source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- target_label: job
replacement: default/defaultPodMonitor
- target_label: endpoint
replacement: podname
- source_labels:
- __address__
- __tmp_hash
target_label: __tmp_hash
regex: (.+);
replacement: $1
action: replace
- source_labels:
- __tmp_hash
target_label: __tmp_hash
modulus: 1
action: hashmod
- source_labels:
- __tmp_hash
regex: $(SHARD)
action: keep

View file

@ -0,0 +1,61 @@
global:
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs:
- job_name: podMonitor/default/defaultPodMonitor/0
honor_labels: false
kubernetes_sd_configs:
- role: pod
namespaces:
names:
- default
scrape_interval: 30s
relabel_configs:
- source_labels:
- job
target_label: __tmp_prometheus_job_name
- action: drop
source_labels:
- __meta_kubernetes_pod_phase
regex: (Failed|Succeeded)
- action: keep
source_labels:
- __meta_kubernetes_pod_label_group
- __meta_kubernetes_pod_labelpresent_group
regex: (group1);true
- action: keep
source_labels:
- __meta_kubernetes_pod_container_port_number
regex: 1024
- source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- target_label: job
replacement: default/defaultPodMonitor
- target_label: endpoint
replacement: "10240"
- source_labels:
- __address__
- __tmp_hash
target_label: __tmp_hash
regex: (.+);
replacement: $1
action: replace
- source_labels:
- __tmp_hash
target_label: __tmp_hash
modulus: 1
action: hashmod
- source_labels:
- __tmp_hash
regex: $(SHARD)
action: keep

View file

@ -0,0 +1,61 @@
global:
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs:
- job_name: podMonitor/default/defaultPodMonitor/0
honor_labels: false
kubernetes_sd_configs:
- role: pod
namespaces:
names:
- default
scrape_interval: 30s
relabel_configs:
- source_labels:
- job
target_label: __tmp_prometheus_job_name
- action: drop
source_labels:
- __meta_kubernetes_pod_phase
regex: (Failed|Succeeded)
- action: keep
source_labels:
- __meta_kubernetes_pod_label_group
- __meta_kubernetes_pod_labelpresent_group
regex: (group1);true
- action: keep
source_labels:
- __meta_kubernetes_pod_container_port_number
regex: 10240
- source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- target_label: job
replacement: default/defaultPodMonitor
- target_label: endpoint
replacement: "10240"
- source_labels:
- __address__
- __tmp_hash
target_label: __tmp_hash
regex: (.+);
replacement: $1
action: replace
- source_labels:
- __tmp_hash
target_label: __tmp_hash
modulus: 1
action: hashmod
- source_labels:
- __tmp_hash
regex: $(SHARD)
action: keep

View file

@ -0,0 +1,61 @@
global:
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs:
- job_name: podMonitor/default/defaultPodMonitor/0
honor_labels: false
kubernetes_sd_configs:
- role: pod
namespaces:
names:
- default
scrape_interval: 30s
relabel_configs:
- source_labels:
- job
target_label: __tmp_prometheus_job_name
- action: drop
source_labels:
- __meta_kubernetes_pod_phase
regex: (Failed|Succeeded)
- action: keep
source_labels:
- __meta_kubernetes_pod_label_group
- __meta_kubernetes_pod_labelpresent_group
regex: (group1);true
- action: keep
source_labels:
- __meta_kubernetes_pod_container_port_name
regex: "10240"
- source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- target_label: job
replacement: default/defaultPodMonitor
- target_label: endpoint
replacement: "10240"
- source_labels:
- __address__
- __tmp_hash
target_label: __tmp_hash
regex: (.+);
replacement: $1
action: replace
- source_labels:
- __tmp_hash
target_label: __tmp_hash
modulus: 1
action: hashmod
- source_labels:
- __tmp_hash
regex: $(SHARD)
action: keep

View file

@ -3535,7 +3535,7 @@ func testPromSecurePodMonitor(t *testing.T) {
{
name: "basic-auth-secret",
endpoint: monitoringv1.PodMetricsEndpoint{
Port: "web",
Port: ptr.To("web"),
BasicAuth: &monitoringv1.BasicAuth{
Username: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
@ -3558,7 +3558,7 @@ func testPromSecurePodMonitor(t *testing.T) {
{
name: "bearer-secret",
endpoint: monitoringv1.PodMetricsEndpoint{
Port: "web",
Port: ptr.To("web"),
BearerTokenSecret: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: name,
@ -3574,7 +3574,7 @@ func testPromSecurePodMonitor(t *testing.T) {
{
name: "tls-secret",
endpoint: monitoringv1.PodMetricsEndpoint{
Port: "mtls",
Port: ptr.To("mtls"),
Scheme: "https",
TLSConfig: &monitoringv1.SafeTLSConfig{
InsecureSkipVerify: ptr.To(true),
@ -3607,7 +3607,7 @@ func testPromSecurePodMonitor(t *testing.T) {
{
name: "tls-configmap",
endpoint: monitoringv1.PodMetricsEndpoint{
Port: "mtls",
Port: ptr.To("mtls"),
Scheme: "https",
TLSConfig: &monitoringv1.SafeTLSConfig{
InsecureSkipVerify: ptr.To(true),
@ -3714,7 +3714,7 @@ func testPromSecurePodMonitor(t *testing.T) {
},
}
if test.endpoint.Port == "mtls" {
if *test.endpoint.Port == "mtls" {
simple.Spec.Template.Spec.Containers[0].Args = []string{"--cert-path=/etc/ca-certificates"}
}

View file

@ -377,7 +377,7 @@ func (f *Framework) MakeBasicPodMonitor(name string) *monitoringv1.PodMonitor {
},
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
Port: "web",
Port: ptr.To("web"),
Interval: "30s",
},
},