prometheus/discovery/gce
Julien Pivotto fd493fe25a discovery/gce: keep Compute SD client from defeating dead-code elimination
The Discovery struct held *compute.Service and *compute.InstancesService as
fields and is boxed into the discovery.Discoverer interface. Once reflection is
reachable in the program (it always is, via the YAML/config machinery), the Go
linker conservatively retains every exported method of any concrete type
reachable through an interface, including via struct fields. *compute.Service
exposes ~150 sub-services and their operations, so all of them — 994 list/get
operations and their serializers — were retained even though discovery only
calls Instances.List.

Wrap the single used operation in a closure over the concrete *compute.Service
so the service lives only in closure context, which reflection cannot traverse.
Returning a *compute.InstancesListCall would not help, since that type has an
s *Service back-reference that re-propagates the marker, so the closure
encapsulates the whole List/Filter/Pages chain and only exposes the
*compute.InstanceList data type discovery already uses.

compute/v1 footprint drops from ~4.9 MB to ~33 KB, and the prometheus and
promtool binaries each shrink by ~13.5 MB. No functional or API change.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-29 14:00:09 +02:00
..
gce.go discovery/gce: keep Compute SD client from defeating dead-code elimination 2026-05-29 14:00:09 +02:00
metrics.go Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00