private static bool InternalRemoveFilter(TraceSinkType sinkType, string taskName) { string eventName = null; int index = taskName.IndexOf('.'); if (index >= 0) { eventName = taskName.Substring(index + 1).Trim(); taskName = taskName.Substring(0, index).Trim(); } EventTask taskId; if (!string.IsNullOrEmpty(taskName)) { taskId = FabricEvents.Events.GetEventTask(taskName); if (taskId == FabricEvents.Tasks.Max) { return(false); } } else { taskId = FabricEvents.Tasks.Max; } TraceSinkFilter filter = SinkFilters[(int)sinkType]; lock (SyncLock) { filter.RemoveFilter(taskId, eventName); } return(true); }
/// <summary> /// Add filter for a sink. /// </summary> /// <param name="sink">Type of the sink.</param> /// <param name="taskName">Task name.</param> /// <param name="eventName">Event name.</param> /// <param name="level">Level for the filter.</param> /// <param name="samplingRatio">Sampling ratio for records below the level.</param> /// <returns>Whether the filter is set correctly.</returns> private static bool InternalAddFilter(TraceSinkType sink, string taskName, string eventName, EventLevel level, int samplingRatio) { EventTask taskId; if (!string.IsNullOrEmpty(taskName)) { taskId = FabricEvents.Events.GetEventTask(taskName); if (taskId == FabricEvents.Tasks.Max) { return(false); } } else { taskId = FabricEvents.Tasks.Max; } TraceSinkFilter filter = SinkFilters[(int)sink]; lock (SyncLock) { filter.AddFilter(taskId, eventName, level, samplingRatio); } return(true); }
/// <summary> /// Update the Status of the Provisional Feature /// </summary> /// <param name="sinkType">Type of the sink</param> /// <param name="isEnabled">If the feature is enabled or not</param> public void UpdateProvisionalFeatureStatus(TraceSinkType sinkType, bool isEnabled) { if (sinkType == TraceSinkType.ETW) { this.isProvisionalFeatureEnabled = isEnabled; } }
public void UpdateSinkSamplingRatio(TraceSinkType sinkType, int newSamplingRatio) { if (sinkType == TraceSinkType.ETW) { this.samplingRatio = newSamplingRatio; } }
public TraceSinkFilter(TraceSinkType sinkType, EventLevel defaultLevel) { this.sinkType = sinkType; this.defaultLevel = defaultLevel; this.defaultSamplingRatio = 0; this.filters = new List <TraceFilterDescription>(); this.isProvisionalFeatureEnabledForCurrentSinkType = DefaultProvisionalFeatureState; }
private static void SetDefaultConfigFilters(IReadOnlyList <TraceSinkFilter> filters) { for (int i = 0; i < filters.Count; i++) { TraceSinkType sink = (TraceSinkType)i; var level = sink == TraceSinkType.Console ? EventLevel.LogAlways : EventLevel.Informational; filters[i].DefaultLevel = level; } }
public static bool AddFilter(TraceSinkType sinkType, string filter) { if (!InternalAddFilter(sinkType, filter)) { return(false); } OnFilterUpdate(sinkType); return(true); }
public static bool RemoveFilter(TraceSinkType sinkType, string source) { if (!InternalRemoveFilter(sinkType, source)) { return(false); } OnFilterUpdate(sinkType); return(true); }
public static bool GetEventProvisionalFeatureStatus(TraceSinkType sinkType) { bool featureStatus; lock (SyncLock) { featureStatus = SinkFilters[(int)sinkType].ProvisionalFeatureStatus; } return(featureStatus); }
private static TraceSinkFilter[] CreateSinkFilters() { TraceSinkFilter[] filters = new TraceSinkFilter[(int)TraceSinkType.Max]; for (int i = 0; i < filters.Length; i++) { TraceSinkType sink = (TraceSinkType)i; filters[i] = new TraceSinkFilter(sink, EventLevel.LogAlways); } SetDefaultConfigFilters(filters); return(filters); }
public static bool GetEventEnabledStatus( TraceSinkType sinkType, EventLevel level, EventTask taskId, string eventName) { lock (SyncLock) { int garbage; return(SinkFilters[(int)sinkType].StaticCheck( level, taskId, eventName, out garbage)); } }
/// <summary> /// Add filter for a sink. /// </summary> /// <param name="sinkType">Type of the sink.</param> /// <param name="filter">The filter to be applied for the sink. /// Syntax: task.event@id:level /// </param> /// <returns>Whether the filter is set correctly.</returns> private static bool InternalAddFilter(TraceSinkType sinkType, string filter) { int index = filter.LastIndexOf(':'); if (index < 0) { return(false); } string source = filter.Substring(0, index).Trim(); string levelString = filter.Substring(index + 1).Trim(); int samplingRatio = 0; index = levelString.IndexOf('#'); if (index > 0) { string ratioString = levelString.Substring(index + 1).Trim(); levelString = levelString.Substring(0, index).Trim(); double ratio; if (double.TryParse(ratioString, out ratio)) { samplingRatio = ConvertSamplingRatio(ratio); } } int level; if (!int.TryParse(levelString, out level)) { return(false); } string secondLevel = null; index = source.IndexOf('.'); if (index >= 0) { secondLevel = source.Substring(index + 1).Trim(); source = source.Substring(0, index).Trim(); } return(InternalAddFilter(sinkType, source, secondLevel, ConvertLevel(level), samplingRatio)); }
public static int GetEventSamplingRatio( TraceSinkType sinkType, EventLevel level, EventTask taskId, string eventName) { int samplingRatio; lock (SyncLock) { SinkFilters[(int)sinkType].StaticCheck( level, taskId, eventName, out samplingRatio); } return(samplingRatio); }
private static void InitializeTraceProvisionalFeatureStatus(IConfigReader configStore, string configSection, TraceSinkType sinkType) { SinkFilters[(int)sinkType].ProvisionalFeatureStatus = configStore.ReadTraceProvisionalFeatureStatus(configSection); }
public void UpdateSinkEnabledStatus(TraceSinkType sinkType, bool enabled) { this.filterStates[(int)sinkType] = enabled; }
private static void InitializeFilters(IConfigReader configStore, string configSection, TraceSinkType sinkType) { SinkFilters[(int)sinkType].ClearFilters(); var filterString = configStore.ReadFiltersKey(configSection); if (!string.IsNullOrEmpty(filterString)) { var tokens = filterString.Split(FilterValueSeparatorArray, System.StringSplitOptions.RemoveEmptyEntries); foreach (var token in tokens) { InternalAddFilter(sinkType, token); } } }
private static void InitializeTraceSamplingRatio(IConfigReader configStore, string configSection, TraceSinkType sinkType) { SinkFilters[(int)sinkType].DefaultSamplingRatio = configStore.ReadTraceSamplingKey(configSection); }
public static void SetDefaultSamplingRatio(TraceSinkType sinkType, double samplingRatio) { SinkFilters[(int)sinkType].DefaultSamplingRatio = ConvertSamplingRatio(samplingRatio); OnFilterUpdate(sinkType); }
public TraceEvent( IVariantEventWriter variantEventWriter, EventTask taskId, ushort eventId, string eventName, EventLevel level, EventOpcode opcode, EventChannel channel, EventKeywords keywords, string format, bool hasId, ProvisionalMetadataAttribute provisionalAttribute, int typeFieldIndex, EventExtendedMetadataAttribute extendedMetadataAttribute = null) { if (string.IsNullOrEmpty(eventName)) { throw new ArgumentException( StringResources.Error_EventNameNullOrEmpty, "eventName"); } // We need to apply a keyword mask to the keyword in order for it to show up // in the Windows Event Log. The mask that is applied depends on the channel // in which we want the event to show up. // // TODO: We are currently hard-coding the mask values, but this is not ideal // because we have reverse-engineered these values by looking at the header // file generated by mc.exe. The algorithm to determine these values is an // internal implementation detail of mc.exe. A better alternative would be // to get the mask value from the source file generated by mc.exe, instead // of hard-coding it as a constant here. ulong keywordMask = 0; switch (channel) { case EventChannel.Admin: keywordMask = AdminChannelKeywordMask; break; case EventChannel.Debug: keywordMask = DebugChannelKeywordMask; break; case EventChannel.Operational: keywordMask = OperationalChannelKeywordMask; break; } long keywordWithMask; unchecked { keywordWithMask = (long)((ulong)keywords | keywordMask | TestKeyword); } // We ignore the opcode field for now. Manifest generation does the same. this.descriptor = new GenericEventDescriptor( eventId, version, (byte)channel, (byte)level, 0, (int)taskId, keywordWithMask); this.eventName = eventName; this.taskId = taskId; this.level = level; this.filterStates = new bool[(int)TraceSinkType.Max]; this.samplingRatio = 0; this.hasId = hasId; this.typeFieldIndex = typeFieldIndex; this.format = format; this.taskName = typeof(FabricEvents.Tasks).GetFields().Single(f => (EventTask)f.GetRawConstantValue() == taskId).Name; this.variantEventWriter = variantEventWriter; // By default, provisional feature is disabled during object initialization. This needs to be enabled // by calling the Update function. this.isProvisionalFeatureEnabled = false; this.provisionalData = provisionalAttribute; if (this.provisionalData != null) { this.isProvisionalEvent = true; this.provisionalCache = AgeBasedCache <VariantId, Variant[]> .DefaultInstance; this.PopulatePositions(); } for (TraceSinkType sink = 0; sink < TraceSinkType.Max; sink++) { var status = TraceConfig.GetEventEnabledStatus(sink, this.level, this.taskId, this.eventName); var sampling = TraceConfig.GetEventSamplingRatio(sink, this.level, this.taskId, this.eventName); this.UpdateProvisionalFeatureStatus(sink, TraceConfig.GetEventProvisionalFeatureStatus(sink)); this.UpdateSinkEnabledStatus(sink, status); this.UpdateSinkSamplingRatio(sink, sampling); } #if DotNetCoreClrLinux // TODO - Following code will be removed once fully transitioned to structured traces in Linux this.linuxStructuredTracesEnabled = TraceConfig.GetLinuxStructuredTracesEnabled(); TraceConfig.OnLinuxStructuredTracesEnabledUpdate += this.UpdateLinuxStructuredTracesEnabled; #endif this.ExtendedMetadata = extendedMetadataAttribute; }
/// <summary> /// Set default level for a sink type. /// </summary> /// <param name="sinkType">Type of the sink.</param> /// <param name="level">Default level for the sink.</param> public static void SetDefaultLevel(TraceSinkType sinkType, EventLevel level) { SinkFilters[(int)sinkType].DefaultLevel = level; OnFilterUpdate(sinkType); }