예제 #1
0
        protected void EnforceDelay()
        {
            if (this.context.ErrorInfo.TerminatePipeline)
            {
                return;
            }
            IPowerShellBudget psbudget = this.PSBudget;

            if (psbudget != null)
            {
                T t = (default(T) == null) ? Activator.CreateInstance <T>() : default(T);
                DelayEnforcementResults delayEnforcementResults = t.EnforceDelay(this, ThrottlingModule <T> .costTypesInEnforceDelay, ThrottlingModule <T> .CmdletMaxPreferredDelay);
                LocalizedString         localizedString         = this.GenerateDelayInfoLogString(this.PSBudget, delayEnforcementResults);
                if (!string.IsNullOrEmpty(localizedString))
                {
                    string          text           = string.Format("; PolicyDN: {0}; Snapshot: {1}", psbudget.ThrottlingPolicy.GetIdentityString(), psbudget);
                    LocalizedString warningMessage = new LocalizedString(localizedString + text);
                    this.context.Items["ThrottlingInfo"] = text;
                    this.context.Items["DelayedInfo"]    = localizedString;
                    Guid uniqueId = this.context.UniqueId;
                    CmdletLogger.SafeSetLogger(uniqueId, RpsCmdletMetadata.ThrottlingInfo, text);
                    CmdletLogger.SafeSetLogger(uniqueId, RpsCmdletMetadata.DelayInfo, CmdletLogHelper.NeedConvertLogMessageToUS ? localizedString.ToString(CmdletLogHelper.DefaultLoggingCulture) : localizedString);
                    this.WriteCmdletMicroDelayMessage(warningMessage, delayEnforcementResults.DelayInfo.Delay.TotalSeconds);
                }
                PowerShellBudgetWrapper powerShellBudgetWrapper = psbudget as PowerShellBudgetWrapper;
                WorkloadManagementLogger.SetBudgetBalance(powerShellBudgetWrapper.GetInnerBudget().CasTokenBucket.GetBalance().ToString(), null);
            }
        }
예제 #2
0
 internal BudgetWrapper(T innerBudget)
 {
     if (innerBudget == null)
     {
         throw new ArgumentNullException("innerBudget");
     }
     this.innerBudget = innerBudget;
     WorkloadManagementLogger.SetBudgetType(this.BudgetType.ToString(), null);
 }
예제 #3
0
        public void Dispose()
        {
            string budgetBalance;

            if (this.TryGetBudgetBalance(out budgetBalance))
            {
                WorkloadManagementLogger.SetBudgetBalance(budgetBalance, null);
            }
            this.CloseAllActions();
            this.AfterDispose();
        }
예제 #4
0
        protected override void InternalLogActivityEvent(IActivityScope activityScope, ActivityEventType eventType)
        {
            LogRowFormatter logRowFormatter = new LogRowFormatter(base.LogSchema);

            logRowFormatter[1] = activityScope.ActivityType;
            logRowFormatter[2] = ActivityContextLogger.ActivityEventTypeDictionary[eventType];
            logRowFormatter[3] = activityScope.Status;
            logRowFormatter[4] = activityScope.StartTime;
            logRowFormatter[5] = activityScope.EndTime;
            logRowFormatter[6] = WorkloadManagementLogger.FormatWlmActivity(activityScope, true);
            base.AppendLog(logRowFormatter);
        }
예제 #5
0
        protected override void InternalLogActivityEvent(IActivityScope activityScope, ActivityEventType eventType)
        {
            object        userState     = activityScope.UserState;
            AssistantBase assistantBase = null;
            string        assistantShortName;

            if (activityScope.ActivityType == ActivityType.Global)
            {
                assistantShortName = "GlobalActivity";
            }
            else
            {
                SystemTaskBase systemTaskBase = userState as SystemTaskBase;
                if (systemTaskBase != null)
                {
                    assistantShortName = systemTaskBase.Workload.Id;
                }
                else
                {
                    AssistantBase assistantBase2 = userState as AssistantBase;
                    if (assistantBase2 == null)
                    {
                        return;
                    }
                    assistantBase      = assistantBase2;
                    assistantShortName = assistantBase.NonLocalizedName;
                }
            }
            AssistantsEventType eventType2;

            switch (eventType)
            {
            case ActivityEventType.SuspendActivity:
                eventType2 = AssistantsEventType.SuspendActivity;
                goto IL_92;

            case ActivityEventType.EndActivity:
                eventType2 = AssistantsEventType.EndActivity;
                goto IL_92;
            }
            base.SafeTraceDebug(0L, "Skip logging ActivityEvent '{0}'.", new object[]
            {
                eventType
            });
            return;

IL_92:
            List <KeyValuePair <string, object> > customData = WorkloadManagementLogger.FormatWlmActivity(activityScope, true);

            AssistantsLog.InternalLogRow(activityScope.ActivityId, assistantShortName, assistantBase, eventType2, customData, Guid.Empty);
        }
