This repository was archived by the owner on Aug 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
EventGenerator #1
Open
tkirill
wants to merge
14
commits into
master
Choose a base branch
from
event-generator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
89408ae
+ Empty ASP.NET Core 2 project EventGenerator
tkirill c5e64ac
+ GenerateController with validation
tkirill f805c79
Install Vostok.Core package
tkirill c231772
Implement a minimal working version of logs generator.
tkirill f5b1255
+ EventGeneratorRegistry
tkirill 93602a9
Use separate ILog for LogEventGenerator.
tkirill 4faa398
+ TraceEventGenerator
tkirill ddeda31
+ MetricEventGenerator
tkirill 0b7e964
Make generation of events synchronous.
tkirill 24db889
Generate specified number of events in LogEventGenerator and TraceEve…
tkirill 3ccfe48
Set default count value to 1
tkirill c7902c1
Remove ValuesController
tkirill d0c991a
Add ammo files for Yandex Tank.
tkirill e2f1d90
Remove tank catalog
tkirill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
25 changes: 25 additions & 0 deletions
25
EventGenerator/EventGenerator/BusinessLogic/EventGenerationManager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
EventGenerator/EventGenerator/BusinessLogic/EventGeneratorRegistry.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
EventGenerator/EventGenerator/BusinessLogic/IEventGenerationManager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
EventGenerator/EventGenerator/BusinessLogic/IEventGenerator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace EventGenerator.BusinessLogic | ||
| { | ||
| public interface IEventGenerator | ||
| { | ||
| void Generate(int count); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
EventGenerator/EventGenerator/BusinessLogic/IEventGeneratorRegistry.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
20
EventGenerator/EventGenerator/BusinessLogic/LogEventGenerator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
EventGenerator/EventGenerator/BusinessLogic/MetricEventGenerator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
EventGenerator/EventGenerator/BusinessLogic/TraceEventGenerator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
28
EventGenerator/EventGenerator/Controllers/GenerateController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
14
EventGenerator/EventGenerator/Models/GenerateEventsArgs.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
29
EventGenerator/EventGenerator/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему-то эти
.Addне считаются, счётчик постоянно посылает ноли. Иногда, редко,.Addвсё-таки учитывается. Почему так?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Наверное слишком часто шлешь. Графит имеет разрешение 10 секунд. Например у тебя в эти 10 секунд 100 отправок в графит. Вероятность, что будет последним ноль довольно велика. Из всех отправок записывается только последняя.