Skip to content

Commit 57c33a4

Browse files
committed
test
1 parent 158a948 commit 57c33a4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

components/server/src/authorization/spicedb-authorizer.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class SpiceDBAuthorizer {
2929
if (!this.client) {
3030
return true;
3131
}
32+
const timing = startTimer();
3233

3334
const featureEnabled = await getExperimentsClientForBackend().getValueAsync("centralizedPermissions", false, {
3435
user: {
@@ -54,13 +55,15 @@ export class SpiceDBAuthorizer {
5455
return false;
5556
} finally {
5657
observeSpicedbClientLatency("check", error, timer());
58+
stopTimer("CHECK", timing);
5759
}
5860
}
5961

6062
async writeRelationships(...updates: v1.RelationshipUpdate[]): Promise<v1.WriteRelationshipsResponse | undefined> {
6163
if (!this.client) {
6264
return undefined;
6365
}
66+
const timing = startTimer();
6467

6568
const timer = spicedbClientLatency.startTimer();
6669
let error: Error | undefined;
@@ -78,13 +81,15 @@ export class SpiceDBAuthorizer {
7881
log.error("[spicedb] Failed to write relationships.", err, { updates: new TrustedValue(updates) });
7982
} finally {
8083
observeSpicedbClientLatency("write", error, timer());
84+
stopTimer("WRITE", timing);
8185
}
8286
}
8387

8488
async deleteRelationships(req: v1.DeleteRelationshipsRequest): Promise<v1.ReadRelationshipsResponse[]> {
8589
if (!this.client) {
8690
return [];
8791
}
92+
const timing = startTimer();
8893

8994
const timer = spicedbClientLatency.startTimer();
9095
let error: Error | undefined;
@@ -111,6 +116,7 @@ export class SpiceDBAuthorizer {
111116
return [];
112117
} finally {
113118
observeSpicedbClientLatency("delete", error, timer());
119+
stopTimer("DELETE", timing);
114120
}
115121
}
116122

@@ -121,3 +127,11 @@ export class SpiceDBAuthorizer {
121127
return this.client.readRelationships(req);
122128
}
123129
}
130+
function startTimer() {
131+
return process.hrtime();
132+
}
133+
134+
function stopTimer(method: string, hrtime: [number, number]) {
135+
const seconds = (hrtime[0] + hrtime[1] / 1e6).toFixed(3);
136+
log.info(`[SPICEDB] ${method} (${seconds} ms)`);
137+
}

0 commit comments

Comments
 (0)