Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCS external image upload error response status code 404 #26194

Closed
puzzloholic opened this issue Jul 9, 2020 · 2 comments · Fixed by #26493
Closed

GCS external image upload error response status code 404 #26194

puzzloholic opened this issue Jul 9, 2020 · 2 comments · Fixed by #26493
Labels
area/image-rendering area/imagestore beginner friendly effort/small help wanted needs investigation for unconfirmed bugs. use type/bug for confirmed bugs, even if they "need" more investigating type/bug

Comments

@puzzloholic
Copy link

puzzloholic commented Jul 9, 2020

What happened:
I am using GCS for external image storage solution. I already mount required key_file json. No file is uploaded when alert is triggered, and log states that GCS response is 404

t=2020-07-09T07:30:45+0000 lvl=dbug msg="Rendered alert panel image" logger=alerting.notifier ruleId=6 path=/var/lib/grafana/png/PaICSdwfoqdYUnOa6DkM.png took=4.289621693s
t=2020-07-09T07:30:45+0000 lvl=dbug msg="Uploading alert panel image to external image store" logger=alerting.notifier ruleId=6 path=/var/lib/grafana/png/PaICSdwfoqdYUnOa6DkM.png
t=2020-07-09T07:30:45+0000 lvl=dbug msg="Opening key file " logger=gcsuploader /etc/secrets/<REDACTED>.json=nil LOG15_ERROR="Normalized odd number of arguments by adding nil"
t=2020-07-09T07:30:45+0000 lvl=dbug msg="Creating JWT conf" logger=gcsuploader
t=2020-07-09T07:30:45+0000 lvl=dbug msg="Creating HTTP client" logger=gcsuploader
t=2020-07-09T07:30:45+0000 lvl=dbug msg="Opening image file " logger=gcsuploader /var/lib/grafana/png/PaICSdwfoqdYUnOa6DkM.png=nil LOG15_ERROR="Normalized odd number of arguments by adding nil"
t=2020-07-09T07:30:45+0000 lvl=dbug msg="Request URL: " logger=gcsuploader https://www.googleapis.com/upload/storage/v1/b/<REDACTED>/o?uploadType=media&name=uJ0fW2e0UqOZ5Q51hp3C.png&predefinedAcl=publicRead=nil LOG15_ERROR="Normalized odd number of arguments by adding nil"
t=2020-07-09T07:30:45+0000 lvl=dbug msg="Sending POST request to GCS" logger=gcsuploader
t=2020-07-09T07:30:45+0000 lvl=eror msg="Failed to render and upload alert panel image." logger=alerting.notifier ruleId=6 error="GCS response status code 404"

What you expected to happen:
Image is uploaded to GCS every time alert triggers.

How to reproduce it (as minimally and precisely as possible):

  • Create k8s Secret for the GCP SA key
apiVersion: v1
kind: Secret
metadata:
  name: secret-name
stringData:
  your-key-file.json: |-
    {
        "type": "service_account",
        ...
    }
image:
  repository: grafana/grafana
  tag: 7.0.3
extraSecretMounts:
- name: secret-files
  mountPath: /etc/secrets
  secretName: secret-name
  readOnly: true
  subPath: ""
grafana.ini:
  external_image_storage:
    provider: gcs
  external_image_storage.gcs:
    key_file: /etc/secrets/your-key-file.json
    bucket: your-gcs-bucket
  • Try to config and trigger an alarm that will upload image file to GCS

Anything else we need to know?:
Official GCP Documentation states this is the API for uploading file to GCS.

curl -X POST --data-binary @[OBJECT_LOCATION] \
-H "Authorization: Bearer [OAUTH2_TOKEN]" \
-H "Content-Type: [OBJECT_CONTENT_TYPE]" \
"https://storage.googleapis.com/upload/storage/v1/b/[BUCKET_NAME]/o?uploadType=media&name=[OBJECT_NAME]"

Apparently there is changes in the endpoint at some time

This is the line that defines the URL

uploadUrl string = "https://www.googleapis.com/upload/storage/v1/b/%s/o?uploadType=media&name=%s&predefinedAcl=publicRead"

Environment:

  • Grafana version: Grafana v7.0.3 (00ee734)
  • Others: Helm Stable Grafana Deployed on GKE Cluster
@torkelo torkelo added type/bug area/image-rendering area/imagestore needs investigation for unconfirmed bugs. use type/bug for confirmed bugs, even if they "need" more investigating effort/small help wanted beginner friendly labels Jul 10, 2020
@gastonqiu
Copy link
Contributor

gastonqiu commented Jul 21, 2020

I propose to do fileUploader with gcp go sdk instead of http request. https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-code-sample

@gastonqiu
Copy link
Contributor

@puzzloholic I patch a new version by using GKE SDK but I'm not so sure about how to use this. Is it possible to help me on testing it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/image-rendering area/imagestore beginner friendly effort/small help wanted needs investigation for unconfirmed bugs. use type/bug for confirmed bugs, even if they "need" more investigating type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants