Пример #1
0
        /// <summary>
        /// Handles a <see cref="TelemetryEvent"/> that is being streamed to Kusto.
        /// </summary>
        /// <param name="event">The event being handled.</param>
        internal virtual void HandleKustoEvent(TelemetryEvent @event)
        {
            var eventType = @event.GetType();

            KustoQueuedIngestionProperties ingestProps;

            if (!KustoMappings.ContainsKey(eventType) && KustoMappings.TryAdd(eventType, new KustoQueuedIngestionProperties(KustoDbName, "Unknown")))
            {
                ingestProps = KustoMappings[eventType];

                ingestProps.TableName            = KustoAdminClient.GenerateTableFromType(eventType);
                ingestProps.JSONMappingReference = KustoAdminClient.GenerateTableJsonMappingFromType(eventType);
                ingestProps.ReportLevel          = IngestionReportLevel.FailuresOnly;
                ingestProps.ReportMethod         = IngestionReportMethod.Queue;
                ingestProps.FlushImmediately     = true;
                ingestProps.Format = DataSourceFormat.json;
            }
            else
            {
                ingestProps = KustoMappings[eventType];
            }

            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                {
                    writer.WriteLine(JsonConvert.SerializeObject(@event));
                    writer.Flush();
                    stream.Seek(0, SeekOrigin.Begin);

                    KustoIngestClient.IngestFromStream(stream, ingestProps, leaveOpen: true);
                }
        }
Пример #2
0
        public async Task <bool> Fuzz(int pct)
        {
            try
            {
                log.LogInformation($"{myTargetType} Fuzzer run against {curSubName} -> {curRGName} start");

                using (var memStream = new MemoryStream())
                {
                    using (var sr = new StreamWriter(memStream))
                    {
                        bool hasWrites = false;


                        foreach (Microsoft.Azure.Management.ResourceManager.Fluent.Core.IResource curResource in myResourceCollection)
                        {
                            int nextRnd = rnd.Next(100);
                            log.LogInformation($"Got {myTargetType}: {curResource.Name}. Will reboot if {nextRnd} is <= {pct}");
                            if (nextRnd <= pct)
                            {
                                hasWrites = true;
                                log.LogInformation($"Turning off {myTargetType} for 3 minutes: {curResource.Name}");
                                sr.WriteLine($"{DateTime.UtcNow.ToString()}, {curSubName},{curRGName},{curResource.Name},{myTargetType+"FaultInjection"},{1}");
                                bool result = turnOff(curResource);
                                log.LogInformation($"Turn Off Result: {result}");
                                // Sleep for a minimum of 3 minutes - an implementor can wait longer if they choose to add
                                log.LogInformation($"Sleeping...");
                                Thread.Sleep(TimeSpan.FromMinutes(3));
                                log.LogInformation($"Turning on {myTargetType}: {curResource.Name}");
                                sr.WriteLine($"{DateTime.UtcNow.ToString()}, {curSubName},{curRGName},{curResource.Name},{myTargetType + "FaultInjection"},{0}");
                                result = turnOn(curResource);
                                log.LogInformation($"Turn On Result: {result}");
                            }
                        }


                        if (hasWrites)
                        {
                            sr.Flush();
                            memStream.Seek(0, SeekOrigin.Begin);
                            ingestClient.IngestFromStream(memStream, ingestProps);
                        }
                    }
                }
                log.LogInformation($"VM Fuzzer run against {curSubName} -> {curRGName} complete");
                return(true);
            }
            catch (Exception err)
            {
                log.LogError($"Error in VM Fuzzer: {err}");
                return(false);
            }
        }
Пример #3
0
        public void IngestData(string table, string mappingName, Stream memStream)
        {
            var ingestProps =
                new KustoQueuedIngestionProperties(DatabaseName, table)
            {
                ReportLevel          = IngestionReportLevel.FailuresAndSuccesses,
                ReportMethod         = IngestionReportMethod.Queue,
                JSONMappingReference = mappingName,
                Format = DataSourceFormat.json
            };

            _ingestionClient.IngestFromStream(memStream, ingestProps, leaveOpen: true);

            // Wait and retrieve all notifications
            Thread.Sleep(10000);
            var errors    = _ingestionClient.GetAndDiscardTopIngestionFailuresAsync().GetAwaiter().GetResult();
            var successes = _ingestionClient.GetAndDiscardTopIngestionSuccessesAsync().GetAwaiter().GetResult();

            errors.ForEach((f) => { Logger.Error($"Ingestion error: {f.Info.Details}."); });
            successes.ForEach((s) => { Logger.Info($"Ingested : {s.Info.IngestionSourcePath}"); });
        }