Skip to content

Commit 9290d58

Browse files
committed
upload-pack: add tracing for fetches
Information on how users are accessing hosted repositories can be helpful to server operators. For example, being able to broadly differentiate between fetches and initial clones; the use of shallow repository features; or partial clone filters. a29263c (fetch-pack: add tracing for negotiation rounds, 2022-08-02) added some information on have counts to fetch-pack itself to help diagnose negotiation; but from a git-upload-pack (server) perspective, there's no means of accessing such information without using GIT_TRACE_PACKET to examine the protocol packets. Improve this by emitting a Trace2 JSON event from upload-pack with summary information on the contents of a fetch request. * haves, wants, and want-ref counts can help determine (broadly) between fetches and clones, and the use of single-branch, etc. * shallow clone depth, tip counts, and deepening options. * any partial clone filter type. Signed-off-by: Robert Coup <robert@coup.net.nz>
1 parent aab89be commit 9290d58

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

t/t5500-fetch-pack.sh

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,18 @@ test_expect_success 'single branch object count' '
132132
'
133133

134134
test_expect_success 'single given branch clone' '
135-
git clone --single-branch --branch A "file://$(pwd)/." branch-a &&
136-
test_must_fail git --git-dir=branch-a/.git rev-parse origin/B
135+
GIT_TRACE2_EVENT="$(pwd)/branch-a/trace2_event" \
136+
git clone --single-branch --branch A "file://$(pwd)/." branch-a &&
137+
test_must_fail git --git-dir=branch-a/.git rev-parse origin/B &&
138+
grep \"fetch-info\".*\"haves\":0 branch-a/trace2_event &&
139+
grep \"fetch-info\".*\"wants\":1 branch-a/trace2_event
137140
'
138141

139142
test_expect_success 'clone shallow depth 1' '
140-
git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0 &&
141-
test "$(git --git-dir=shallow0/.git rev-list --count HEAD)" = 1
143+
GIT_TRACE2_EVENT="$(pwd)/shallow0/trace2_event" \
144+
git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0 &&
145+
test "$(git --git-dir=shallow0/.git rev-list --count HEAD)" = 1 &&
146+
grep \"fetch-info\".*\"depth\":1 shallow0/trace2_event
142147
'
143148

144149
test_expect_success 'clone shallow depth 1 with fsck' '
@@ -235,7 +240,10 @@ test_expect_success 'add two more (part 2)' '
235240
test_expect_success 'deepening pull in shallow repo' '
236241
(
237242
cd shallow &&
238-
git pull --depth 4 .. B
243+
GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
244+
git pull --depth 4 .. B &&
245+
grep \"fetch-info\".*\"depth\":4 trace2_event &&
246+
grep \"fetch-info\".*\"shallows\":2 trace2_event
239247
)
240248
'
241249

@@ -306,9 +314,12 @@ test_expect_success 'fetch --depth --no-shallow' '
306314
test_expect_success 'turn shallow to complete repository' '
307315
(
308316
cd shallow &&
309-
git fetch --unshallow &&
317+
GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
318+
git fetch --unshallow &&
310319
! test -f .git/shallow &&
311-
git fsck --full
320+
git fsck --full &&
321+
grep \"fetch-info\".*\"shallows\":2 trace2_event &&
322+
grep \"fetch-info\".*\"depth\":2147483647 trace2_event
312323
)
313324
'
314325

@@ -826,13 +837,15 @@ test_expect_success 'clone shallow since ...' '
826837
'
827838

828839
test_expect_success 'fetch shallow since ...' '
829-
git -C shallow11 fetch --shallow-since "200000000 +0700" origin &&
840+
GIT_TRACE2_EVENT=$(pwd)/shallow11/trace2_event \
841+
git -C shallow11 fetch --shallow-since "200000000 +0700" origin &&
830842
git -C shallow11 log --pretty=tformat:%s origin/main >actual &&
831843
cat >expected <<-\EOF &&
832844
three
833845
two
834846
EOF
835-
test_cmp expected actual
847+
test_cmp expected actual &&
848+
grep \"fetch-info\".*\"deepen-since\":true shallow11/trace2_event
836849
'
837850

838851
test_expect_success 'clone shallow since selects no commits' '
@@ -987,13 +1000,16 @@ test_expect_success 'filtering by size' '
9871000
test_config -C server uploadpack.allowfilter 1 &&
9881001
9891002
test_create_repo client &&
990-
git -C client fetch-pack --filter=blob:limit=0 ../server HEAD &&
1003+
GIT_TRACE2_EVENT=$(pwd)/client/trace2_event \
1004+
git -C client fetch-pack --filter=blob:limit=0 ../server HEAD &&
9911005
9921006
# Ensure that object is not inadvertently fetched
9931007
commit=$(git -C server rev-parse HEAD) &&
9941008
blob=$(git hash-object server/one.t) &&
9951009
git -C client rev-list --objects --missing=allow-any "$commit" >oids &&
996-
! grep "$blob" oids
1010+
! grep "$blob" oids &&
1011+
1012+
grep \"fetch-info\".*\"filter\":\"blob:limit\" client/trace2_event
9971013
'
9981014

9991015
test_expect_success 'filtering by size has no effect if support for it is not advertised' '

upload-pack.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "commit-reach.h"
3434
#include "shallow.h"
3535
#include "write-or-die.h"
36+
#include "json-writer.h"
3637

3738
/* Remember to update object flag allocation in object.h */
3839
#define THEY_HAVE (1u << 11)
@@ -1552,6 +1553,30 @@ static int parse_have(const char *line, struct oid_array *haves)
15521553
return 0;
15531554
}
15541555

1556+
static void trace2_fetch_info(struct upload_pack_data *data)
1557+
{
1558+
struct json_writer jw = JSON_WRITER_INIT;
1559+
1560+
jw_object_begin(&jw, 0);
1561+
jw_object_intmax(&jw, "haves", data->haves.nr);
1562+
jw_object_intmax(&jw, "wants", data->want_obj.nr);
1563+
jw_object_intmax(&jw, "want-refs", data->wanted_refs.nr);
1564+
jw_object_intmax(&jw, "depth", data->depth);
1565+
jw_object_intmax(&jw, "shallows", data->shallows.nr);
1566+
jw_object_bool(&jw, "deepen-since", data->deepen_since);
1567+
jw_object_intmax(&jw, "deepen-not", data->deepen_not.nr);
1568+
jw_object_bool(&jw, "deepen-relative", data->deepen_relative);
1569+
if (data->filter_options.choice)
1570+
jw_object_string(&jw, "filter", list_object_filter_config_name(data->filter_options.choice));
1571+
else
1572+
jw_object_null(&jw, "filter");
1573+
jw_end(&jw);
1574+
1575+
trace2_data_json("upload-pack", the_repository, "fetch-info", &jw);
1576+
1577+
jw_release(&jw);
1578+
}
1579+
15551580
static void process_args(struct packet_reader *request,
15561581
struct upload_pack_data *data)
15571582
{
@@ -1640,6 +1665,9 @@ static void process_args(struct packet_reader *request,
16401665

16411666
if (request->status != PACKET_READ_FLUSH)
16421667
die(_("expected flush after fetch arguments"));
1668+
1669+
if (trace2_is_enabled())
1670+
trace2_fetch_info(data);
16431671
}
16441672

16451673
static int process_haves(struct upload_pack_data *data, struct oid_array *common)

0 commit comments

Comments
 (0)