Skip to content

[FEATURE] Make upstream clone/fetch failures diagnosable from logs #82

Done

Description

@profiling

Is your feature request related to a problem?

When gitcacheproxy_upstream_ops_total{op="clone"|"fetch",result="error"} rises, an operator cannot tell which repo failed, when, or why. The metric uses repo="-" on failure by design (bounded cardinality), so the detail has to come from logs, and the logs do not carry it:

  • Upstream git stderr is read only to classify the failure. It is never logged, so an unrecognized failure shows only "permanent or unrecognized error".
  • Errors are logged with error = %e, which drops the source chain (e.g. whether an auth rejection was 401, 403 or 404).
  • A budget timeout and a cancellation are the same error.
  • A client disconnect or shutdown cancels the operation, counts it as result="error", and logs nothing. The counter can rise with no log line at any level.

Describe the solution you'd like

Log each upstream operation once, at its final failure, with structured fields:

  • op: clone | fetch | want_fetch
  • trigger: request | refresh
  • repo
  • error_kind: auth | transient_http | tls | connection | dns | timeout | unknown
  • elapsed_ms
  • stderr: a redacted summary of git stderr (last 8 lines, at most 1 KiB)
  • error: the full error chain, including attempts and exit status

Also:

  • Split timeout from cancellation. Log cancellation at debug and do not count it as result="error". This changes an existing metric.
  • Callers do not log a failure that is already logged, so one failure gives one line.
  • Redact the stderr summary: URL userinfo, Authorization and Cookie values, and the credential in use. Remove inherited GIT_TRACE* and GIT_CURL_VERBOSE from upstream git. Keep stderr out of the returned error.

Describe alternatives you've considered

  • Raise the log level only: still no stderr, no timeout vs cancel split, and silent cancellations.
  • An error_kind metric label: bounded, but not needed once the log exists.
  • Error message or URL as a metric label: rejected, unbounded cardinality.

Scope check

  • Keeps the proxy strictly read-only and pull-only (it must never push or
    proactively replicate to upstream).
  • Not already tracked in the README "Status / scope" (LRU eviction, per-repo
    histograms, scheduled refresh) or listed there as a non-goal (git-free image).

Activity

  1. profiling commented on Nov 19, 2026

    @profiling
    ContributorAuthor

    Design note before I open a PR, on one point that differs from the current docs.

    docs/architecture.md says retry logs carry no raw upstream stderr. Looking at the history, that line comes from #37: before it, upstream clone/fetch used .status() and inherited stderr, so git's diagnostics went straight to the process output, unfiltered and unbounded (that is how the TLS EOF in #35 was diagnosed). #37 piped stderr to classify it and, as a side effect, stopped surfacing it. I could not find a review discussion that asked for that restriction, so I read it as a conservative default rather than a requirement. Please correct me if there was a reason I am missing.

    Proposal: put a bounded, redacted stderr summary on the single final-failure log line only. The error string returned to callers stays as it is, so noisy_stderr_is_drained_and_not_exposed_in_errors still holds.

    • Bounded: last 8 lines, at most 1 KiB, non-printable bytes replaced.
    • At the source: strip inherited GIT_TRACE* / GIT_CURL_VERBOSE from upstream git, so stderr holds only git's own diagnostics and remote: lines.
    • Redaction, mirroring git itself: git already strips URL userinfo from its error messages (transport_anonymize_url), and its trace redacts Authorization / Cookie (http.c, trace2.c). The proxy applies the same rules again as defense in depth, and also replaces any verbatim occurrence of the credential used for that operation.

    Recognized failures without the raw text only give a category, and unrecognized ones give "permanent or unrecognized error" plus an exit code, which is where diagnosis is needed most. I will update the architecture doc to match. Happy to drop the stderr field or move it to debug if you prefer; the rest of #82 does not depend on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions