当用户发送 reload命令时 curl -vvv -X POST localhost:9090/-/reload
调用ruleManager.Update更新 rule.yml和record.yml配置
{
name:"rules",
reloader:func(cfg *config.Config)error{// Get all rule files matching the configuration paths.var files []stringfor_, pat :=range cfg.RuleFiles {
fs, err := filepath.Glob(pat)if err !=nil{// The only error can be a bad pattern.return errors.Wrapf(err,"error retrieving rule files for %s", pat)}
files =append(files, fs...)}return ruleManager.Update(
time.Duration(cfg.GlobalConfig.EvaluationInterval),
files,
cfg.GlobalConfig.ExternalLabels,
externalURL,)},
// Eval evaluates the rule and then overrides the metric names and labels accordingly.func(rule *RecordingRule)Eval(ctx context.Context, ts time.Time, query QueryFunc,_*url.URL)(promql.Vector,error){
vector, err :=query(ctx, rule.vector.String(), ts)if err !=nil{returnnil, err
}// Override the metric name and labels.for i :=range vector {
sample :=&vector[i]
lb := labels.NewBuilder(sample.Metric)
lb.Set(labels.MetricName, rule.name)for_, l :=range rule.labels {
lb.Set(l.Name, l.Value)}
sample.Metric = lb.Labels()}// Check that the rule does not produce identical metrics after applying// labels.if vector.ContainsSameLabelset(){
err = fmt.Errorf("vector contains metrics with the same labelset after applying rule labels")
rule.SetHealth(HealthBad)
rule.SetLastError(err)returnnil, err
}
rule.SetHealth(HealthGood)
rule.SetLastError(err)return vector,nil}
底层调用的instant query查询一个点
使用rule中配置的record作为新的series的name,并设置标签
标签来自于两个部分
一个是查询的结果标签,比如sum by instance 那就会有一个instance标签 或者 avg by code,verb 就会有code和verb的标签
第二是rule中配置的标签
lb.Set(labels.MetricName, rule.name)for_, l :=range rule.labels {
lb.Set(l.Name, l.Value)}
1.平台证书及平台证书序列号设置错误报错:
错误1:
Verify the response’s data with: timestamp1735184656, noncea5806b8cabc923299f8db1a174f3a4d0, signatureFZ5FgD/jtt4J99GKssKWKA/0buBSOAbWcu6H52l2UqqaJKvrsNxvodB569ZFz5G3fbassOQcSh5BFq6hvE…