Skip to content
This repository was archived by the owner on Aug 15, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions EventGenerator/EventGenerator.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventGenerator", "EventGenerator\EventGenerator.csproj", "{C3DBE575-343E-4C6D-9E89-4A4032A81A68}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C3DBE575-343E-4C6D-9E89-4A4032A81A68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3DBE575-343E-4C6D-9E89-4A4032A81A68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3DBE575-343E-4C6D-9E89-4A4032A81A68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3DBE575-343E-4C6D-9E89-4A4032A81A68}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6D315680-7A26-4A3E-A536-87E729253BD8}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using EventGenerator.Models;

namespace EventGenerator.BusinessLogic
{
public class EventGenerationManager : IEventGenerationManager
{
private readonly IEventGeneratorRegistry _generatorRegistry;

public EventGenerationManager(IEventGeneratorRegistry generatorRegistry)
{
_generatorRegistry = generatorRegistry;
}

public bool Send(EventType argsEventType, int argsCount)
{
var generator = _generatorRegistry.Get(argsEventType);
if (generator != null)
{
generator.Generate(argsCount);
return true;
}
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Concurrent;
using EventGenerator.Models;

namespace EventGenerator.BusinessLogic
{
public class EventGeneratorRegistry : IEventGeneratorRegistry
{
private readonly ConcurrentDictionary<EventType, IEventGenerator> _registry;

public EventGeneratorRegistry() => _registry = new ConcurrentDictionary<EventType, IEventGenerator>();

public void Add(EventType eventType, IEventGenerator generator) => _registry[eventType] = generator;

public IEventGenerator Get(EventType eventType) =>
_registry.TryGetValue(eventType, out var result) ? result : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using EventGenerator.Models;

namespace EventGenerator.BusinessLogic
{
public interface IEventGenerationManager
{
bool Send(EventType argsEventType, int argsCount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EventGenerator.BusinessLogic
{
public interface IEventGenerator
{
void Generate(int count);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using EventGenerator.Models;

namespace EventGenerator.BusinessLogic
{
public interface IEventGeneratorRegistry
{
void Add(EventType eventType, IEventGenerator generator);
IEventGenerator Get(EventType eventType);
}
}
20 changes: 20 additions & 0 deletions EventGenerator/EventGenerator/BusinessLogic/LogEventGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Vostok.Logging;

namespace EventGenerator.BusinessLogic
{
public class LogEventGenerator : IEventGenerator
{
private readonly ILog _log;

public LogEventGenerator(ILog log)
{
_log = log;
}

public void Generate(int count)
{
for (int i = 0; i < count; i++)
_log.Info("Generate info log event");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Vostok.Metrics;
using Vostok.Metrics.Meters;

namespace EventGenerator.BusinessLogic
{
public class MetricEventGenerator : IEventGenerator
{
private readonly ICounter _counter;

public MetricEventGenerator(IMetricScope scope)
{
_counter = scope.Counter(TimeSpan.FromMilliseconds(100), "generated");
}

public void Generate(int count)
{
for (var i = 0; i < count; i++)
_counter.Add();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему-то эти .Add не считаются, счётчик постоянно посылает ноли. Иногда, редко, .Add всё-таки учитывается. Почему так?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наверное слишком часто шлешь. Графит имеет разрешение 10 секунд. Например у тебя в эти 10 секунд 100 отправок в графит. Вероятность, что будет последним ноль довольно велика. Из всех отправок записывается только последняя.

}
}
}
25 changes: 25 additions & 0 deletions EventGenerator/EventGenerator/BusinessLogic/TraceEventGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Vostok.Tracing;

namespace EventGenerator.BusinessLogic
{
public class TraceEventGenerator : IEventGenerator
{
public void Generate(int count)
{
for (int i = 0; i < count; i++)
{
using (var spanBuilder = Trace.BeginSpan())
{
spanBuilder.SetAnnotation(TracingAnnotationNames.Operation, "Generate Trace");
spanBuilder.SetAnnotation(TracingAnnotationNames.Kind, "loadtest");
spanBuilder.SetAnnotation(TracingAnnotationNames.Service, "event-generator");
spanBuilder.SetAnnotation(TracingAnnotationNames.Host, "localhost");
spanBuilder.SetAnnotation(TracingAnnotationNames.HttpUrl, "send");
spanBuilder.SetAnnotation(TracingAnnotationNames.HttpRequestContentLength, 1024);
spanBuilder.SetAnnotation(TracingAnnotationNames.HttpResponseContentLength, 2048);
spanBuilder.SetAnnotation(TracingAnnotationNames.HttpCode, 200);
}
}
}
}
}
28 changes: 28 additions & 0 deletions EventGenerator/EventGenerator/Controllers/GenerateController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using EventGenerator.BusinessLogic;
using EventGenerator.Models;
using Microsoft.AspNetCore.Mvc;

namespace EventGenerator.Controllers
{
[Route("/[controller]")]
public class GenerateController : Controller
{
private readonly IEventGenerationManager _manager;

public GenerateController(IEventGenerationManager manager)
{
_manager = manager;
}

[HttpPost]
public IActionResult Index([FromBody] GenerateEventsArgs args)
{
if (ModelState.IsValid)
{
var ok = _manager.Send(args.EventType, args.Count);
return ok ? Ok() : StatusCode(500);
}
return BadRequest(ModelState);
}
}
}
26 changes: 26 additions & 0 deletions EventGenerator/EventGenerator/EventGenerator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Vostok.Instrumentation.AspNetCore" Version="1.0.0-pre000108" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions EventGenerator/EventGenerator/Models/EventType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace EventGenerator.Models
{
public enum EventType
{
Logs,
Trace,
Metric
}
}
14 changes: 14 additions & 0 deletions EventGenerator/EventGenerator/Models/GenerateEventsArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace EventGenerator.Models
{
public class GenerateEventsArgs
{
[Required]
public EventType EventType { get; set; }

[Range(1, 10000)]
public int Count { get; set; } = 1;
}
}
52 changes: 52 additions & 0 deletions EventGenerator/EventGenerator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Vostok.Instrumentation.AspNetCore;
using Vostok.Logging;
using Vostok.Logging.Serilog;

namespace EventGenerator
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile("appsettings.json", false, true);
})
.UseUrls("http://*:5000")
.ConfigureLogging(ConfigureLogging)
.ConfigureAirlock()
.ConfigureVostokMetrics()
.ConfigureVostokTracing()
.UseStartup<Startup>()
.Build();

private static void ConfigureLogging(WebHostBuilderContext context, ILoggingBuilder builder)
{
var loggingSection = context.Configuration.GetSection("logging");
var rollingFileSection = loggingSection.GetSection("rollingFile");
var rollingFilePathFormat = rollingFileSection.GetValue<string>("pathFormat");
var service = context.Configuration.GetValue<string>("service");
var template = "{Timestamp:HH:mm:ss.fff} {Level} {Message:l} {Exception}{NewLine}{Properties}{NewLine}";

Log.Logger = new LoggerConfiguration()
.Enrich.WithProperty("Service", service)
.WriteTo.Async(x => x.RollingFile(rollingFilePathFormat, outputTemplate: template))
.CreateLogger();
var log = new SerilogLog(Log.Logger).WithFlowContext();

builder.AddVostok(log);
builder.Services.AddSingleton(log);
}
}
}
29 changes: 29 additions & 0 deletions EventGenerator/EventGenerator/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:58226/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"EventGenerator": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:58227/"
}
}
}
11 changes: 7 additions & 4 deletions tank/README.md → EventGenerator/EventGenerator/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
0. Запустить EventGenerator:

> dotnet EventGenerator.dll

1. Создать рабочий каталог для танка и перейти в него. В этом каталоге танк оставит логи

> md tank
> cd tank

2. Скопировать в рабочий каталог конфиг танка vostok.yaml.
2. Скопировать в рабочий каталог конфиг танка tank-vostok.yaml.

3. Скопировать в рабочий каталог нужный файл с патронами в файл ammo:

> cp ammo-logs.txt ammo

4. Запустить танк:

docker run -v $(pwd):/var/loadtest -v $HOME/.ssh:/root/.ssh --net host -it direvius/yandex-tank -c vostok.yaml

5. Логи танка будут в каталоге logs.
docker run -v $(pwd):/var/loadtest -v $HOME/.ssh:/root/.ssh --net host -it direvius/yandex-tank -c tank-vostok.yaml

5. Логи танка будут в каталоге logs.
Loading