public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            providerRuntime.SetInvokeInterceptor((method, request, grain, invoker) =>
            {
                RequestContext.Set("GrainInfo", 38);
                return invoker.Invoke(grain, request);
            });

            return Task.FromResult(0);
        }
        public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            providerRuntime.SetInvokeInterceptor((method, request, grain, invoker) =>
            {
                RequestContext.Set("GrainInfo", 38);
                return(invoker.Invoke(grain, request));
            });

            return(Task.FromResult(0));
        }
Esempio n. 3
0
        public GrainProfiler(TaskScheduler taskScheduler, IProviderRuntime providerRuntime)
        {
            this.TaskScheduler = taskScheduler;
            this.ProviderRuntime = providerRuntime;

            // register interceptor, wrapping any previously set interceptor
            this.innerInterceptor = providerRuntime.GetInvokeInterceptor();
            providerRuntime.SetInvokeInterceptor(this.InvokeInterceptor);
            siloAddress = providerRuntime.SiloIdentity.ToSiloAddress();

            // register timer to report every second
            timer = new Timer(this.ProcessStats, providerRuntime, 1 * 1000, 1 * 1000);

        }
        public GrainProfiler(TaskScheduler taskScheduler, IProviderRuntime providerRuntime)
        {
            this.TaskScheduler   = taskScheduler;
            this.ProviderRuntime = providerRuntime;
            this.Logger          = this.ProviderRuntime.GetLogger("GrainProfiler");

            // register interceptor, wrapping any previously set interceptor
            this.innerInterceptor = providerRuntime.GetInvokeInterceptor();
            providerRuntime.SetInvokeInterceptor(this.InvokeInterceptor);
            siloAddress = providerRuntime.SiloIdentity.ToSiloAddress();

            // register timer to report every second
            timer = new Timer(this.ProcessStats, providerRuntime, 1 * 1000, 1 * 1000);
        }
Esempio n. 5
0
        private void ConfigureSiloInterceptor(bool enable = true)
        {
            // TODO: harden this for production use
            // TODO: add tracking of the time each grain method call took to complete
            // TODO: make this optional, enabled or disabled via ClusterMetricsGrain calls
            Runtime.SetInvokeInterceptor(async(method, request, grain, invoker) =>
            {
                try
                {
                    // Invoke the request and return the result back to the caller.
                    var result = await invoker.Invoke(grain, request);

                    if (Configuration.TrackMethodGrainCalls)
                    {
                        // Would be nice if we could figure out if this is a local or remote call, and perhaps caller / calling silo... Unless I've got something backwards
                        logger.IncrementMetric($"GrainMethodCall:{grain.GetType().Name}:{method.Name}");
                    }

                    return(result);
                }
                catch (TimeoutException ex) // Not sure if this is going to be an innerException here or if everything gets unrolled... Fingers crossed for now!
                {
                    if (Configuration.TrackExceptionCounters)
                    {
                        logger.IncrementMetric($"GrainInvokeTimeout:{grain.GetType().Name}:{method.Name}");
                        logger.TrackException(ex, new Dictionary <string, string>
                        {
                            { "GrainType", grain.GetType().Name },
                            { "MethodName", method.Name },
                        });
                    }
                    throw;
                }
                catch (Exception ex)
                {
                    if (Configuration.TrackExceptionCounters)
                    {
                        logger.IncrementMetric($"GrainException:{grain.GetType().Name}:{method.Name}");
                        logger.TrackException(ex, new Dictionary <string, string>
                        {
                            { "GrainType", grain.GetType().Name },
                            { "MethodName", method.Name },
                        });
                    }
                    throw;
                }
            });
        }
Esempio n. 6
0
        public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
#pragma warning disable 618
            providerRuntime.SetInvokeInterceptor((method, request, grain, invoker) =>
#pragma warning restore 618
            {
                if (string.Equals(method.Name, nameof(IGrainCallFilterTestGrain.GetRequestContext)))
                {
                    var value = RequestContext.Get(GrainCallFilterTestConstants.Key) as string;
                    if (value != null)
                    {
                        RequestContext.Set(GrainCallFilterTestConstants.Key, value + '3');
                    }
                }

                return(invoker.Invoke(grain, request));
            });

            return(Task.FromResult(0));
        }
Esempio n. 7
0
        public GrainProfiler(TaskScheduler taskScheduler, IProviderRuntime providerRuntime)
        {
            this.TaskScheduler   = taskScheduler;
            this.ProviderRuntime = providerRuntime;
            this.Logger          = this.ProviderRuntime.GetLogger("GrainProfiler");

            // check if custom method name formatter is registered
            var formatter = providerRuntime.ServiceProvider.GetService <Func <MethodInfo, InvokeMethodRequest, IGrain, string> >();

            if (formatter != null)
            {
                formatMethodName = formatter;
            }

            // register interceptor, wrapping any previously set interceptor
            this.innerInterceptor = providerRuntime.GetInvokeInterceptor();
            providerRuntime.SetInvokeInterceptor(this.InvokeInterceptor);
            siloAddress = providerRuntime.SiloIdentity.ToSiloAddress();

            // register timer to report every second
            timer = new Timer(this.ProcessStats, providerRuntime, 1 * 1000, 1 * 1000);
        }
Esempio n. 8
0
        public void SetInvokeInterceptor(InvokeInterceptor interceptor)
        {
#pragma warning disable 618
            runtime.SetInvokeInterceptor(interceptor);
#pragma warning restore 618
        }
Esempio n. 9
0
 public void SetInvokeInterceptor(InvokeInterceptor interceptor)
 {
     providerRuntime.SetInvokeInterceptor(interceptor);
 }
Esempio n. 10
0
 public void SetInvokeInterceptor(InvokeInterceptor interceptor)
 {
     runtime.SetInvokeInterceptor(interceptor);
 }