Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion api/cloud_api/routes/Mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ router.post('/sendVerificationEmail', async (req, res) => {

if (tokenJson) {
if (apiHandler.checkIfTokenIsExpired(tokenJson)) {
logger.warn('refreshing token');
// the time() function in prometheus returns the epoch time in seconds
// i.e. 1760310047.552
// Date.now() returns the time in milliseconds, so we divide by 1000
// to be consistent with prometheus.
MetricsHandler.gcpRefreshTokenLastUpdated.set(Math.floor(Date.now() / 1000));
apiHandler.refreshToken();
}
} else {
Expand Down Expand Up @@ -69,6 +73,7 @@ router.post('/sendPasswordReset', async (req, res) => {
if (tokenJson) {
if (apiHandler.checkIfTokenIsExpired(tokenJson)) {
logger.warn('refreshing token');
MetricsHandler.gcpRefreshTokenLastUpdated.set(Math.floor(Date.now() / 1000));
apiHandler.refreshToken();
}
} else {
Expand Down
11 changes: 10 additions & 1 deletion api/cloud_api/util/SceGoogleApiHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ class SceGoogleApiHandler {
* DevOps purposes, false for API endpoints.
*/
getNewToken(isDevScript) {
if (!isDevScript) return;
if (!isDevScript) {
logger.warn(`
The 'getNewToken' function was called outside of a development environment.
Token generation requires manual steps and interactive console input.
If you actually want to set this up, visit:
https://sce.sjsu.edu/s/gmailtoken
Interactive setup has been skipped.
`);
return;
}

const authUrl = this.oAuth2Client.generateAuthUrl({
/* eslint-disable-next-line */
Expand Down
5 changes: 5 additions & 0 deletions api/util/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class MetricsHandler {
labelNames: ['endpointName']
})

gcpRefreshTokenLastUpdated = new client.Gauge({
name: 'google_cloud_refresh_token_last_updated',
help: 'When the GCP refresh token needs to be refreshed, time written in eopch format'
})

constructor() {
register.setDefaultLabels({
app: 'sce-core',
Expand Down
3 changes: 3 additions & 0 deletions prometheus/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ scrape_configs:
- job_name: 'clark'
static_configs:
- targets: ['main-endpoints:8080']
- job_name: 'clark-email'
static_configs:
- targets: ['sce-cloud-api:8082']
# the below is for discord bot
- job_name: 'sarah'
static_configs:
Expand Down