Skip to content

Commit d1d5024

Browse files
committed
api: adds scrapeTimeout - global configuration for vmagent
1 parent 908a477 commit d1d5024

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

api/v1beta1/vmagent_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ type VMAgentSpec struct {
134134
// +optional
135135
// +kubebuilder:validation:Pattern:="[0-9]+(ms|s|m|h)"
136136
ScrapeInterval string `json:"scrapeInterval,omitempty"`
137+
// ScrapeTimeout defines global timeout for targets scrape
138+
// +optional
139+
// +kubebuilder:validation:Pattern:="[0-9]+(ms|s|m|h)"
140+
ScrapeTimeout string `json:"scrapeTimeout,omitempty"`
137141

138142
// APIServerConfig allows specifying a host and auth methods to access apiserver.
139143
// If left empty, VMAgent is assumed to run inside of the cluster

api/v1beta1/vmservicescrape_types.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v1beta1
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"reflect"
67

@@ -390,6 +391,29 @@ type RelabelConfig struct {
390391
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
391392
}
392393

394+
// UnmarshalJSON implements interface
395+
// handles cases for snake and camel cases of json tags
396+
func (rc *RelabelConfig) UnmarshalJSON(src []byte) error {
397+
type rcfg RelabelConfig
398+
if err := json.Unmarshal(src, (*rcfg)(rc)); err != nil {
399+
return fmt.Errorf("cannot parse relabelConfig: %w", err)
400+
}
401+
402+
if len(rc.SourceLabels) == 0 && len(rc.UnderScoreSourceLabels) > 0 {
403+
rc.SourceLabels = append(rc.SourceLabels, rc.UnderScoreSourceLabels...)
404+
}
405+
if len(rc.UnderScoreSourceLabels) == 0 && len(rc.SourceLabels) > 0 {
406+
rc.UnderScoreSourceLabels = append(rc.UnderScoreSourceLabels, rc.SourceLabels...)
407+
}
408+
if rc.TargetLabel == "" && rc.UnderScoreTargetLabel != "" {
409+
rc.TargetLabel = rc.UnderScoreTargetLabel
410+
}
411+
if rc.UnderScoreTargetLabel == "" && rc.TargetLabel != "" {
412+
rc.UnderScoreTargetLabel = rc.TargetLabel
413+
}
414+
return nil
415+
}
416+
393417
func (rc *RelabelConfig) IsEmpty() bool {
394418
if rc == nil {
395419
return true

config/crd/bases/operator.victoriametrics.com_vmagents.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,6 +2305,10 @@ spec:
23052305
description: ScrapeInterval defines how often scrape targets by default
23062306
pattern: '[0-9]+(ms|s|m|h)'
23072307
type: string
2308+
scrapeTimeout:
2309+
description: ScrapeTimeout defines global timeout for targets scrape
2310+
pattern: '[0-9]+(ms|s|m|h)'
2311+
type: string
23082312
secrets:
23092313
description: Secrets is a list of Secrets in the same namespace as
23102314
the vmagent object, which shall be mounted into the vmagent Pods.

0 commit comments

Comments
 (0)