예제 #6
0
 private void Initialize(BudgetKey owner, IThrottlingPolicy policy, string policyPart, string policyValue, int backoffTime, string snapshot)
 {
     this.owner = owner.ToString();
     this.isServiceAccountBudget = owner.IsServiceAccountBudget;
     this.throttlingPolicyDN     = policy.GetIdentityString();
     this.budgetType             = owner.BudgetType;
     this.policyPart             = policyPart;
     this.policyValue            = policyValue;
     this.backoffTime            = backoffTime;
     this.snapshot = snapshot;
     ThrottlingPerfCounterWrapper.IncrementOverBudget(owner, TimeSpan.FromMilliseconds((double)backoffTime));
     WorkloadManagementLogger.SetOverBudget(policyPart, policyValue, null);
     WorkloadManagementLogger.SetBudgetType(owner.BudgetType.ToString(), null);
 }
예제 #7
0
        private void CalculateElapsedTime(CostHandle costHandle)
        {
            LocalTimeCostHandle localTimeCostHandle = costHandle as LocalTimeCostHandle;

            if (localTimeCostHandle != null)
            {
                TimeSpan unaccountedForTime = localTimeCostHandle.UnaccountedForTime;
                if (unaccountedForTime > TimeSpan.Zero)
                {
                    T t = this.GetInnerBudget();
                    if (t.CasTokenBucket.GetBalance() < 0f)
                    {
                        this.microDelayWorthyWork += unaccountedForTime;
                    }
                    else
                    {
                        this.microDelayWorthyWork = TimeSpan.Zero;
                    }
                    this.allWork += unaccountedForTime;
                    WorkloadManagementLogger.SetBudgetUsage(unaccountedForTime, null, null);
                }
            }
        }
        protected override void InternalLogActivityEvent(IActivityScope scope, ActivityEventType eventType)
        {
            List <KeyValuePair <string, object> > customData = null;

            switch (eventType)
            {
            case ActivityEventType.StartActivity:
            case ActivityEventType.ResumeActivity:
                break;

            case ActivityEventType.SuspendActivity:
            case ActivityEventType.EndActivity:
                customData = WorkloadManagementLogger.FormatWlmActivity(scope, true);
                break;

            default:
                MrsAndProxyActivityLogger.instance.SafeTraceDebug(0L, "Skip logging ActivityEvent '{0}'.", new object[]
                {
                    eventType
                });
                return;
            }
            MrsAndProxyActivityLogger.InternalLogRow(scope.ActivityId, ActivityContextLogger.ActivityEventTypeDictionary[eventType], scope.Action, scope.UserId, scope.ClientInfo, customData);
        }
        protected override void InternalDispose(bool disposing)
        {
            if (!this.isDisposeAlreadyCalled && disposing && this.ActivityScope != null)
            {
                lock (this.SyncRoot)
                {
                    if (!this.isDisposeAlreadyCalled)
                    {
                        this.excludeLogEntry |= this.SkipLogging;
                        try
                        {
                            if (this.ActivityScope.ActivityType == ActivityType.Request)
                            {
                                this.FetchLatencyData();
                                if (!this.excludeLogEntry)
                                {
                                    this.PreCommitTasks();
                                }
                            }
                            if (this.EndActivityContext && this.ActivityScope.Status == ActivityContextStatus.ActivityStarted)
                            {
                                this.ActivityScope.End();
                            }
                            if (!this.excludeLogEntry)
                            {
                                List <KeyValuePair <string, object> > formattableMetadata = this.ActivityScope.GetFormattableMetadata();
                                formattableMetadata.RemoveAll(delegate(KeyValuePair <string, object> pair)
                                {
                                    Enum @enum = ActivityContext.LookupEnum(pair.Key);
                                    return(object.Equals(@enum, RequestDetailsLoggerBase <T> .RequestLoggerConfig.GenericInfoColumn) || object.Equals(@enum, ActivityStandardMetadata.ReturnClientRequestId) || RequestDetailsLoggerBase <T> .enumToIndexMap.ContainsKey(@enum));
                                });
                                List <KeyValuePair <string, object> > collection = WorkloadManagementLogger.FormatWlmActivity(this.ActivityScope, false);
                                formattableMetadata.AddRange(collection);
                                foreach (KeyValuePair <Enum, int> keyValuePair in RequestDetailsLoggerBase <T> .enumToIndexMap)
                                {
                                    string text = this.Get(keyValuePair.Key);
                                    if (object.Equals(RequestDetailsLoggerBase <T> .RequestLoggerConfig.GenericInfoColumn, keyValuePair.Key))
                                    {
                                        text += LogRowFormatter.FormatCollection(formattableMetadata);
                                    }
                                    if (!string.IsNullOrEmpty(text))
                                    {
                                        text = RequestDetailsLoggerBase <T> .FormatForCsv(text);

                                        this.Row[keyValuePair.Value] = text;
                                    }
                                }
                                RequestDetailsLoggerBase <T> .Log.Append(this.Row, -1);

                                this.UploadDataToStreamInsight();
                            }
                        }
                        finally
                        {
                            if (this.ActivityScope != null && this.EndActivityContext && this.ActivityScope.Status == ActivityContextStatus.ActivityStarted)
                            {
                                this.ActivityScope.End();
                            }
                            this.isDisposeAlreadyCalled = true;
                        }
                    }
                }
            }
        }