client_golang icon indicating copy to clipboard operation
client_golang copied to clipboard

How to parse the query result, it seems like only provides Type and String

Open wmf508 opened this issue 3 years ago • 1 comments

I want to iterator result from query, but it's a string, so, i need to handle it by myself?

`result, warnings, err := cli.api.Query(context.TODO(), "kube_node_status_condition{condition="Ready"}", time.Now()) if warnings != nil { log.Printf("warning: %v", warnings) }

if err != nil {
	log.Printf("warning: %v", err)
}

log.Printf("result: %v", result)`

wmf508 avatar Mar 19 '22 14:03 wmf508

You need to cast result to model.Vector (https://pkg.go.dev/github.com/prometheus/common/model#Vector) for instant queries or model.Matrix (https://pkg.go.dev/github.com/prometheus/common/model#Matrix) for range queries.

result, warnings, err := cli.api.Query(...)
for _, sample := range result.(model.Vector) {
  ...
}

prymitive avatar Mar 27 '22 14:03 prymitive

Hello 👋 Looks like there was no activity on this issue for the last 3 months. Do you mind updating us on the status? Is this still reproducible or needed? If yes, just comment on this PR or push a commit. Thanks! 🤗 If there will be no activity in the next 4 weeks, this issue will be closed (we can always reopen an issue if we need!).

stale[bot] avatar Oct 16 '22 05:10 stale[bot]

Closing for now as promised, let us know if you need this to be reopened! 🤗

stale[bot] avatar Jan 21 '23 22:01 stale[bot]