2013-02-22 12:07:35 -08:00
|
|
|
// Copyright 2013 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/prometheus/prometheus/model"
|
|
|
|
"github.com/prometheus/prometheus/retrieval"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TargetGroup struct {
|
|
|
|
Endpoints []string `json:"endpoints"`
|
|
|
|
BaseLabels map[string]string `json:"baseLabels"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (serv MetricsService) SetTargets(targetGroups []TargetGroup, jobName string) {
|
2013-05-05 10:32:04 -07:00
|
|
|
job := serv.Config.GetJobByName(jobName)
|
|
|
|
if job == nil {
|
2013-02-22 12:07:35 -08:00
|
|
|
rb := serv.ResponseBuilder()
|
|
|
|
rb.SetResponseCode(http.StatusNotFound)
|
2013-05-05 10:32:04 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
newTargets := []retrieval.Target{}
|
|
|
|
|
|
|
|
for _, targetGroup := range targetGroups {
|
|
|
|
// Do mandatory map type conversion due to Go shortcomings.
|
|
|
|
baseLabels := model.LabelSet{
|
|
|
|
model.JobLabel: model.LabelValue(job.GetName()),
|
|
|
|
}
|
|
|
|
for label, value := range targetGroup.BaseLabels {
|
|
|
|
baseLabels[model.LabelName(label)] = model.LabelValue(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, endpoint := range targetGroup.Endpoints {
|
|
|
|
newTarget := retrieval.NewTarget(endpoint, time.Second*5, baseLabels)
|
|
|
|
newTargets = append(newTargets, newTarget)
|
2013-02-22 12:07:35 -08:00
|
|
|
}
|
|
|
|
}
|
2013-05-05 10:32:04 -07:00
|
|
|
|
|
|
|
// BUG(julius): Validate that this ScrapeInterval is in fact the proper one
|
|
|
|
// for the job.
|
2013-06-11 08:54:58 -07:00
|
|
|
serv.TargetManager.ReplaceTargets(*job, newTargets)
|
2013-02-22 12:07:35 -08:00
|
|
|
}
|