Пример #1
0
func (config *GlobalConfig) SetOption(option string, value string) (err error) {
	switch option {
	case "scrape_interval":
		config.ScrapeInterval, err = utility.StringToDuration(value)
		return nil
	case "evaluation_interval":
		config.EvaluationInterval, err = utility.StringToDuration(value)
		return err
	default:
		err = fmt.Errorf("Unrecognized global configuration option '%v'", option)
	}
	return
}
Пример #2
0
// stringToDuration converts a string to a duration and dies on invalid format.
func stringToDuration(intervalStr string) time.Duration {
	duration, err := utility.StringToDuration(intervalStr)
	if err != nil {
		panic(err)
	}
	return duration
}
Пример #3
0
// Validate checks an entire parsed Config for the validity of its fields.
func (c Config) Validate() error {
	// Check the global configuration section for validity.
	global := c.Global
	if _, err := utility.StringToDuration(global.GetScrapeInterval()); err != nil {
		return fmt.Errorf("Invalid global scrape interval: %s", err)
	}
	if _, err := utility.StringToDuration(global.GetEvaluationInterval()); err != nil {
		return fmt.Errorf("Invalid rule evaluation interval: %s", err)
	}
	if err := c.validateLabels(global.Labels); err != nil {
		return fmt.Errorf("Invalid global labels: %s", err)
	}

	// Check each job configuration for validity.
	jobNames := map[string]bool{}
	for _, job := range c.Job {
		if jobNames[job.GetName()] {
			return fmt.Errorf("Found multiple jobs configured with the same name: '%s'", job.GetName())
		}
		jobNames[job.GetName()] = true

		if !jobNameRE.MatchString(job.GetName()) {
			return fmt.Errorf("Invalid job name '%s'", job.GetName())
		}
		if _, err := utility.StringToDuration(job.GetScrapeInterval()); err != nil {
			return fmt.Errorf("Invalid scrape interval for job '%s': %s", job.GetName(), err)
		}
		if _, err := utility.StringToDuration(job.GetSdRefreshInterval()); err != nil {
			return fmt.Errorf("Invalid SD refresh interval for job '%s': %s", job.GetName(), err)
		}
		if _, err := utility.StringToDuration(job.GetScrapeTimeout()); err != nil {
			return fmt.Errorf("Invalid scrape timeout for job '%s': %s", job.GetName(), err)
		}
		for _, targetGroup := range job.TargetGroup {
			if err := c.validateLabels(targetGroup.Labels); err != nil {
				return fmt.Errorf("Invalid labels for job '%s': %s", job.GetName(), err)
			}
		}
		if job.SdName != nil && len(job.TargetGroup) > 0 {
			return fmt.Errorf("Specified both DNS-SD name and target group for job: %s", job.GetName())
		}
	}

	return nil
}
Пример #4
0
// Constructs a new sdTargetProvider for a job.
func NewSdTargetProvider(job config.JobConfig) *sdTargetProvider {
	i, err := utility.StringToDuration(job.GetSdRefreshInterval())
	if err != nil {
		panic(fmt.Sprintf("illegal refresh duration string %s: %s", job.GetSdRefreshInterval(), err))
	}
	return &sdTargetProvider{
		job:             job,
		refreshInterval: i,
	}
}
Пример #5
0
func CreateAlertingRule(name string, expr ast.Node, holdDurationStr string, labels clientmodel.LabelSet, summary string, description string) (*AlertingRule, error) {
	if _, ok := expr.(ast.VectorNode); !ok {
		return nil, fmt.Errorf("Alert rule expression %v does not evaluate to vector type", expr)
	}
	holdDuration, err := utility.StringToDuration(holdDurationStr)
	if err != nil {
		return nil, err
	}
	return NewAlertingRule(name, expr.(ast.VectorNode), holdDuration, labels, summary, description), nil
}
Пример #6
0
func (job *JobConfig) SetOption(option string, value string) (err error) {
	switch option {
	case "name":
		job.Name = value
	case "scrape_interval":
		job.ScrapeInterval, err = utility.StringToDuration(value)
	default:
		err = fmt.Errorf("Unrecognized job configuration option '%v'", option)
	}
	return
}
Пример #7
0
func NewMatrix(vector ast.Node, intervalStr string) (ast.MatrixNode, error) {
	switch vector.(type) {
	case *ast.VectorLiteral:
		{
			break
		}
	default:
		return nil, fmt.Errorf("Intervals are currently only supported for vector literals.")
	}
	interval, err := utility.StringToDuration(intervalStr)
	if err != nil {
		return nil, err
	}
	vectorLiteral := vector.(*ast.VectorLiteral)
	return ast.NewMatrixLiteral(vectorLiteral, interval), nil
}