0

I am trying to use this API endpoint here: https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/tail

But it does not seem to work as documented:

curl -s \
    -H 'authorization: Bearer x' \
    -H 'accept: application/json' \
    -H 'content-type: application/json' \
    --data-binary '{"resourceNames":["projects/del-test-x"]}' \
    --compressed 'https://logging.googleapis.com/v2/entries:tail'
[{
  "error": {
    "code": 400,
    "message": "Invalid value (Object), ",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid value (Object), "
          }
        ]
      }
    ]
  }
}
]

Is there an issue with the API?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
zino
  • 1,222
  • 2
  • 17
  • 47
  • Note: `--data '[{"resourceNames":["projects/del-test-x"]}]' ` works (wrapped in array), but only ever returns a blank array. In the GPRC service here: https://github.com/googleapis/googleapis/blob/master/google/logging/v2/logging.proto#L126, both request and response are `stream`, which I think does not support HTTP/JSON – zino Jul 25 '23 at 18:11
  • 1
    Interesting question. I'm able to repro your error. Generally, when the underlying API is unclear, I use the `gcloud` `--log-http` flag to see what `gcloud` does. In this instance [`gcloud alpha logging tail --log-http`](https://cloud.google.com/sdk/gcloud/reference/alpha/logging/tail), appears to use the underlying gRPC method but I'm unable to get that to work either. – DazWilkin Jul 26 '23 at 16:15
  • 1
    I'll leave you to fill in the blanks but e.g. `grpcurl -vv -H "Authorization: Bearer ${TOKEN}" --import-path=${ROOT} --proto=${ROOT}/google/logging/v2/logging.proto -d "{\"resource_names\":[\"projects/${PROJECT}\"]}" logging.googleapis.com:443 google.logging.v2.LoggingServiceV2/TailLogEntries`. `ROOT` refers to a clone of [`googleapis`](https://github.com/googleapis/googleapis) as this includes the protobuf defs for Google APIs and `TOKEN=$(gcloud auth print-access-token)`. I'd expect this command to block on the returned response stream. I'm unable to reproduce the behavior of `gcloud`. – DazWilkin Jul 26 '23 at 16:18
  • 1
    Aha! One flaw with my gRPCurl approach is that the request is a stream too which may be my mistake. Trying with a request stream. – DazWilkin Jul 26 '23 at 16:50

1 Answers1

1

Im not sure but try it like this let me know if it works or not.

curl --request POST \
  'https://logging.googleapis.com/v2/entries:tail' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"resourceNames":["projects/del-test-x"]}' \
  --compressed

its just the --data-binary vs --data that i think is off.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449