Skip to content

Commit

Permalink
feat: creates the consumer dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Lima authored Jul 2, 2021
1 parent 0c138bf commit 8f4edf8
Show file tree
Hide file tree
Showing 133 changed files with 21,307 additions and 213 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@ jobs:
with:
dotnet-version: 3.1.403

- name: Build
- name: Setup Node 14.x
uses: actions/setup-node@v1
with:
node-version: '14.x'

- name: Build Client App
working-directory: ./src/KafkaFlow.Admin.Dashboard/ClientApp
run: |
npm install
npm run lint
npm run build:prod
- name: Build Framework
run: dotnet build ./src/KafkaFlow.sln -c Release

- name: UnitTest
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ jobs:
with:
dotnet-version: 3.1.403

- name: Setup Node 14.x
uses: actions/setup-node@v1
with:
node-version: '14.x'

- name: Build Client App
working-directory: ./src/KafkaFlow.Admin.Dashboard/ClientApp
run: |
npm install
npm run lint
npm run build:prod
- name: Pack
run: dotnet pack ./src/KafkaFlow.sln -c Release /p:Version=${{ github.event.release.tag_name }} -o ./drop

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ project.lock.json
project.fragment.lock.json
artifacts/

# Node folders
node_modules/

# StyleCop
StyleCopReport.xml

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\KafkaFlow.Admin.Dashboard\KafkaFlow.Admin.Dashboard.csproj" />
<ProjectReference Include="..\..\src\KafkaFlow.Admin.WebApi\KafkaFlow.Admin.WebApi.csproj" />
<ProjectReference Include="..\..\src\KafkaFlow.Admin\KafkaFlow.Admin.csproj" />
<ProjectReference Include="..\..\src\KafkaFlow.LogHandler.Console\KafkaFlow.LogHandler.Console.csproj" />
<ProjectReference Include="..\..\src\KafkaFlow.Microsoft.DependencyInjection\KafkaFlow.Microsoft.DependencyInjection.csproj" />
<ProjectReference Include="..\..\src\KafkaFlow\KafkaFlow.csproj" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions samples/KafkaFlow.Sample.Dashboard/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace KafkaFlow.Sample.Dashboard
{
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
}
27 changes: 27 additions & 0 deletions samples/KafkaFlow.Sample.Dashboard/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:63128",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"KafkaFlow.Sample.Dashboard": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
50 changes: 50 additions & 0 deletions samples/KafkaFlow.Sample.Dashboard/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace KafkaFlow.Sample.Dashboard
{
using KafkaFlow.Admin.Dashboard;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddKafka(
kafka => kafka
.UseConsoleLog()
.AddCluster(
cluster => cluster
.WithBrokers(new[] { "localhost:9092" })
.EnableAdminMessages("kafka-flow.admin", "kafka-flow.admin.group.id")
.EnableTelemetry("kafka-flow.admin", "kafka-flow.telemetry.group.id")
.AddConsumer(
consumer => consumer
.Topics("topic-dashboard")
.WithGroupId("groupid-dashboard")
.WithName("consumer-dashboard")
.WithBufferSize(100)
.WithWorkersCount(20)
.WithAutoOffsetReset(AutoOffsetReset.Latest)
))
);

services
.AddControllers();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime lifetime)
{
app
.UseRouting()
.UseEndpoints(endpoints => { endpoints.MapControllers(); })
.UseKafkaFlowDashboard();

var kafkaBus = app.ApplicationServices.CreateKafkaBus();

lifetime.ApplicationStarted.Register(() => kafkaBus.StartAsync(lifetime.ApplicationStopped));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
10 changes: 10 additions & 0 deletions samples/KafkaFlow.Sample.Dashboard/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
6 changes: 3 additions & 3 deletions samples/KafkaFlow.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using KafkaFlow.Admin;
using Confluent.Kafka;
using global::Microsoft.Extensions.DependencyInjection;
using KafkaFlow.Admin;
using KafkaFlow.Admin.Messages;
using KafkaFlow.Consumers;
using KafkaFlow.Producers;
Expand Down Expand Up @@ -143,10 +143,10 @@ await adminProducer.ProduceAsync(
if (int.TryParse(workersInput, out var workers))
{
await adminProducer.ProduceAsync(
new ChangeConsumerWorkerCount
new ChangeConsumerWorkersCount
{
ConsumerName = consumerName,
WorkerCount = workers
WorkersCount = workers
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public interface IClusterConfigurationBuilder
/// <returns></returns>
IClusterConfigurationBuilder WithBrokers(IEnumerable<string> brokers);

/// <summary>
/// Sets a unique name for the cluster
/// </summary>
/// <param name="name">A unique name</param>
/// <returns></returns>
IClusterConfigurationBuilder WithName(string name);

/// <summary>
/// Configures cluster security
/// </summary>
Expand Down Expand Up @@ -49,5 +56,19 @@ public interface IClusterConfigurationBuilder
/// <param name="consumer">A handler to configure the consumer</param>
/// <returns></returns>
IClusterConfigurationBuilder AddConsumer(Action<IConsumerConfigurationBuilder> consumer);

/// <summary>
/// Adds a handler to be executed when KafkaFlow cluster is stopping
/// </summary>
/// <param name="handler">A handler to KafkaFlow cluster stopping event</param>
/// <returns></returns>
IClusterConfigurationBuilder OnStopping(Action<IDependencyResolver> handler);

/// <summary>
/// Adds a handler to be executed after KafkaFlow cluster started
/// </summary>
/// <param name="handler">A handler to KafkaFlow cluster start event</param>
/// <returns></returns>
IClusterConfigurationBuilder OnStarted(Action<IDependencyResolver> handler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public interface IConsumerConfigurationBuilder
/// <returns></returns>
IConsumerConfigurationBuilder WithName(string name);

/// <summary>
/// Sets the consumer as readonly, that means this consumer can not be managed and it will not send telemetry data
/// </summary>
/// <returns></returns>
IConsumerConfigurationBuilder DisableManagement();

/// <summary>
/// Sets the group id used by the consumer
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/KafkaFlow.Abstractions/IDateTimeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace KafkaFlow
{
using System;

/// <summary>
/// Provides access to DateTime static members
/// </summary>
public interface IDateTimeProvider
{
/// <inheritdoc cref="DateTime.Now"/>
DateTime Now { get; }

/// <inheritdoc cref="DateTime.MinValue"/>
DateTime MinValue { get; }
}
}
43 changes: 43 additions & 0 deletions src/KafkaFlow.Admin.Dashboard/ApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace KafkaFlow.Admin.Dashboard
{
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.FileProviders;

/// <summary>
/// Extension methods over IApplicationBuilder
/// </summary>
public static class ApplicationBuilderExtensions
{
/// <summary>
/// Enable the KafkaFlow dashboard
/// </summary>
/// <param name="app">Instance of <see cref="IApplicationBuilder"/></param>
/// <returns></returns>
public static IApplicationBuilder UseKafkaFlowDashboard(this IApplicationBuilder app)
{
app.Map(
"/kafka-flow",
builder =>
{
var provider = new ManifestEmbeddedFileProvider(
Assembly.GetAssembly(typeof(ApplicationBuilderExtensions)),
"ClientApp/dist");

builder.UseStaticFiles(new StaticFileOptions { FileProvider = provider });

builder.Run(
async context =>
{
if (context.Request.Path == "/" || context.Request.Path == string.Empty)
{
await context.Response.SendFileAsync(provider.GetFileInfo("index.html"));
}
});
});

return app;
}
}
}
17 changes: 17 additions & 0 deletions src/KafkaFlow.Admin.Dashboard/ClientApp/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries

# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support

# You can see what browsers were selected by your queries by running:
# npx browserslist

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.
16 changes: 16 additions & 0 deletions src/KafkaFlow.Admin.Dashboard/ClientApp/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = single

[*.md]
max_line_length = off
trim_trailing_whitespace = false
46 changes: 46 additions & 0 deletions src/KafkaFlow.Admin.Dashboard/ClientApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc
# Only exists if Bazel was run
/bazel-out

# dependencies
/node_modules

# profiling files
chrome-profiler-events*.json
speed-measure-plugin*.json

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings

# System Files
.DS_Store
Thumbs.db
Loading

0 comments on commit 8f4edf8

Please sign in to comment.