Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(logging): add detectResource benchmark (#6084)
Adding a benchmark test to measure execution time for detectResource() to address #5855. Current implementation uses cloud.google.com/go/compute/metadata package to read Google Cloud metadata server attributes. The package implements retrying mechanism to cover on occasional problems of miscommunication with the metadata server. When a new Logger instance is being created, it calls detectResource() to read the monitored resource object. The resource detection algorithm is invoked once per process (regardless of how many Logger instances is created). The algorithm checks whether the environment runs the metadata server as a first step and to avoid further validations. Due to the retrying mechanism, this call may take between 6 to 7 seconds which composes the overall delay of creating a first instance of the Logger. The benchmark demonstrates that only first Logger takes long time: ```bash go test -run=XXX -bench=BenchmarkDetectResource -benchtime 8s goos: linux goarch: amd64 pkg: cloud.google.com/go/logging cpu: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz BenchmarkDetectResource-8 1000000000 2.291 ns/op PASS ok cloud.google.com/go/logging 9.955s ``` When the cloud.google.com/go/compute/metadata package will be modified to allow customizable retrying mechanism, this logic will be altered to minimize the number of retries for the initial call.
- Loading branch information