github.com/kiali/kiali@v1.84.0/graph/telemetry/istio/appender/util.go (about) 1 package appender 2 3 import ( 4 "context" 5 "fmt" 6 "strings" 7 "time" 8 9 prom_v1 "github.com/prometheus/client_golang/api/prometheus/v1" 10 "github.com/prometheus/common/model" 11 12 "github.com/kiali/kiali/graph" 13 "github.com/kiali/kiali/graph/telemetry/istio/util" 14 "github.com/kiali/kiali/log" 15 "github.com/kiali/kiali/prometheus/internalmetrics" 16 ) 17 18 // package-private util functions (used by multiple files) 19 20 func promQuery(query string, queryTime time.Time, ctx context.Context, api prom_v1.API, a graph.Appender) model.Vector { 21 if query == "" { 22 return model.Vector{} 23 } 24 25 // add scope if necessary 26 query = util.AddQueryScope(query) 27 28 // wrap with a round() to be in line with metrics api 29 query = fmt.Sprintf("round(%s,0.001)", query) 30 log.Tracef("Appender query:\n%s&time=%v (now=%v, %v)\n", query, queryTime.Format(graph.TF), time.Now().Format(graph.TF), queryTime.Unix()) 31 32 promtimer := internalmetrics.GetPrometheusProcessingTimePrometheusTimer("Graph-Appender-" + a.Name()) 33 value, warnings, err := api.Query(ctx, query, queryTime) 34 if len(warnings) > 0 { 35 log.Warningf("promQuery. Prometheus Warnings: [%s]", strings.Join(warnings, ",")) 36 } 37 graph.CheckUnavailable(err) 38 promtimer.ObserveDuration() // notice we only collect metrics for successful prom queries 39 40 switch t := value.Type(); t { 41 case model.ValVector: // Instant Vector 42 return value.(model.Vector) 43 default: 44 graph.Error(fmt.Sprintf("No handling for type %v!\n", t)) 45 } 46 47 return nil 48 }