Question: How do I skip the expiry on a headless server?
Opened this issue · 6 comments
As advised in the READ.ME I have created the login_cookie.dat on my local Windows host (with internet). I moved that file to the headless linux server where I want to run the docker container. It's working for 1 hour, then the file is expired. How do I prevent expiry?
login_cookie.dat
{
"token": "[[very-long-token]]"
, "refresh_token": "[[long-token]]"
, "token_uri": "https://oauth2.googleapis.com/token"
, "client_id": "[[ID]].apps.googleusercontent.com"
, "client_secret": "[[secret]]"
, "scopes": "https://www.googleapis.com/auth/gmail.readonly "
, "expiry": "2023-08-24T10:59:26.026612Z"
}
client_secret.json
{"web":
{
"client_id":"[[ID]].apps.googleusercontent.com"
,"project_id":"mailbox"
,"auth_uri":"https://accounts.google.com/o/oauth2/auth"
,"token_uri":"https://oauth2.googleapis.com/token"
,"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs"
,"client_secret":"[[secret]]"
}
}
Linux Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-156-generic x86_64)
docker run -d -p 9117:8080 \
-v /etc/gmail/:/root/.prometheus-gmail-exporter/ \
--restart unless-stopped \
--network prometheusnet \
--name gmail-exporter gmail-exporter:latest \
--updateDelaySeconds 60 \
--daemonize \
--labels INBOX
Logfile after 1 hour shows:
INFO:root:Updating gmail metrics - started
INFO:google_auth_httplib2:Refreshing credentials due to a 401 response. Attempt 1/2.
ERROR:root:Error: ('invalid_scope: Some requested scopes were invalid. {invalid=[a, c, d, e, g, h, i, l, m, ., n, /, o, p, r, s, t, u, w, y, :]}', {'error': 'invalid_scope', 'error_description': 'Some requested scopes were invalid. {invalid=[a, c, d, e, g, h, i, l, m, ., n, /, o, p, r, s, t, u, w, y, :]}', 'error_uri': 'https://developers.google.com/identity/protocols/oauth2'})
INFO:root:Updating gmail metrics - complete
I'm probably missing a simple step, can you help me out? :)
On a 401 would also be nice to delete metrics and stop exporting (outdated) values to Prometheus, so that we can notice this is happening from the graph.
For me it works barely for 20 minutes after authentication. :(
[2024-05-14 12:21:58] INFO:googleapiclient.discovery_cache:file_cache is only supported with oauth2client<4.0.0
[2024-05-14 12:21:58] INFO:root:Got gmail client successfully
[2024-05-14 12:21:58] INFO:root:Prometheus started on port 9137
[2024-05-14 12:21:58] INFO:root:Updating gmail metrics - started
[2024-05-14 12:21:58] INFO:root:Getting metadata about labels
[2024-05-14 12:21:58] INFO:root:Using labels: ['INBOX']
[2024-05-14 12:21:58] INFO:root:Updating gmail metrics - complete
[2024-05-14 12:31:58] INFO:root:Updating gmail metrics - started
[2024-05-14 12:31:59] INFO:root:Updating gmail metrics - complete
[2024-05-14 12:41:59] INFO:root:Updating gmail metrics - started
[2024-05-14 12:42:00] INFO:root:Updating gmail metrics - complete
[2024-05-14 12:52:00] INFO:root:Updating gmail metrics - started
[2024-05-14 12:52:00] ERROR:root:Error: ('invalid_scope: Some requested scopes were invalid. …', 'error_uri': 'https://developers.google.com/identity/protocols/oauth2'})
Hey @lapo-luchini , gmail / google is kinda shitty with their APIs - things seem to randomly change and aren't versioned great. It does look like some scopes were renamed which I need to look into - see #32 (comment) .
I agree that this app should expose this as an error to prom - I don't know what is the idiomatic way to do this in Prometheus, so I'll start some research on that.
@Kiara0107 - the app needs to constantly refresh login_cookie.dat - but it should re-login automatically without you having to open a browser all the time. Sorry that you have been waiting so long for me to reply.
@lapo-luchini - the error message you're posting isn't logging you out, but rather, you just have some bad scopes configured. I had some old documentation in the readme about scopes - which I've updated just now. Can you re-check your scopes? If you remove the invalid ones your error should disapear.
the error message you're posting isn't logging you out, but rather, you just have some bad scopes configured.
Oh, okay! I did need to re-login when stopping and immediately restarting the app, so I tought it was so.
I will try agani this evening. Thanks for the feedback!
Make sure you update your container image - the version posted to docker hub was very old (I just deleted it), the version on ghcr.io is good 😊