コード例 #1
0
        /// <summary>
        /// This is the main entry point for your service replica.
        /// This method executes when this replica of your service becomes primary and has write status.
        /// </summary>
        /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param>
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            FabricClient fc = new FabricClient();

            this.telemetryEvents = new TelemetryEvents(fc, ServiceEventSource.Current);
            this.rmHelper        = new RepairManagerHelper(fc, this.Context);
            ICodePackageActivationContext activationContext = this.Context.CodePackageActivationContext;

            this.InitializeConfiguration(activationContext.GetConfigurationPackageObject("Config"));
            activationContext.ConfigurationPackageModifiedEvent += this.OnConfigurationPackageModified;
            await this.RunLoopAsync(cancellationToken);
        }
コード例 #2
0
        /// <summary>
        /// Assign event callbacks, so we can count and report at the end events rejected, dropped, sent and retried.
        /// </summary>
        private static void InitCallbacks()
        {
            TelemetryEvents telemetryEvents = LogManager.GetTelemetryEvents(out EVTStatus status);

            if (status != EVTStatus.OK)
            {
                Trace.TraceError($"Aria LogManager.GetTelemetryEvents failed with EVTStatus = {status}");
            }
            else
            {
                eventsRejected = 0;
                eventsRetry    = 0;
                eventsDropped  = 0;
                eventsSent     = 0;

                telemetryEvents.EventsRetrying += (sender, args) =>
                {
                    Trace.TraceInformation($"Aria retry event: {args.RetryReason}, {args.RetryDetails}");
                    Interlocked.Add(ref eventsRetry, args.EventsCount);
                };

                telemetryEvents.EventsDropped += (sender, args) =>
                {
                    Trace.TraceInformation($"Aria event dropped: {args.DroppedReason}, {args.DroppedDetails}");
                    Interlocked.Add(ref eventsDropped, args.EventsCount);
                };

                telemetryEvents.EventsSent += (sender, args) =>
                {
                    Interlocked.Add(ref eventsSent, args.EventsCount);
                };

                telemetryEvents.EventsRejected += (sender, args) =>
                {
                    Trace.TraceInformation($"Aria event rejected: {args.RejectedReason}, {args.RejectedDetails}");
                    Interlocked.Add(ref eventsRejected, args.EventsCount);
                };
            }
        }
