public void TestSetup() { factory = Substitute.For <IStreamStateFactory>(); factory.Create(Arg.Any <string>()).Returns(_ => state); state = Substitute.For <IStreamState>(); state.BufferPool.Returns(_ => pool); state.Statistics.Returns(_ => stats); state.RecordWriter.Returns(_ => writer); state.SendSignal.Returns(new AsyncManualResetEvent(false)); buffer = Substitute.For <IBuffer>(); writer = Substitute.For <IRecordWriter>(); stats = Substitute.For <IStatisticsCollector>(); daemon = Substitute.For <IDaemon>(); pool = Substitute.For <IBufferPool>(); pool.TryAcquire(out _) .Returns( info => { info[0] = buffer; return(true); }); log = new SynchronousConsoleLog(); sink = new HerculesSink(factory, daemon, log); }
public static IMetricContext Get([NotNull] HerculesSinkSettings settings, [CanBeNull] ILog log) { if (defaultMetricContext != null) { return(defaultMetricContext); } lock (Sync) { if (defaultMetricContext != null) { return(defaultMetricContext); } var memoryLimit = 8 * 1024 * 1024; var sinkSettings = new HerculesSinkSettings(settings.Cluster, settings.ApiKeyProvider) { AdditionalSetup = settings.AdditionalSetup, MaximumMemoryConsumption = memoryLimit, MaximumPerStreamMemoryConsumption = memoryLimit }; log = (log ?? LogProvider.Get()).WithMinimumLevel(LogLevel.Warn); var sink = new HerculesSink(sinkSettings, log); var metricsSender = new HerculesMetricSender(new HerculesMetricSenderSettings(sink)); return(defaultMetricContext = new MetricContext(new MetricContextConfig(metricsSender))); } }
public HerculesSinkMetricsCounters(IMetricContext context, HerculesSink herculesSink) { this.herculesSink = herculesSink; tags = context.Tags; registration = context.Register(this, null); }
private HerculesSinkMetrics(HerculesSink herculesSink, IMetricContext context, ILog log) { this.log = log.ForContext <HerculesSink>(); this.herculesSink = herculesSink; tags = context.Tags; context.Register(this, ScrapePeriod); }
public static void InitializeHerculesLogger(string command) { if (!(herculesLog is null)) { return; } var configLogFilePath = Path.Combine(Helper.GetCementInstallDirectory(), "dotnet", "herculeslog.config.json"); if (!File.Exists(configLogFilePath)) { ConsoleWriter.WriteError($"{configLogFilePath} not found."); return; } var configuration = new ConfigurationBuilder() .AddJsonFile(configLogFilePath) .Build() .Get <HerculesLogConfiguration>(); if (!configuration.Enabled) { return; } var settings = new HerculesSinkSettings(new FixedClusterProvider(configuration.ServerUrl), () => configuration.ApiKey) { MaximumMemoryConsumption = configuration.MaximumMemoryConsumptionInBytes }; var fileLogForHercules = GetFileLogger("hercules"); var herculesSink = new HerculesSink(settings, fileLogForHercules); herculesLog = new HerculesLog(new HerculesLogSettings(herculesSink, configuration.Stream)) .WithProperties( new Dictionary <string, object> { ["project"] = configuration.Project, ["environment"] = configuration.Environment, ["hostName"] = ObtainHostname(), ["command"] = command }); disposables.Add(herculesSink); loggerFactory.AddVostok(herculesLog); }
private Hercules() { var log = new SynchronousConsoleLog(); Cluster = HerculesCluster.DeployNew(TestContext.CurrentContext.TestDirectory, log.WithMinimumLevel(LogLevel.Warn)); string GetApiKey() => Cluster.ApiKey; var managementSettings = new HerculesManagementClientSettings( Cluster.HerculesManagementApiTopology, GetApiKey); var streamSettings = new HerculesStreamClientSettings( Cluster.HerculesStreamApiTopology, GetApiKey); var metricsStreamSettings = new HerculesStreamClientSettings <MetricEvent>( Cluster.HerculesStreamApiTopology, GetApiKey, buffer => new HerculesMetricEventReader(buffer)); var gateSettings = new HerculesGateClientSettings( Cluster.HerculesGateTopology, GetApiKey); var sinkSettings = new HerculesSinkSettings( Cluster.HerculesGateTopology, GetApiKey) { SendPeriod = 1.Seconds() }; Management = new HerculesManagementClient( managementSettings, log); Sink = new HerculesSink(sinkSettings, log); Stream = new HerculesStreamClient(streamSettings, log); MetricsStream = new HerculesStreamClient <MetricEvent>(metricsStreamSettings, log); Gate = new HerculesGateClient(gateSettings, log); }
public void Setup() { transport = Substitute.For <ITransport>(); transport.Capabilities.Returns( TransportCapabilities.RequestStreaming | TransportCapabilities.ResponseStreaming | TransportCapabilities.RequestCompositeBody); var settings = new HerculesSinkSettings(new FixedClusterProvider(new Uri("http://localhost/")), () => "apiKey") { AdditionalSetup = c => c.Transport = transport, SuppressVerboseLogging = false, SendPeriod = 100.Milliseconds() }; sink = new HerculesSink(settings, new SynchronousConsoleLog()); SetResponse(Responses.Ok); }
public Hercules() { log = new SynchronousConsoleLog(); cluster = HerculesCluster.DeployNew(TestContext.CurrentContext.TestDirectory, log.WithMinimumLevel(LogLevel.Warn)); string GetApiKey() => cluster.ApiKey; var managementSettings = new HerculesManagementClientSettings( cluster.HerculesManagementApiTopology, GetApiKey); var streamSettings = new HerculesStreamClientSettings( cluster.HerculesStreamApiTopology, GetApiKey); var gateSettings = new HerculesGateClientSettings( cluster.HerculesGateTopology, GetApiKey); var sinkSettings = new HerculesSinkSettings( cluster.HerculesGateTopology, GetApiKey) { SendPeriod = 1.Seconds() }; Management = new HerculesManagementClient( managementSettings, log); Sink = new HerculesSink(sinkSettings, log); Stream = new HerculesStreamClient(streamSettings, log); Gate = new HerculesGateClient(gateSettings, log); }
public HerculesSinkInfoProvider(HerculesSink sink) => this.sink = sink;
private HerculesSinkMetrics(HerculesSink herculesSink, IMetricContext context, ILog log) { this.log = log.ForContext <HerculesSink>(); this.herculesSink = herculesSink; tags = context.Tags; }
public static HerculesSinkMetricsCounters CreateHerculesSinkMetricsCounters([NotNull] this IMetricContext metricContext, [NotNull] HerculesSink herculesSink) => new HerculesSinkMetricsCounters(metricContext, herculesSink);
public static HerculesSink SetupMetrics([NotNull] this HerculesSink sink, [NotNull] IMetricContext metricContext) { metricContext.CreateHerculesSinkMetricsCounters(sink); return(sink); }