Skip to content

Commit

Permalink
Improve logging around tokens and fix initial read (#6149)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored Dec 21, 2024
1 parent f0629e3 commit 90932da
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class TokenStorage {
this.logger.error(error);
}

this.logger.error('Failed to fetch token', error);
throw new HiveError('Invalid token provided', {
originalError: error,
});
Expand Down
11 changes: 10 additions & 1 deletion packages/services/tokens/src/multi-tier-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export async function createStorage(
action: 'set',
});
});

return cacheEntry;
} catch (error) {
// If the DB is down, we log the error, and we throw exception.
// This will cause the cache to return stale data.
Expand Down Expand Up @@ -193,6 +195,9 @@ export async function createStorage(
async readToken(hashedToken, maskedToken) {
const status: LRUCache.Status<CacheEntry> = {};
const context = { maskedToken, source: 'in-memory' };
const tokenLogger = serverLogger.child({
maskedToken,
});
const data = await cache.fetch(hashedToken, {
context,
status,
Expand All @@ -201,7 +206,11 @@ export async function createStorage(
if (status.fetch) {
recordCacheRead(status.fetch);
} else {
serverLogger.warn('Status of the fetch is missing');
tokenLogger.warn('Status of the fetch is missing');
}

if (status.fetchError) {
tokenLogger.error('Fetch error in the In-Memory-Cache (error=%s)', status.fetchError);
}

if (!data) {
Expand Down
1 change: 1 addition & 0 deletions packages/services/usage/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function createTokens(config: { endpoint: string; logger: ServiceLogger }
}
return TokenStatus.NotFound;
} catch (error) {
config.logger.error('Failed to fetch fresh token', error);
return TokenStatus.NotFound;
}
}
Expand Down

0 comments on commit 90932da

Please sign in to comment.