Comments (5)
@veggiemonk Thank you for the link to the incorrect type. This is helpful, I will continue to investigate.
from google-api-go-client.
By forming the query manually it works:
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"path"
"testing"
"time"
monv1 "google.golang.org/api/monitoring/v1"
"google.golang.org/api/option"
apihttp "google.golang.org/api/transport/http"
)
func main() {
fmt.Println("Hello, δΈη")
}
const projectID = "XXX"
func TestPromMetrics(t *testing.T) {
opts := []option.ClientOption{
option.WithScopes("https://www.googleapis.com/auth/monitoring.read"),
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
targetx := fmt.Sprintf("https://monitoring.googleapis.com/v1/projects/%s/location/global/prometheus", projectID)
transport, err := apihttp.NewTransport(ctx, http.DefaultTransport, opts...)
if err != nil {
t.Fatal("create HTTP transport", "err", err)
}
client := http.Client{Transport: transport}
u, err := url.Parse(targetx)
if err != nil {
t.Fatal("parse target URL", "err", err)
}
u.Path = path.Join(u.Path, "/api/v1/query_range")
q := &monv1.QueryRangeRequest{
Query: "up",
Start: time.Now().UTC().Add(-5 * time.Minute).Format(time.RFC3339),
End: time.Now().UTC().Format(time.RFC3339),
Step: "60s",
Timeout: "60s",
// ForceSendFields: nil,
// NullFields: nil,
}
body, err := json.Marshal(q)
if err != nil {
t.Fatal("marshal query", "err", err)
}
newReq, err := http.NewRequestWithContext(ctx, http.MethodPost, u.String(), bytes.NewReader(body))
resp, err := client.Do(newReq)
if err != nil {
t.Fatal("do request", "err", err)
}
defer resp.Body.Close()
res, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal("read response", "err", err)
}
t.Log(string(res))
}
from google-api-go-client.
Thank you for reporting this issue.
I couldn't find an example on how to query Google Managed Prometheus programmatically.
I looked through the samples in https://github.com/GoogleCloudPlatform/golang-samples/tree/main/monitoring but couldn't find anything for queries.
from google-api-go-client.
Thank you for providing the manual workaround.
Question: Can https://pkg.go.dev/cloud.google.com/go/monitoring be used for this use case?
Unfortunately, due to the maintenance mode status of this project, I won't be able to prioritize reproducing this issue right now. If you can still reproduce it, can you by any chance provide a deeper analysis of where the json
error is occurring in the client library and what the fix might be?
from google-api-go-client.
Question: Can https://pkg.go.dev/cloud.google.com/go/monitoring be used for this use case?
That package is for dealing with metrics stored in Cloud Operations as far as I understood. The metrics I used are store in Google Managed Prometheus which, apparently, is a different APIs.
can you by any chance provide a deeper analysis of where the
json
error is occurring in the client library and what the fix might be?
The error occurs because the Data
field of HttpBody
of type string which cause decoding JSON to fail while the request has succeeded (status 200). See https://github.com/googleapis/google-api-go-client/blob/main/monitoring/v1/monitoring-gen.go#L1518
The field should be of type []byte
as the error states:
json: cannot unmarshal object into Go struct field HttpBody.data of type string
That's the fix as far as I can tell.
from google-api-go-client.
Related Issues (20)
- Missing ISS and IAT validation of IAP tokens in idtoken.Validate HOT 1
- google.golang.org/api/internal/examples/fake: TestTranslateText failed HOT 3
- Full text search doesn't work when using 'in parents' option HOT 1
- How does Google define private APIs? HOT 2
- Missing path element of analyticsdata URL endpoint HOT 3
- Business Profile APIs is missing endpoints for Listing Reviews HOT 3
- Firebase Remote Config Project Not Found HOT 2
- androidpublisher: missing TargetingRuleScope fields HOT 2
- Where is the authorization code if the page returns 404 SOLVED
- Error 400: Invalid Value, invalid HOT 2
- androidpublisher/v3 - nondeterministic failure to create subscription with offer HOT 2
- g
- option.WithCredentialsJSON incompatible with option.WithHTTPClient HOT 10
- Proxy sheets.NewService and oauth2 HOT 3
- sqladmin: Instance Patch command does not modify deletetionProtectionEnabled HOT 2
- maxResults option is not being respected by channel list endpoint HOT 2
- google.golang.org/api/idtoken: TestNewClient_WithCredentialFile failed HOT 1
- google.golang.org/api/integration-tests/downscope: TestDownscopedToken failed HOT 1
- SafeBrowsing v5 only supports alt=proto HOT 5
- Import broken when using only androidpublisher/v3 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-api-go-client.