Skip to content

WatchedSetting based refresh#14

Merged
linglingye001 merged 12 commits intorelease/v1.0.0-beta.2from
linglingye/sentinelBasedRefresh
Apr 24, 2025
Merged

WatchedSetting based refresh#14
linglingye001 merged 12 commits intorelease/v1.0.0-beta.2from
linglingye/sentinelBasedRefresh

Conversation

@linglingye001
Copy link
Member

Overall
The refresh mechanism is designed around these key components:

  • watchedSettings: The specific settings to monitor for changes
  • sentinalETags: Stores ETags for tracked settings to detect changes
  • kvRefreshTimer: Controls refresh intervals using a timer
  • refreshKeyValues: Core logic that handles checking and refreshing
  • watchedSettingClient: Checks if ETags have changed using Azure's API

Refresh Control Flow
The refresh process follows this logical flow:

  • Initialization (during Load):

    • Validates refresh configuration (interval and watched settings)
    • Sets up the refresh timer with configured interval
    • Loads initial configuration and ETags for watched settings
    • Refresh Invocation (in Refresh method):
  • Checks if refresh is enabled

    • Uses mutex to prevent concurrent refreshes
    • Checks if it's time to refresh (using refresh timer)
    • Calls refreshKeyValues to check and reload if needed
    • Executes success callbacks only if configuration actually changed
    • Change Detection (in refreshKeyValues):
  • Creates/uses a monitor to check ETags

    • Uses Azure's API with OnlyIfChanged flag for efficient checking
    • Only proceeds with reloading if ETags have changed
    • Resets timer if no changes detected (early return)
    • Configuration Reloading (if changes detected):
  • Reloads all key-values concurrently using errgroup

    • Reloads watched settings to get new ETags
    • Updates the monitor with new ETags
    • Resets the timer only after successful reload
    • Returns true to indicate successful refresh
  • Error Handling:

    • Does not reset the timer if reload fails
    • Returns specific error messages for different failure points
    • Maintains refresh status to avoid duplicate refreshes

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a refresh mechanism based on watched settings, adding validation, monitoring, and concurrent reloading of configuration when changes occur.

  • Added validation and normalization for refresh options and watched settings.
  • Introduced a dedicated refresh timer and corresponding client logic for Azure App Configuration.
  • Expanded test coverage to validate various refresh scenarios.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
utils.go Adds validations for refresh options including interval and watched settings.
settings_client.go Introduces watchedSettingClient with error handling and ETag check logic.
refresh_test.go Provides comprehensive tests for refresh functionality and configuration updates.
options.go Defines new refresh options and watched settings structures.
internal/refreshtimer/refresh_timer.go Implements a refresh timer to control refresh intervals.
constants.go Adds minimal refresh interval constant.
azureappconfiguration.go Implements refresh logic including mutual exclusion, reloading key-values and watched settings.

@linglingye001 linglingye001 force-pushed the linglingye/sentinelBasedRefresh branch from 3a69488 to 760d5ff Compare March 28, 2025 08:54
@linglingye001 linglingye001 force-pushed the linglingye/sentinelBasedRefresh branch from 760d5ff to 831f1b1 Compare April 9, 2025 13:11
Base automatically changed from release/v0 to main April 10, 2025 05:32
@linglingye001 linglingye001 force-pushed the linglingye/sentinelBasedRefresh branch from 831f1b1 to a0a7fb2 Compare April 11, 2025 06:52
@linglingye001 linglingye001 changed the base branch from main to release/v1.0.0-beta.2 April 11, 2025 06:54
@linglingye001 linglingye001 force-pushed the linglingye/sentinelBasedRefresh branch from b6bf5ec to c733192 Compare April 23, 2025 05:07
EnvVarServiceFabric = "Fabric_NodeName"

RequestTracingKey = "Tracing"
TracingKey = "Tracing"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it can be removed now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be removed


if err := azappcfg.load(ctx); err != nil {
return nil, err
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

if err := azappcfg.load(ctx); err != nil {
		return nil, err
	} 
	
	azappcfg.tracingOptions.InitialLoadFinished = true

@linglingye001 linglingye001 merged commit 88f5a60 into release/v1.0.0-beta.2 Apr 24, 2025
13 checks passed
@linglingye001 linglingye001 deleted the linglingye/sentinelBasedRefresh branch April 24, 2025 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants