Skip to content

Commit efe07e3

Browse files
committed
gvfs: add gvfs.sessionKey config
In different engineering systems, there may already be pseudonymous identifiers stored in the local Git config. For Office and 1JS, this is present in the 'otel.trace2.id' config value. We'd like to be able to collect server-side telemetry based on these pseudonymous identifiers, so prefxing the X-Session-Id header with this value is helpful. We could create a single 'gvfs.sessionPrefix' config key that stores this value, but then we'd need to duplicate the identifier and risk drift in the value. For now, we create this indirection by saying "what config _key_ should Git use to look up the value to add as a prefix?" Signed-off-by: Derrick Stolee <stolee@gmail.com>
1 parent ed7ffcc commit efe07e3

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

Documentation/config/gvfs.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,11 @@ gvfs.fallback::
2626
If set to `false`, then never fallback to the origin server when the cache
2727
server fails to connect. This will alert users to failures with the cache
2828
server, but avoid causing throttling on the origin server.
29+
30+
gvfs.sessionKey::
31+
If set to a string, then the value is a config key name that will be used
32+
to set a prefix in the `X-Session-Id` header sent to the server for all
33+
GVFS Protocol calls. This allows engineering systems to improve support
34+
across client and server behavior, including any End User Pseodynomous
35+
Identifiers (EUPI) that may be configured. The `X-Session-Id` will
36+
include the SID of the current process in either case.

gvfs-helper.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,28 @@ static char *build_session_id_header(void)
467467
{
468468
struct strbuf header = STRBUF_INIT;
469469
const char *sid = tr2_sid_get();
470+
char *session_key = NULL;
471+
char *prefix = NULL;
472+
473+
/* Read gvfs.sessionkey to see if it points to a config key */
474+
if (!repo_config_get_string(the_repository, "gvfs.sessionkey", &session_key) &&
475+
session_key) {
476+
/* Try to read the config key that session_key points to */
477+
if (!repo_config_get_string(the_repository, session_key, &prefix) &&
478+
prefix) {
479+
/* We have a prefix, format as: X-Session-Id: <prefix>:<SID> */
480+
strbuf_addf(&header, "X-Session-Id: %s:%s", prefix, sid);
481+
free(prefix);
482+
} else {
483+
/* Config key doesn't exist, use just SID */
484+
strbuf_addf(&header, "X-Session-Id: %s", sid);
485+
}
470486

471-
strbuf_addf(&header, "X-Session-Id: %s", sid);
487+
free(session_key);
488+
} else {
489+
/* No gvfs.sessionkey configured, use just SID */
490+
strbuf_addf(&header, "X-Session-Id: %s", sid);
491+
}
472492

473493
return strbuf_detach(&header, NULL);
474494
}

t/t5793-gvfs-helper-integration.sh

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ test_expect_success 'integration: X-Session-Id header with and without prefix' '
173173
test_when_finished "per_test_cleanup" &&
174174
start_gvfs_protocol_server &&
175175
176+
# Case 1: No gvfs.sessionkey configured - should send just SID
176177
git -C "$REPO_T1" gvfs-helper \
177178
--cache-server=disable \
178179
--remote=origin \
@@ -182,7 +183,34 @@ test_expect_success 'integration: X-Session-Id header with and without prefix' '
182183
# Verify X-Session-Id contains SID (with process ID marker "-P")
183184
test_grep "X-Session-Id:.*-P" "$SERVER_LOG" >OUT.case1 &&
184185
# Verify no slash (no prefix)
185-
test_grep ! "X-Session-Id:.*:" OUT.case1
186+
test_grep ! "X-Session-Id:.*:" OUT.case1 &&
187+
188+
# Case 2: gvfs.sessionkey points to non-existent config - should send just SID
189+
rm -f OUT.output* OUT.case* &&
190+
git -C "$REPO_T1" -c gvfs.sessionkey="test.id" gvfs-helper \
191+
--cache-server=disable \
192+
--remote=origin \
193+
get \
194+
<"$OID_ONE_BLOB_FILE" >OUT.output2 &&
195+
196+
# Verify X-Session-Id still contains just SID (no prefix)
197+
test_grep "X-Session-Id:.*-P" "$SERVER_LOG" >OUT.case2 &&
198+
test_grep ! "X-Session-Id:.*:" OUT.case2 &&
199+
200+
# Case 3: gvfs.sessionkey points to existing config - should send prefix/SID
201+
rm -f OUT.output* OUT.case* &&
202+
git -C "$REPO_T1" \
203+
-c gvfs.sessionkey="test.id" \
204+
-c test.id="my-trace-12345" \
205+
gvfs-helper \
206+
--cache-server=disable \
207+
--remote=origin \
208+
get \
209+
<"$OID_ONE_BLOB_FILE" >OUT.output3 &&
210+
211+
# Verify X-Session-Id contains prefix, slash, and SID
212+
test_grep "X-Session-Id:.*my-trace-12345:" "$SERVER_LOG" >OUT.case3 &&
213+
test_grep "X-Session-Id:.*my-trace-12345:.*-P" OUT.case3
186214
'
187215

188216
test_done

0 commit comments

Comments
 (0)