Created
September 19, 2024 22:34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Request { | |
/* | |
In our HTTP stack at HubSpot, request context is always available | |
and it tracks original callers for us. You will need to implement | |
similar tracking across calls in order to manage HBase resources | |
at original caller granularity. | |
*/ | |
String getOriginalCaller(); | |
} | |
// This assumes hbase.quota.user.override.key is set to `qu` | |
private static final String QUOTA_USER_OVERRIDE_KEY = "qu"; | |
private final ExecutorService; | |
private final TableName tableName; | |
private final Connection connection; | |
@GET // This is an example endpoint | |
public Response getResponse(Request request) { | |
try (Table table = buildTable(request.getOriginalCaller()) { | |
// Any requests against HBase will be subject to user quotas | |
// based on the value of Request#getOriginalCaller | |
... | |
} | |
} | |
private Table buildTable(String user) { | |
// The TableBuilder class lets you specify request attributes to be | |
// used whenever interacting with the Table that it builds | |
return connection.getTableBuilder(tableName, executorService) | |
.setRequestAttribute(QUOTA_USER_OVERRIDE_KEY, Bytes.toBytes(user)) | |
.build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment