Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

UpdatePolicy does not update rate limits on a azure service fabric self owin deployment #108

Open
udbach opened this issue Sep 5, 2017 · 2 comments

Comments

@udbach
Copy link

udbach commented Sep 5, 2017

Hi,

We have a cloud service written on Azure Service Fabric. It has self owin controller web apis for which throttling has been enforced using WebApiThrottle.

Cloude service is deployed on azure service fabric which gets deployed on multiple nodes. This allows service fabric to fail over in case of and service down/crashes.

We are seeing issue with updating throttle policy at run time. WebApiThrottling is applied for the riles defined in App.config but when updating the policy at run time, the same is not reflected.

When trying to fetch policy from "PolicyMemoryCacheRepository" at run time, we see older policy
some times and some times new policy updated.
We also tried removing the policy and adding it. But are still seeing the same issue.

How are are such things handled in case where cache is replicated ? Do you have any scenario for a service fabric application ? Please comment.

More Information:
As per the documentation, in the startup Register.cs, we registered throttling handler as :

//Register throttling handler
config.MessageHandlers.Add(new ThrottlingHandler(
policy: ThrottlePolicy.FromStore(new PolicyConfigurationProvider()),
policyRepository: new PolicyMemoryCacheRepository(),
repository: new MemoryCacheRepository(),
logger: new WebApiThrottle.TracingThrottleLogger(traceWriter)
));

Helper functions to fetch and update throttle policy:
private string GetPolicyConfiguration()
{
try
{
string id = "throttle_policy";

            PolicyMemoryCacheRepository policyRepository = new PolicyMemoryCacheRepository();
            ThrottlePolicy policyObject = policyRepository.FirstOrDefault(id);
            if (policyObject == null)
            {
                return "Provisioning Service Policy Configuration doesnot exist.";
            }
            else
            {
                return JsonConvert.SerializeObject(policyObject);
            }                
        }
        catch (Exception e)
        {
            throw;
        }
    }

    private string UpdatePolicyConfig(string policyConfig)
    {
        try
        {
            string id = "throttle_policy";

            
            if (string.IsNullOrEmpty(policyConfig))
                throw new Exception("Policy configuration passed was either null or empty.");

            //Deserialize policyConfig
            ThrottlePolicy policyObject = JsonConvert.DeserializeObject<ThrottlePolicy>(policyConfig);

           //init policy repo
            var policyRepository = new PolicyMemoryCacheRepository();
            

            //apply policy updates
            policyRepository.Remove(id);

            if (policyRepository.FirstOrDefault(id) == null)
            {
                //Policy id : successfully removed from repository of type 
            }
            else
            {
                //Could not remove policy id : from repository of type
            }

            //apply policy updates
            ThrottleManager.UpdatePolicy(policyObject, policyRepository);               
            
            return "Successfully updated policy configuration for type";
        }
        catch (Exception ex)
        {
            throw;
        }
    }
@BoAnd
Copy link

BoAnd commented Oct 3, 2017

@udbach instead of using the PolicyMemoryCacheRepository. You should implement a Redis Cache implementation or Table Storage. That way you can have a global policy over all the fabric nodes.

@udbach
Copy link
Author

udbach commented Oct 3, 2017 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants