1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-15 16:56:24 +00:00

feat: add support fallback_scrape_protocol option for each scrape CRD and globally (#7131)

* add fallback scrape protocol


---------

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
This commit is contained in:
dongjiang 2024-11-21 17:35:54 +08:00 committed by GitHub
parent ef69943905
commit d3b8e5921d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
45 changed files with 1102 additions and 0 deletions

195
Documentation/api.md generated
View file

@ -1000,6 +1000,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>labelLimit</code><br/>
<em>
uint64
@ -1408,6 +1423,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>labelLimit</code><br/>
<em>
uint64
@ -1964,6 +1994,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>externalLabels</code><br/>
<em>
map[string]string
@ -3652,6 +3697,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>targetLimit</code><br/>
<em>
uint64
@ -6969,6 +7029,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>externalLabels</code><br/>
<em>
map[string]string
@ -10545,6 +10620,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>labelLimit</code><br/>
<em>
uint64
@ -10904,6 +10994,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>labelLimit</code><br/>
<em>
uint64
@ -11746,6 +11851,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>externalLabels</code><br/>
<em>
map[string]string
@ -15367,6 +15487,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>targetLimit</code><br/>
<em>
uint64
@ -18409,6 +18544,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>externalLabels</code><br/>
<em>
map[string]string
@ -19977,6 +20127,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>honorTimestamps</code><br/>
<em>
bool
@ -26294,6 +26459,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>externalLabels</code><br/>
<em>
map[string]string
@ -29039,6 +29219,21 @@ protocols supported by Prometheus in order of preference (from most to least pre
</tr>
<tr>
<td>
<code>scrapeFallbackProtocol</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.ScrapeProtocol">
ScrapeProtocol
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.</p>
<p>It requires Prometheus &gt;= v3.0.0.</p>
</td>
</tr>
<tr>
<td>
<code>honorTimestamps</code><br/>
<em>
bool

72
bundle.yaml generated
View file

@ -19690,6 +19690,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeProtocols:
description: |-
`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the
@ -20462,6 +20474,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeProtocols:
description: |-
`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the
@ -27746,6 +27770,18 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeInterval:
default: 30s
description: |-
@ -40041,6 +40077,18 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeInterval:
default: 30s
description: |-
@ -55805,6 +55853,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeInterval:
description: ScrapeInterval is the interval between consecutive scrapes.
pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$
@ -57157,6 +57217,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeProtocols:
description: |-
`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the

View file

@ -1086,6 +1086,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeProtocols:
description: |-
`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the

View file

@ -681,6 +681,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeProtocols:
description: |-
`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the

View file

@ -6803,6 +6803,18 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeInterval:
default: 30s
description: |-

View file

@ -8450,6 +8450,18 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeInterval:
default: 30s
description: |-

View file

@ -11248,6 +11248,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeInterval:
description: ScrapeInterval is the interval between consecutive scrapes.
pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$

View file

@ -1106,6 +1106,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeProtocols:
description: |-
`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the

View file

@ -1087,6 +1087,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeProtocols:
description: |-
`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the

View file

@ -682,6 +682,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeProtocols:
description: |-
`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the

View file

@ -6804,6 +6804,18 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeInterval:
default: 30s
description: |-

View file

@ -8451,6 +8451,18 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeInterval:
default: 30s
description: |-

View file

@ -11249,6 +11249,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeInterval:
description: ScrapeInterval is the interval between consecutive scrapes.
pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$

View file

@ -1107,6 +1107,18 @@ spec:
Whether to scrape a classic histogram that is also exposed as a native histogram.
It requires Prometheus >= v2.45.0.
type: boolean
scrapeFallbackProtocol:
description: |-
The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
It requires Prometheus >= v3.0.0.
enum:
- PrometheusProto
- OpenMetricsText0.0.1
- OpenMetricsText1.0.0
- PrometheusText0.0.4
- PrometheusText1.0.0
type: string
scrapeProtocols:
description: |-
`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the

View file

@ -942,6 +942,17 @@
"description": "Whether to scrape a classic histogram that is also exposed as a native histogram.\nIt requires Prometheus >= v2.45.0.",
"type": "boolean"
},
"scrapeFallbackProtocol": {
"description": "The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.\n\nIt requires Prometheus >= v3.0.0.",
"enum": [
"PrometheusProto",
"OpenMetricsText0.0.1",
"OpenMetricsText1.0.0",
"PrometheusText0.0.4",
"PrometheusText1.0.0"
],
"type": "string"
},
"scrapeProtocols": {
"description": "`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the\nprotocols supported by Prometheus in order of preference (from most to least preferred).\n\nIf unset, Prometheus uses its default value.\n\nIt requires Prometheus >= v2.49.0.",
"items": {

View file

@ -626,6 +626,17 @@
"description": "Whether to scrape a classic histogram that is also exposed as a native histogram.\nIt requires Prometheus >= v2.45.0.",
"type": "boolean"
},
"scrapeFallbackProtocol": {
"description": "The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.\n\nIt requires Prometheus >= v3.0.0.",
"enum": [
"PrometheusProto",
"OpenMetricsText0.0.1",
"OpenMetricsText1.0.0",
"PrometheusText0.0.4",
"PrometheusText1.0.0"
],
"type": "string"
},
"scrapeProtocols": {
"description": "`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the\nprotocols supported by Prometheus in order of preference (from most to least preferred).\n\nIf unset, Prometheus uses its default value.\n\nIt requires Prometheus >= v2.49.0.",
"items": {

View file

@ -5826,6 +5826,17 @@
"type": "object",
"x-kubernetes-map-type": "atomic"
},
"scrapeFallbackProtocol": {
"description": "The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.\n\nIt requires Prometheus >= v3.0.0.",
"enum": [
"PrometheusProto",
"OpenMetricsText0.0.1",
"OpenMetricsText1.0.0",
"PrometheusText0.0.4",
"PrometheusText1.0.0"
],
"type": "string"
},
"scrapeInterval": {
"default": "30s",
"description": "Interval between consecutive scrapes.\n\nDefault: \"30s\"",

View file

@ -7284,6 +7284,17 @@
"type": "object",
"x-kubernetes-map-type": "atomic"
},
"scrapeFallbackProtocol": {
"description": "The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.\n\nIt requires Prometheus >= v3.0.0.",
"enum": [
"PrometheusProto",
"OpenMetricsText0.0.1",
"OpenMetricsText1.0.0",
"PrometheusText0.0.4",
"PrometheusText1.0.0"
],
"type": "string"
},
"scrapeInterval": {
"default": "30s",
"description": "Interval between consecutive scrapes.\n\nDefault: \"30s\"",

View file

@ -10675,6 +10675,17 @@
"description": "Whether to scrape a classic histogram that is also exposed as a native histogram.\nIt requires Prometheus >= v2.45.0.",
"type": "boolean"
},
"scrapeFallbackProtocol": {
"description": "The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.\n\nIt requires Prometheus >= v3.0.0.",
"enum": [
"PrometheusProto",
"OpenMetricsText0.0.1",
"OpenMetricsText1.0.0",
"PrometheusText0.0.4",
"PrometheusText1.0.0"
],
"type": "string"
},
"scrapeInterval": {
"description": "ScrapeInterval is the interval between consecutive scrapes.",
"pattern": "^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$",

View file

@ -958,6 +958,17 @@
"description": "Whether to scrape a classic histogram that is also exposed as a native histogram.\nIt requires Prometheus >= v2.45.0.",
"type": "boolean"
},
"scrapeFallbackProtocol": {
"description": "The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.\n\nIt requires Prometheus >= v3.0.0.",
"enum": [
"PrometheusProto",
"OpenMetricsText0.0.1",
"OpenMetricsText1.0.0",
"PrometheusText0.0.4",
"PrometheusText1.0.0"
],
"type": "string"
},
"scrapeProtocols": {
"description": "`scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the\nprotocols supported by Prometheus in order of preference (from most to least preferred).\n\nIf unset, Prometheus uses its default value.\n\nIt requires Prometheus >= v2.49.0.",
"items": {

View file

@ -105,6 +105,12 @@ type PodMonitorSpec struct {
// +optional
ScrapeProtocols []ScrapeProtocol `json:"scrapeProtocols,omitempty"`
// The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
//
// It requires Prometheus >= v3.0.0.
// +optional
ScrapeFallbackProtocol *ScrapeProtocol `json:"scrapeFallbackProtocol,omitempty"`
// Per-scrape limit on number of labels that will be accepted for a sample.
//
// It requires Prometheus >= v2.27.0.

View file

@ -100,6 +100,11 @@ type ProbeSpec struct {
// +listType=set
// +optional
ScrapeProtocols []ScrapeProtocol `json:"scrapeProtocols,omitempty"`
// The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
//
// It requires Prometheus >= v3.0.0.
// +optional
ScrapeFallbackProtocol *ScrapeProtocol `json:"scrapeFallbackProtocol,omitempty"`
// Per-scrape limit on number of labels that will be accepted for a sample.
// Only valid in Prometheus versions 2.27.0 and newer.
// +optional

View file

@ -300,6 +300,12 @@ type CommonPrometheusFields struct {
// +optional
ScrapeProtocols []ScrapeProtocol `json:"scrapeProtocols,omitempty"`
// The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
//
// It requires Prometheus >= v3.0.0.
// +optional
ScrapeFallbackProtocol *ScrapeProtocol `json:"scrapeFallbackProtocol,omitempty"`
// The labels to add to any time series or alerts when communicating with
// external systems (federation, remote storage, Alertmanager).
// Labels defined by `spec.replicaExternalLabelName` and

View file

@ -104,6 +104,12 @@ type ServiceMonitorSpec struct {
// +optional
ScrapeProtocols []ScrapeProtocol `json:"scrapeProtocols,omitempty"`
// The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
//
// It requires Prometheus >= v3.0.0.
// +optional
ScrapeFallbackProtocol *ScrapeProtocol `json:"scrapeFallbackProtocol,omitempty"`
// `targetLimit` defines a limit on the number of scraped targets that will
// be accepted.
//

View file

@ -745,6 +745,11 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) {
*out = make([]ScrapeProtocol, len(*in))
copy(*out, *in)
}
if in.ScrapeFallbackProtocol != nil {
in, out := &in.ScrapeFallbackProtocol, &out.ScrapeFallbackProtocol
*out = new(ScrapeProtocol)
**out = **in
}
if in.ExternalLabels != nil {
in, out := &in.ExternalLabels, &out.ExternalLabels
*out = make(map[string]string, len(*in))
@ -1807,6 +1812,11 @@ func (in *PodMonitorSpec) DeepCopyInto(out *PodMonitorSpec) {
*out = make([]ScrapeProtocol, len(*in))
copy(*out, *in)
}
if in.ScrapeFallbackProtocol != nil {
in, out := &in.ScrapeFallbackProtocol, &out.ScrapeFallbackProtocol
*out = new(ScrapeProtocol)
**out = **in
}
if in.LabelLimit != nil {
in, out := &in.LabelLimit, &out.LabelLimit
*out = new(uint64)
@ -1949,6 +1959,11 @@ func (in *ProbeSpec) DeepCopyInto(out *ProbeSpec) {
*out = make([]ScrapeProtocol, len(*in))
copy(*out, *in)
}
if in.ScrapeFallbackProtocol != nil {
in, out := &in.ScrapeFallbackProtocol, &out.ScrapeFallbackProtocol
*out = new(ScrapeProtocol)
**out = **in
}
if in.LabelLimit != nil {
in, out := &in.LabelLimit, &out.LabelLimit
*out = new(uint64)
@ -3064,6 +3079,11 @@ func (in *ServiceMonitorSpec) DeepCopyInto(out *ServiceMonitorSpec) {
*out = make([]ScrapeProtocol, len(*in))
copy(*out, *in)
}
if in.ScrapeFallbackProtocol != nil {
in, out := &in.ScrapeFallbackProtocol, &out.ScrapeFallbackProtocol
*out = new(ScrapeProtocol)
**out = **in
}
if in.TargetLimit != nil {
in, out := &in.TargetLimit, &out.TargetLimit
*out = new(uint64)

View file

@ -251,6 +251,11 @@ type ScrapeConfigSpec struct {
// +kubebuilder:validation:MinItems:=1
// +optional
ScrapeProtocols []v1.ScrapeProtocol `json:"scrapeProtocols,omitempty"`
// The protocol to use if a scrape returns blank, unparseable, or otherwise invalid Content-Type.
//
// It requires Prometheus >= v3.0.0.
// +optional
ScrapeFallbackProtocol *v1.ScrapeProtocol `json:"scrapeFallbackProtocol,omitempty"`
// HonorTimestamps controls whether Prometheus respects the timestamps present in scraped data.
// +optional
HonorTimestamps *bool `json:"honorTimestamps,omitempty"`

View file

@ -2492,6 +2492,11 @@ func (in *ScrapeConfigSpec) DeepCopyInto(out *ScrapeConfigSpec) {
*out = make([]monitoringv1.ScrapeProtocol, len(*in))
copy(*out, *in)
}
if in.ScrapeFallbackProtocol != nil {
in, out := &in.ScrapeFallbackProtocol, &out.ScrapeFallbackProtocol
*out = new(monitoringv1.ScrapeProtocol)
**out = **in
}
if in.HonorTimestamps != nil {
in, out := &in.HonorTimestamps, &out.HonorTimestamps
*out = new(bool)

View file

@ -49,6 +49,7 @@ type CommonPrometheusFieldsApplyConfiguration struct {
ScrapeInterval *monitoringv1.Duration `json:"scrapeInterval,omitempty"`
ScrapeTimeout *monitoringv1.Duration `json:"scrapeTimeout,omitempty"`
ScrapeProtocols []monitoringv1.ScrapeProtocol `json:"scrapeProtocols,omitempty"`
ScrapeFallbackProtocol *monitoringv1.ScrapeProtocol `json:"scrapeFallbackProtocol,omitempty"`
ExternalLabels map[string]string `json:"externalLabels,omitempty"`
EnableRemoteWriteReceiver *bool `json:"enableRemoteWriteReceiver,omitempty"`
EnableOTLPReceiver *bool `json:"enableOTLPReceiver,omitempty"`
@ -312,6 +313,14 @@ func (b *CommonPrometheusFieldsApplyConfiguration) WithScrapeProtocols(values ..
return b
}
// WithScrapeFallbackProtocol sets the ScrapeFallbackProtocol 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 ScrapeFallbackProtocol field is set to the value of the last call.
func (b *CommonPrometheusFieldsApplyConfiguration) WithScrapeFallbackProtocol(value monitoringv1.ScrapeProtocol) *CommonPrometheusFieldsApplyConfiguration {
b.ScrapeFallbackProtocol = &value
return b
}
// WithExternalLabels puts the entries into the ExternalLabels field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, the entries provided by each call will be put on the ExternalLabels field,

View file

@ -33,6 +33,7 @@ type PodMonitorSpecApplyConfiguration struct {
SampleLimit *uint64 `json:"sampleLimit,omitempty"`
TargetLimit *uint64 `json:"targetLimit,omitempty"`
ScrapeProtocols []monitoringv1.ScrapeProtocol `json:"scrapeProtocols,omitempty"`
ScrapeFallbackProtocol *monitoringv1.ScrapeProtocol `json:"scrapeFallbackProtocol,omitempty"`
LabelLimit *uint64 `json:"labelLimit,omitempty"`
LabelNameLengthLimit *uint64 `json:"labelNameLengthLimit,omitempty"`
LabelValueLengthLimit *uint64 `json:"labelValueLengthLimit,omitempty"`
@ -122,6 +123,14 @@ func (b *PodMonitorSpecApplyConfiguration) WithScrapeProtocols(values ...monitor
return b
}
// WithScrapeFallbackProtocol sets the ScrapeFallbackProtocol 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 ScrapeFallbackProtocol field is set to the value of the last call.
func (b *PodMonitorSpecApplyConfiguration) WithScrapeFallbackProtocol(value monitoringv1.ScrapeProtocol) *PodMonitorSpecApplyConfiguration {
b.ScrapeFallbackProtocol = &value
return b
}
// WithLabelLimit sets the LabelLimit 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 LabelLimit field is set to the value of the last call.

View file

@ -40,6 +40,7 @@ type ProbeSpecApplyConfiguration struct {
SampleLimit *uint64 `json:"sampleLimit,omitempty"`
TargetLimit *uint64 `json:"targetLimit,omitempty"`
ScrapeProtocols []monitoringv1.ScrapeProtocol `json:"scrapeProtocols,omitempty"`
ScrapeFallbackProtocol *monitoringv1.ScrapeProtocol `json:"scrapeFallbackProtocol,omitempty"`
LabelLimit *uint64 `json:"labelLimit,omitempty"`
LabelNameLengthLimit *uint64 `json:"labelNameLengthLimit,omitempty"`
LabelValueLengthLimit *uint64 `json:"labelValueLengthLimit,omitempty"`
@ -181,6 +182,14 @@ func (b *ProbeSpecApplyConfiguration) WithScrapeProtocols(values ...monitoringv1
return b
}
// WithScrapeFallbackProtocol sets the ScrapeFallbackProtocol 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 ScrapeFallbackProtocol field is set to the value of the last call.
func (b *ProbeSpecApplyConfiguration) WithScrapeFallbackProtocol(value monitoringv1.ScrapeProtocol) *ProbeSpecApplyConfiguration {
b.ScrapeFallbackProtocol = &value
return b
}
// WithLabelLimit sets the LabelLimit 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 LabelLimit field is set to the value of the last call.

View file

@ -245,6 +245,14 @@ func (b *PrometheusSpecApplyConfiguration) WithScrapeProtocols(values ...monitor
return b
}
// WithScrapeFallbackProtocol sets the ScrapeFallbackProtocol 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 ScrapeFallbackProtocol field is set to the value of the last call.
func (b *PrometheusSpecApplyConfiguration) WithScrapeFallbackProtocol(value monitoringv1.ScrapeProtocol) *PrometheusSpecApplyConfiguration {
b.ScrapeFallbackProtocol = &value
return b
}
// WithExternalLabels puts the entries into the ExternalLabels field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, the entries provided by each call will be put on the ExternalLabels field,

View file

@ -33,6 +33,7 @@ type ServiceMonitorSpecApplyConfiguration struct {
NamespaceSelector *NamespaceSelectorApplyConfiguration `json:"namespaceSelector,omitempty"`
SampleLimit *uint64 `json:"sampleLimit,omitempty"`
ScrapeProtocols []monitoringv1.ScrapeProtocol `json:"scrapeProtocols,omitempty"`
ScrapeFallbackProtocol *monitoringv1.ScrapeProtocol `json:"scrapeFallbackProtocol,omitempty"`
TargetLimit *uint64 `json:"targetLimit,omitempty"`
LabelLimit *uint64 `json:"labelLimit,omitempty"`
LabelNameLengthLimit *uint64 `json:"labelNameLengthLimit,omitempty"`
@ -125,6 +126,14 @@ func (b *ServiceMonitorSpecApplyConfiguration) WithScrapeProtocols(values ...mon
return b
}
// WithScrapeFallbackProtocol sets the ScrapeFallbackProtocol 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 ScrapeFallbackProtocol field is set to the value of the last call.
func (b *ServiceMonitorSpecApplyConfiguration) WithScrapeFallbackProtocol(value monitoringv1.ScrapeProtocol) *ServiceMonitorSpecApplyConfiguration {
b.ScrapeFallbackProtocol = &value
return b
}
// WithTargetLimit sets the TargetLimit 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 TargetLimit field is set to the value of the last call.

View file

@ -233,6 +233,14 @@ func (b *PrometheusAgentSpecApplyConfiguration) WithScrapeProtocols(values ...mo
return b
}
// WithScrapeFallbackProtocol sets the ScrapeFallbackProtocol 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 ScrapeFallbackProtocol field is set to the value of the last call.
func (b *PrometheusAgentSpecApplyConfiguration) WithScrapeFallbackProtocol(value monitoringv1.ScrapeProtocol) *PrometheusAgentSpecApplyConfiguration {
b.ScrapeFallbackProtocol = &value
return b
}
// WithExternalLabels puts the entries into the ExternalLabels field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, the entries provided by each call will be put on the ExternalLabels field,

View file

@ -55,6 +55,7 @@ type ScrapeConfigSpecApplyConfiguration struct {
ScrapeInterval *monitoringv1.Duration `json:"scrapeInterval,omitempty"`
ScrapeTimeout *monitoringv1.Duration `json:"scrapeTimeout,omitempty"`
ScrapeProtocols []monitoringv1.ScrapeProtocol `json:"scrapeProtocols,omitempty"`
ScrapeFallbackProtocol *monitoringv1.ScrapeProtocol `json:"scrapeFallbackProtocol,omitempty"`
HonorTimestamps *bool `json:"honorTimestamps,omitempty"`
TrackTimestampsStaleness *bool `json:"trackTimestampsStaleness,omitempty"`
HonorLabels *bool `json:"honorLabels,omitempty"`
@ -438,6 +439,14 @@ func (b *ScrapeConfigSpecApplyConfiguration) WithScrapeProtocols(values ...monit
return b
}
// WithScrapeFallbackProtocol sets the ScrapeFallbackProtocol 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 ScrapeFallbackProtocol field is set to the value of the last call.
func (b *ScrapeConfigSpecApplyConfiguration) WithScrapeFallbackProtocol(value monitoringv1.ScrapeProtocol) *ScrapeConfigSpecApplyConfiguration {
b.ScrapeFallbackProtocol = &value
return b
}
// WithHonorTimestamps sets the HonorTimestamps 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 HonorTimestamps field is set to the value of the last call.

View file

@ -385,6 +385,15 @@ func (cg *ConfigGenerator) addScrapeProtocols(cfg yaml.MapSlice, scrapeProtocols
return cg.WithMinimumVersion("2.49.0").AppendMapItem(cfg, "scrape_protocols", sps)
}
// addScrapeFallbackProtocol adds the fallback_scrape_protocol field into the configuration.
func (cg *ConfigGenerator) addScrapeFallbackProtocol(cfg yaml.MapSlice, scrapeFallbackProtocol *monitoringv1.ScrapeProtocol) yaml.MapSlice {
if scrapeFallbackProtocol == nil {
return cfg
}
return cg.WithMinimumVersion("3.0.0-rc.0").AppendMapItem(cfg, "fallback_scrape_protocol", scrapeFallbackProtocol)
}
// AddHonorLabels adds the honor_labels field into scrape configurations.
// if OverrideHonorLabels is true then honor_labels is always false.
func (cg *ConfigGenerator) AddHonorLabels(cfg yaml.MapSlice, honorLabels bool) yaml.MapSlice {
@ -1372,6 +1381,7 @@ func (cg *ConfigGenerator) generatePodMonitorConfig(
cfg = cg.AddLimitsToYAML(cfg, keepDroppedTargetsKey, m.Spec.KeepDroppedTargets, cpf.EnforcedKeepDroppedTargets)
cfg = cg.addNativeHistogramConfig(cfg, m.Spec.NativeHistogramConfig)
cfg = cg.addScrapeProtocols(cfg, m.Spec.ScrapeProtocols)
cfg = cg.addScrapeFallbackProtocol(cfg, m.Spec.ScrapeFallbackProtocol)
if bodySizeLimit := getLowerByteSize(m.Spec.BodySizeLimit, &cpf); !isByteSizeEmpty(bodySizeLimit) {
cfg = cg.WithMinimumVersion("2.28.0").AppendMapItem(cfg, "body_size_limit", bodySizeLimit)
@ -1440,6 +1450,7 @@ func (cg *ConfigGenerator) generateProbeConfig(
cfg = cg.AddLimitsToYAML(cfg, keepDroppedTargetsKey, m.Spec.KeepDroppedTargets, cpf.EnforcedKeepDroppedTargets)
cfg = cg.addNativeHistogramConfig(cfg, m.Spec.NativeHistogramConfig)
cfg = cg.addScrapeProtocols(cfg, m.Spec.ScrapeProtocols)
cfg = cg.addScrapeFallbackProtocol(cfg, m.Spec.ScrapeFallbackProtocol)
if cpf.EnforcedBodySizeLimit != "" {
cfg = cg.WithMinimumVersion("2.28.0").AppendMapItem(cfg, "body_size_limit", cpf.EnforcedBodySizeLimit)
@ -1889,6 +1900,7 @@ func (cg *ConfigGenerator) generateServiceMonitorConfig(
cfg = cg.AddLimitsToYAML(cfg, keepDroppedTargetsKey, m.Spec.KeepDroppedTargets, cpf.EnforcedKeepDroppedTargets)
cfg = cg.addNativeHistogramConfig(cfg, m.Spec.NativeHistogramConfig)
cfg = cg.addScrapeProtocols(cfg, m.Spec.ScrapeProtocols)
cfg = cg.addScrapeFallbackProtocol(cfg, m.Spec.ScrapeFallbackProtocol)
if bodySizeLimit := getLowerByteSize(m.Spec.BodySizeLimit, &cpf); !isByteSizeEmpty(bodySizeLimit) {
cfg = cg.WithMinimumVersion("2.28.0").AppendMapItem(cfg, "body_size_limit", bodySizeLimit)
@ -2949,6 +2961,7 @@ func (cg *ConfigGenerator) generateScrapeConfig(
}
cfg = cg.addScrapeProtocols(cfg, sc.Spec.ScrapeProtocols)
cfg = cg.addScrapeFallbackProtocol(cfg, sc.Spec.ScrapeFallbackProtocol)
if sc.Spec.Scheme != nil {
cfg = append(cfg, yaml.MapItem{Key: "scheme", Value: strings.ToLower(*sc.Spec.Scheme)})
@ -4674,6 +4687,7 @@ func (cg *ConfigGenerator) buildGlobalConfig() yaml.MapSlice {
cfg := yaml.MapSlice{}
cfg = cg.appendScrapeIntervals(cfg)
cfg = cg.addScrapeProtocols(cfg, cg.prom.GetCommonPrometheusFields().ScrapeProtocols)
cfg = cg.addScrapeFallbackProtocol(cfg, cg.prom.GetCommonPrometheusFields().ScrapeFallbackProtocol)
cfg = cg.appendExternalLabels(cfg)
cfg = cg.appendScrapeLimits(cfg)
if cpf.NameValidationScheme != nil {

View file

@ -125,6 +125,7 @@ func TestGlobalSettings(t *testing.T) {
ScrapeInterval monitoringv1.Duration
ScrapeTimeout monitoringv1.Duration
ScrapeProtocols []monitoringv1.ScrapeProtocol
ScrapeFallbackProtocol *monitoringv1.ScrapeProtocol
ExternalLabels map[string]string
PrometheusExternalLabelName *string
ReplicaExternalLabelName *string
@ -264,6 +265,22 @@ func TestGlobalSettings(t *testing.T) {
},
Golden: "valid_global_config_with_unsupported_scrape_protocols.golden",
},
{
Scenario: "valid global config with scrape fallback protocol",
Version: "v3.0.0-rc.0",
ScrapeInterval: "30s",
EvaluationInterval: "30s",
ScrapeFallbackProtocol: ptr.To(monitoringv1.PrometheusText1_0_0),
Golden: "valid_global_config_with_scrape_fallback_protocol.golden",
},
{
Scenario: "valid global config scrape protocols with unsupported version",
Version: "v2.55.0",
ScrapeInterval: "30s",
EvaluationInterval: "30s",
ScrapeFallbackProtocol: ptr.To(monitoringv1.PrometheusProto),
Golden: "valid_global_config_with_unsupported_scrape_fallback_protocols.golden",
},
{
Scenario: "valid global config without rule query offset if prometheus version less required",
Version: "v2.52.0",
@ -292,6 +309,7 @@ func TestGlobalSettings(t *testing.T) {
ScrapeInterval: tc.ScrapeInterval,
ScrapeTimeout: tc.ScrapeTimeout,
ScrapeProtocols: tc.ScrapeProtocols,
ScrapeFallbackProtocol: tc.ScrapeFallbackProtocol,
ExternalLabels: tc.ExternalLabels,
PrometheusExternalLabelName: tc.PrometheusExternalLabelName,
ReplicaExternalLabelName: tc.ReplicaExternalLabelName,
@ -2157,6 +2175,67 @@ func TestSettingScrapeProtocolsInServiceMonitor(t *testing.T) {
}
}
func TestSettingScrapeFallbackProtocolInServiceMonitor(t *testing.T) {
for _, tc := range []struct {
name string
version string
scrapeFallbackProtocol *monitoringv1.ScrapeProtocol
golden string
}{
{
name: "setting ScrapeFallbackProtocol in ServiceMonitor with prometheus old version",
version: "v2.55.0",
scrapeFallbackProtocol: ptr.To(monitoringv1.OpenMetricsText1_0_0),
golden: "SettingScrapeFallbackProtocolInServiceMonitor_OldVersion.golden",
},
{
name: "setting ScrapeFallbackProtocol in ServiceMonitor with prometheus new version",
version: "v3.0.0",
scrapeFallbackProtocol: ptr.To(monitoringv1.OpenMetricsText0_0_1),
golden: "SettingScrapeFallbackProtocolInServiceMonitor_NewVersion.golden",
},
} {
t.Run(tc.name, func(t *testing.T) {
p := defaultPrometheus()
p.Spec.CommonPrometheusFields.Version = tc.version
cg := mustNewConfigGenerator(t, p)
cfg, err := cg.GenerateServerConfiguration(
p,
map[string]*monitoringv1.ServiceMonitor{
"testservicemonitor1": {
ObjectMeta: metav1.ObjectMeta{
Name: "testservicemonitor1",
Namespace: "default",
},
Spec: monitoringv1.ServiceMonitorSpec{
TargetLabels: []string{"example", "env"},
ScrapeFallbackProtocol: tc.scrapeFallbackProtocol,
Endpoints: []monitoringv1.Endpoint{
{
HonorTimestamps: ptr.To(false),
Port: "web",
Interval: "30s",
},
},
},
},
},
nil,
nil,
nil,
&assets.StoreBuilder{},
nil,
nil,
nil,
nil,
)
require.NoError(t, err)
golden.Assert(t, string(cfg), tc.golden)
})
}
}
func TestSettingScrapeProtocolsInPodMonitor(t *testing.T) {
for _, tc := range []struct {
name string
@ -2224,6 +2303,67 @@ func TestSettingScrapeProtocolsInPodMonitor(t *testing.T) {
}
}
func TestSettingScrapeFallbackProtocolInPodMonitor(t *testing.T) {
for _, tc := range []struct {
name string
version string
scrapeFallbackProtocol *monitoringv1.ScrapeProtocol
golden string
}{
{
name: "setting ScrapeFallbackProtocol in PodMonitor with prometheus old version",
version: "v2.55.0",
scrapeFallbackProtocol: ptr.To(monitoringv1.OpenMetricsText0_0_1),
golden: "SettingScrapeFallbackProtocolInPodMonitor_OldVersion.golden",
},
{
name: "setting ScrapeFallbackProtocol in PodMonitor with prometheus new version",
version: "v3.0.0",
scrapeFallbackProtocol: ptr.To(monitoringv1.OpenMetricsText1_0_0),
golden: "SettingScrapeFallbackProtocolInPodMonitor_NewVersion.golden",
},
} {
t.Run(tc.name, func(t *testing.T) {
p := defaultPrometheus()
p.Spec.CommonPrometheusFields.Version = tc.version
cg := mustNewConfigGenerator(t, p)
cfg, err := cg.GenerateServerConfiguration(
p,
nil,
map[string]*monitoringv1.PodMonitor{
"testpodmonitor1": {
ObjectMeta: metav1.ObjectMeta{
Name: "testpodmonitor1",
Namespace: "default",
},
Spec: monitoringv1.PodMonitorSpec{
PodTargetLabels: []string{"example", "env"},
ScrapeFallbackProtocol: tc.scrapeFallbackProtocol,
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{
{
TrackTimestampsStaleness: ptr.To(false),
Port: "web",
Interval: "30s",
},
},
},
},
},
nil,
nil,
&assets.StoreBuilder{},
nil,
nil,
nil,
nil,
)
require.NoError(t, err)
golden.Assert(t, string(cfg), tc.golden)
})
}
}
func TestHonorTimestampsOverriding(t *testing.T) {
p := defaultPrometheus()
p.Spec.CommonPrometheusFields.OverrideHonorTimestamps = true
@ -5960,6 +6100,22 @@ func TestScrapeConfigSpecConfig(t *testing.T) {
},
golden: "ScrapeConfigSpecConfig_ScrapeProtocols.golden",
},
{
name: "fallback_scrape_protocol",
version: "v3.0.0",
scSpec: monitoringv1alpha1.ScrapeConfigSpec{
ScrapeFallbackProtocol: ptr.To(monitoringv1.OpenMetricsText1_0_0),
},
golden: "ScrapeConfigSpecConfig_ScrapeFallbackProtocol.golden",
},
{
name: "fallback_scrape_protocol_with_unsupported_version",
version: "v2.55.0",
scSpec: monitoringv1alpha1.ScrapeConfigSpec{
ScrapeFallbackProtocol: ptr.To(monitoringv1.OpenMetricsText1_0_0),
},
golden: "ScrapeConfigSpecConfig_ScrapeFallbackProtocol_OldVersion.golden",
},
{
name: "non_empty_metric_relabel_config",
scSpec: monitoringv1alpha1.ScrapeConfigSpec{

View file

@ -0,0 +1,13 @@
global:
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs:
- job_name: scrapeConfig/default/testscrapeconfig1
fallback_scrape_protocol: OpenMetricsText1.0.0
relabel_configs:
- source_labels:
- job
target_label: __tmp_prometheus_job_name

View file

@ -0,0 +1,12 @@
global:
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs:
- job_name: scrapeConfig/default/testscrapeconfig1
relabel_configs:
- source_labels:
- job
target_label: __tmp_prometheus_job_name

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/testpodmonitor1/0
honor_labels: false
track_timestamps_staleness: 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_container_port_name
regex: web
- 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
- source_labels:
- __meta_kubernetes_pod_label_example
target_label: example
regex: (.+)
replacement: ${1}
- source_labels:
- __meta_kubernetes_pod_label_env
target_label: env
regex: (.+)
replacement: ${1}
- target_label: job
replacement: default/testpodmonitor1
- target_label: endpoint
replacement: web
- source_labels:
- __address__
target_label: __tmp_hash
modulus: 1
action: hashmod
- source_labels:
- __tmp_hash
regex: $(SHARD)
action: keep
fallback_scrape_protocol: OpenMetricsText1.0.0

View file

@ -0,0 +1,60 @@
global:
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs:
- job_name: podMonitor/default/testpodmonitor1/0
honor_labels: false
track_timestamps_staleness: 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_container_port_name
regex: web
- 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
- source_labels:
- __meta_kubernetes_pod_label_example
target_label: example
regex: (.+)
replacement: ${1}
- source_labels:
- __meta_kubernetes_pod_label_env
target_label: env
regex: (.+)
replacement: ${1}
- target_label: job
replacement: default/testpodmonitor1
- target_label: endpoint
replacement: web
- source_labels:
- __address__
target_label: __tmp_hash
modulus: 1
action: hashmod
- source_labels:
- __tmp_hash
regex: $(SHARD)
action: keep

View file

@ -0,0 +1,80 @@
global:
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs:
- job_name: serviceMonitor/default/testservicemonitor1/0
honor_labels: false
honor_timestamps: false
kubernetes_sd_configs:
- role: endpoints
namespaces:
names:
- default
scrape_interval: 30s
relabel_configs:
- source_labels:
- job
target_label: __tmp_prometheus_job_name
- action: keep
source_labels:
- __meta_kubernetes_endpoint_port_name
regex: web
- source_labels:
- __meta_kubernetes_endpoint_address_target_kind
- __meta_kubernetes_endpoint_address_target_name
separator: ;
regex: Node;(.*)
replacement: ${1}
target_label: node
- source_labels:
- __meta_kubernetes_endpoint_address_target_kind
- __meta_kubernetes_endpoint_address_target_name
separator: ;
regex: Pod;(.*)
replacement: ${1}
target_label: pod
- source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- source_labels:
- __meta_kubernetes_service_name
target_label: service
- source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- action: drop
source_labels:
- __meta_kubernetes_pod_phase
regex: (Failed|Succeeded)
- source_labels:
- __meta_kubernetes_service_label_example
target_label: example
regex: (.+)
replacement: ${1}
- source_labels:
- __meta_kubernetes_service_label_env
target_label: env
regex: (.+)
replacement: ${1}
- source_labels:
- __meta_kubernetes_service_name
target_label: job
replacement: ${1}
- target_label: endpoint
replacement: web
- source_labels:
- __address__
target_label: __tmp_hash
modulus: 1
action: hashmod
- source_labels:
- __tmp_hash
regex: $(SHARD)
action: keep
fallback_scrape_protocol: OpenMetricsText0.0.1

View file

@ -0,0 +1,79 @@
global:
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs:
- job_name: serviceMonitor/default/testservicemonitor1/0
honor_labels: false
honor_timestamps: false
kubernetes_sd_configs:
- role: endpoints
namespaces:
names:
- default
scrape_interval: 30s
relabel_configs:
- source_labels:
- job
target_label: __tmp_prometheus_job_name
- action: keep
source_labels:
- __meta_kubernetes_endpoint_port_name
regex: web
- source_labels:
- __meta_kubernetes_endpoint_address_target_kind
- __meta_kubernetes_endpoint_address_target_name
separator: ;
regex: Node;(.*)
replacement: ${1}
target_label: node
- source_labels:
- __meta_kubernetes_endpoint_address_target_kind
- __meta_kubernetes_endpoint_address_target_name
separator: ;
regex: Pod;(.*)
replacement: ${1}
target_label: pod
- source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- source_labels:
- __meta_kubernetes_service_name
target_label: service
- source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- action: drop
source_labels:
- __meta_kubernetes_pod_phase
regex: (Failed|Succeeded)
- source_labels:
- __meta_kubernetes_service_label_example
target_label: example
regex: (.+)
replacement: ${1}
- source_labels:
- __meta_kubernetes_service_label_env
target_label: env
regex: (.+)
replacement: ${1}
- source_labels:
- __meta_kubernetes_service_name
target_label: job
replacement: ${1}
- target_label: endpoint
replacement: web
- source_labels:
- __address__
target_label: __tmp_hash
modulus: 1
action: hashmod
- source_labels:
- __tmp_hash
regex: $(SHARD)
action: keep

View file

@ -0,0 +1,8 @@
global:
scrape_interval: 30s
fallback_scrape_protocol: PrometheusText1.0.0
external_labels:
prometheus: test/example
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs: []

View file

@ -0,0 +1,7 @@
global:
scrape_interval: 30s
external_labels:
prometheus: test/example
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs: []

View file

@ -1778,6 +1778,27 @@ var ScrapeConfigCRDTestCases = []scrapeCRDTestCase{
},
expectedError: false,
},
{
name: "ScrapeFallbackProtocol: Valid Value",
scrapeConfigSpec: monitoringv1alpha1.ScrapeConfigSpec{
ScrapeFallbackProtocol: ptr.To(monitoringv1.OpenMetricsText0_0_1),
},
expectedError: false,
},
{
name: "ScrapeFallbackProtocol: Invalid Protocol",
scrapeConfigSpec: monitoringv1alpha1.ScrapeConfigSpec{
ScrapeFallbackProtocol: ptr.To(monitoringv1.ScrapeProtocol("InvalidProtocol")),
},
expectedError: true,
},
{
name: "ScrapeFallbackProtocol: Setting nil",
scrapeConfigSpec: monitoringv1alpha1.ScrapeConfigSpec{
ScrapeFallbackProtocol: nil,
},
expectedError: false,
},
}
var staticConfigTestCases = []scrapeCRDTestCase{