コード例 #3
0
        //public void LogString(string stringLog)
        //{
        //    if (null != TestLog)
        //    {
        //        TestLog.Log(LogLevel.Info, stringLog);
        //    }
        //}

        public void LogTelemetryEvent(TelemetryEvents telemetryEvent)
        {
            // convert the event to a string
            string eventName = telemetryEvent.ToString();

            // log it
            switch (this.ActiveKey)
            {
            case TelemetryKeys.Test:
            default:
                if (null != TestLog)
                {
                    TestLog.Log(LogLevel.Info, eventName);
                }
                break;

            case TelemetryKeys.Prod:
                if (null != ProdLog)
                {
                    ProdLog.Log(eventName);
                }
                break;
            }
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObserverManager"/> class.
        /// </summary>
        public ObserverManager(
            StatelessServiceContext context,
            CancellationToken token)
        {
            this.token = token;
            this.cts   = new CancellationTokenSource();
            this.token.Register(() => { this.ShutdownHandler(this, null); });
            FabricClientInstance = new FabricClient();
            FabricServiceContext = context;
            this.nodeName        = FabricServiceContext?.NodeContext.NodeName;

            // Observer Logger setup.
            string logFolderBasePath = null;
            string observerLogPath   = GetConfigSettingValue(
                ObserverConstants.ObserverLogPath);

            if (!string.IsNullOrEmpty(observerLogPath))
            {
                logFolderBasePath = observerLogPath;
            }
            else
            {
                string logFolderBase = $@"{Environment.CurrentDirectory}\observer_logs";
                logFolderBasePath = logFolderBase;
            }

            // this logs metrics from observers, if enabled, and/or sends
            // telemetry data to your implemented provider.
            this.DataLogger = new DataTableFileLogger();

            // this logs error/warning/info messages for ObserverManager.
            this.Logger         = new Logger("ObserverManager", logFolderBasePath);
            this.HealthReporter = new ObserverHealthReporter(this.Logger);
            this.SetPropertiesFromConfigurationParameters();

            // Populate the Observer list for the sequential run loop.
            this.observers = GetObservers();

            // FabricObserver Internal Diagnostic Telemetry (Non-PII).
            // Internally, TelemetryEvents determines current Cluster Id as a unique identifier for transmitted events.
            if (FabricObserverInternalTelemetryEnabled)
            {
                string codePkgVersion         = FabricServiceContext.CodePackageActivationContext.CodePackageVersion;
                string serviceManifestVersion = FabricServiceContext.CodePackageActivationContext.GetConfigurationPackageObject("Config").Description.ServiceManifestVersion;
                string filepath = Path.Combine(logFolderBasePath, $"fo_telemetry_sent_{codePkgVersion.Replace(".", string.Empty)}_{serviceManifestVersion.Replace(".", string.Empty)}_{FabricServiceContext.NodeContext.NodeType}.txt");
#if !DEBUG
                // If this has already been sent for this activated version (code/config) of nodetype x
                if (File.Exists(filepath))
                {
                    return;
                }
#endif
                this.telemetryEvents = new TelemetryEvents(
                    FabricClientInstance,
                    FabricServiceContext,
                    ServiceEventSource.Current,
                    this.token);

                if (this.telemetryEvents.FabricObserverRuntimeNodeEvent(
                        codePkgVersion,
                        this.GetFabricObserverInternalConfiguration(),
                        "HealthState.Initialized"))
                {
                    // Log a file to prevent re-sending this in case of process restart(s).
                    // This non-PII FO/Cluster info is versioned and should only be sent once per deployment (config or code updates.).
                    _ = this.Logger.TryWriteLogFile(filepath, "_");
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObserverManager"/> class.
        /// </summary>
        /// <param name="context">service context.</param>
        /// <param name="token">cancellation token.</param>
        public ObserverManager(IServiceProvider serviceProvider, CancellationToken token)
        {
            this.token = token;
            this.cts   = new CancellationTokenSource();
            this.linkedSFRuntimeObserverTokenSource = CancellationTokenSource.CreateLinkedTokenSource(this.cts.Token, this.token);
            FabricClientInstance = new FabricClient();
            FabricServiceContext = serviceProvider.GetRequiredService <StatelessServiceContext>();
            this.nodeName        = FabricServiceContext?.NodeContext.NodeName;
            FabricServiceContext.CodePackageActivationContext.ConfigurationPackageModifiedEvent += CodePackageActivationContext_ConfigurationPackageModifiedEvent;

            // Observer Logger setup.
            string logFolderBasePath;
            string observerLogPath = GetConfigSettingValue(
                ObserverConstants.ObserverLogPathParameter);

            if (!string.IsNullOrEmpty(observerLogPath))
            {
                logFolderBasePath = observerLogPath;
            }
            else
            {
                string logFolderBase = Path.Combine(Environment.CurrentDirectory, "observer_logs");
                logFolderBasePath = logFolderBase;
            }

            // this logs error/warning/info messages for ObserverManager.
            this.Logger         = new Logger("ObserverManager", logFolderBasePath);
            this.HealthReporter = new ObserverHealthReporter(this.Logger);
            this.SetPropertieSFromConfigurationParameters();
            this.serviceCollection = serviceProvider.GetServices <ObserverBase>();

            // Populate the Observer list for the sequential run loop.
            this.observers = this.serviceCollection.Where(o => o.IsEnabled).ToList();

            // FabricObserver Internal Diagnostic Telemetry (Non-PII).
            // Internally, TelemetryEvents determines current Cluster Id as a unique identifier for transmitted events.
            if (!FabricObserverInternalTelemetryEnabled)
            {
                return;
            }

            if (FabricServiceContext == null)
            {
                return;
            }

            string codePkgVersion         = FabricServiceContext.CodePackageActivationContext.CodePackageVersion;
            string serviceManifestVersion = FabricServiceContext.CodePackageActivationContext.GetConfigurationPackageObject("Config").Description.ServiceManifestVersion;
            string filepath = Path.Combine(this.Logger.LogFolderBasePath, $"fo_telemetry_sent_{codePkgVersion.Replace(".", string.Empty)}_{serviceManifestVersion.Replace(".", string.Empty)}_{FabricServiceContext.NodeContext.NodeType}.log");

#if !DEBUG
            // If this has already been sent for this activated version (code/config) of nodetype x
            if (File.Exists(filepath))
            {
                return;
            }
#endif
            this.telemetryEvents = new TelemetryEvents(
                FabricClientInstance,
                FabricServiceContext,
                ServiceEventSource.Current,
                this.token);

            string foInternalTelemetryData = this.GetFabricObserverInternalConfiguration();
            if (this.telemetryEvents.FabricObserverRuntimeNodeEvent(
                    codePkgVersion,
                    foInternalTelemetryData,
                    "HealthState.Initialized"))
            {
                // Log a file to prevent re-sending this in case of process restart(s).
                // This non-PII FO/Cluster info is versioned and should only be sent once per deployment (config or code updates.).
                _ = this.Logger.TryWriteLogFile(filepath, foInternalTelemetryData);
            }
        }