microsoft / ApplicationInsights-Kubernetes

Enrich the telemetry data for .NET applications running inside containers that are managed by Kubernetes.
Other
135 stars 57 forks source link

Make bootstrap idempotent #328

Closed xiaomi7732 closed 1 year ago

xiaomi7732 commented 1 year ago

Addresses #327. Piggybacked some simple refactor.

  1. Flipped the dependency.

    • It was IK8sInfoBootstrap depends on K8sInfoBackgroundService
    • Changed to K8sInfoBackgroundService depends on K8sInfoBootstrap So that logic has been pulled out of K8sInfoBackgroundService. The responsibility for K8sInfoBackgroundService is clearly to handle background service startup. And the bootstrap logic is shared by both the background service and called by the client directly.
  2. The fetch of the cluster properties is pulled out of the bootstrap implementations to divide the responsibilities:

    • K8sInfoBootstrap is responsible for handling bootstrap logic - initial delay, time out, query intervals, etc.
    • K8sEnvironmentFetcher is responsible for creating a new K8sEnv object and setting it to K8sEnvHolder. It is more aligned with the single responsibility principle, isolating those responsibilities also made it possible to mock half of the responsibilities and test the other half.
  3. Added unit tests to cover DI container service resolution.

Tests