Skip to content

Commit

Permalink
Merge pull request #984 from IgorAlymov/SITKO-CORE-T-18
Browse files Browse the repository at this point in the history
feat(opensearch): added solution for searching with OpenSearch
  • Loading branch information
pogromistik authored Jul 18, 2024
2 parents 338c2a8 + 83e520d commit 9bcfcf7
Show file tree
Hide file tree
Showing 12 changed files with 555 additions and 2 deletions.
27 changes: 26 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,31 @@ jobs:
- name: Run tests
run: dotnet test --logger GitHubActions tests/Sitko.Core.SonyFlake.Tests/Sitko.Core.SonyFlake.Tests.csproj

opensearch:
runs-on: ubuntu-latest
container: ghcr.io/sitkoru/actions-container
env:
OpenSearchModuleOptions__Url: http://opensearch:9200
OpenSearchModuleOptions__Login: admin
OpenSearchModuleOptions__Password: sikdadasDA123@ituDSSaMydfdssdss
services:
opensearch:
image: opensearchproject/opensearch:latest
ports: [ "9200:9200" ]
env:
discovery.type: single-node
plugins.security.disabled: true
OPENSEARCH_INITIAL_ADMIN_PASSWORD: sikdadasDA123@ituDSSaMydfdssdss
options: >-
--health-cmd="curl http://localhost:9200/_cluster/health"
--health-interval=10s
--health-timeout=5s
--health-retries=10
steps:
- uses: actions/checkout@v4
- name: Run opensearch tests
run: dotnet test --logger GitHubActions tests/Sitko.Core.Search.OpenSearch.Tests/Sitko.Core.Search.OpenSearch.Tests.csproj

storage:
runs-on: ubuntu-latest
container: ghcr.io/sitkoru/actions-container
Expand Down Expand Up @@ -183,7 +208,7 @@ jobs:
release:
name: Release
runs-on: ubuntu-latest
needs: [ build, apps, blazor, grpc, imgproxy, pdf, queue, repository, sonyflake, storage, vault ]
needs: [ build, apps, blazor, grpc, imgproxy, pdf, queue, repository, sonyflake, storage, vault, opensearch ]
if: ${{ github.event_name == 'push' }}
steps:
- name: Checkout
Expand Down
30 changes: 30 additions & 0 deletions Sitko.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sitko.Core.ServiceDiscovery
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sitko.Core.ServiceDiscovery.Server.Consul", "src\Sitko.Core.ServiceDiscovery.Server.Consul\Sitko.Core.ServiceDiscovery.Server.Consul.csproj", "{0E38CE06-301D-44CF-9093-A7119876059C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sitko.Core.Search.OpenSearch", "src\Sitko.Core.Search.OpenSearch\Sitko.Core.Search.OpenSearch.csproj", "{0275F631-EAD9-4BAB-BA5F-1820526B69FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sitko.Core.Search.OpenSearch.Tests", "tests\Sitko.Core.Search.OpenSearch.Tests\Sitko.Core.Search.OpenSearch.Tests.csproj", "{1026C1DE-5614-441E-A7DD-A1A2D4D96872}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1613,6 +1617,30 @@ Global
{0E38CE06-301D-44CF-9093-A7119876059C}.Release|x64.Build.0 = Release|Any CPU
{0E38CE06-301D-44CF-9093-A7119876059C}.Release|x86.ActiveCfg = Release|Any CPU
{0E38CE06-301D-44CF-9093-A7119876059C}.Release|x86.Build.0 = Release|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Debug|x64.ActiveCfg = Debug|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Debug|x64.Build.0 = Debug|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Debug|x86.ActiveCfg = Debug|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Debug|x86.Build.0 = Debug|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Release|Any CPU.Build.0 = Release|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Release|x64.ActiveCfg = Release|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Release|x64.Build.0 = Release|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Release|x86.ActiveCfg = Release|Any CPU
{0275F631-EAD9-4BAB-BA5F-1820526B69FA}.Release|x86.Build.0 = Release|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Debug|x64.ActiveCfg = Debug|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Debug|x64.Build.0 = Debug|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Debug|x86.ActiveCfg = Debug|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Debug|x86.Build.0 = Debug|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Release|Any CPU.Build.0 = Release|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Release|x64.ActiveCfg = Release|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Release|x64.Build.0 = Release|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Release|x86.ActiveCfg = Release|Any CPU
{1026C1DE-5614-441E-A7DD-A1A2D4D96872}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6677865F-C349-4D25-9E19-3DEC43E92DD5} = {109B331E-71B9-483C-8FC1-13B10C92A7F1}
Expand Down Expand Up @@ -1729,5 +1757,7 @@ Global
{991FDA4A-8103-4BC2-934A-6EC039164E15} = {361A42BE-0F1F-47D0-9A70-0702D95BA6F5}
{FFA5D00A-2CB6-4AAA-9345-0D3BCC13D7FA} = {109B331E-71B9-483C-8FC1-13B10C92A7F1}
{0E38CE06-301D-44CF-9093-A7119876059C} = {109B331E-71B9-483C-8FC1-13B10C92A7F1}
{0275F631-EAD9-4BAB-BA5F-1820526B69FA} = {109B331E-71B9-483C-8FC1-13B10C92A7F1}
{1026C1DE-5614-441E-A7DD-A1A2D4D96872} = {10C46F0D-1B13-447E-AD22-F01DDB5A79FD}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<!--OpenSearch libraries-->
<ItemGroup>
<PackageVersion Include="Serilog.Sinks.OpenSearch" Version="1.2.0" />
<PackageVersion Include="OpenSearch.Client" Version="1.7.1" />
</ItemGroup>
<!--Elastic libraries-->
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Sitko.Core.App/BaseApplicationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public interface IModuleOptionsWithValidation
public abstract class BaseModuleOptions
{
public virtual bool Enabled { get; set; } = true;
public virtual bool InitProviders { get; set; } = true;

public virtual void Configure(IApplicationContext applicationContext)
{
Expand Down
35 changes: 35 additions & 0 deletions src/Sitko.Core.Search.OpenSearch/ApplicationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Hosting;
using Sitko.Core.App;

namespace Sitko.Core.Search.OpenSearch;

[PublicAPI]
public static class ApplicationExtensions
{
public static IHostApplicationBuilder AddOpenSearch(this IHostApplicationBuilder hostApplicationBuilder,
Action<IApplicationContext, OpenSearchModuleOptions> configure,
string? optionsKey = null)
{
hostApplicationBuilder.GetSitkoCore().AddOpenSearch(configure, optionsKey);
return hostApplicationBuilder;
}

public static IHostApplicationBuilder AddOpenSearch(this IHostApplicationBuilder hostApplicationBuilder,
Action<OpenSearchModuleOptions>? configure = null,
string? optionsKey = null)
{
hostApplicationBuilder.GetSitkoCore().AddOpenSearch(configure, optionsKey);
return hostApplicationBuilder;
}

public static ISitkoCoreApplicationBuilder AddOpenSearch(this ISitkoCoreApplicationBuilder applicationBuilder,
Action<IApplicationContext, OpenSearchModuleOptions> configure,
string? optionsKey = null) =>
applicationBuilder.AddModule<OpenSearchModule, OpenSearchModuleOptions>(configure, optionsKey);

public static ISitkoCoreApplicationBuilder AddOpenSearch(this ISitkoCoreApplicationBuilder applicationBuilder,
Action<OpenSearchModuleOptions>? configure = null,
string? optionsKey = null) =>
applicationBuilder.AddModule<OpenSearchModule, OpenSearchModuleOptions>(configure, optionsKey);
}
11 changes: 11 additions & 0 deletions src/Sitko.Core.Search.OpenSearch/OpenSearchModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Extensions.DependencyInjection;

namespace Sitko.Core.Search.OpenSearch;

public class OpenSearchModule : SearchModule<OpenSearchModuleOptions>
{
public override string OptionsKey => "Search:OpenSearch";

protected override void ConfigureSearch(IServiceCollection services) =>
services.AddScoped(typeof(ISearcher<>), typeof(OpenSearchSearcher<>));
}
20 changes: 20 additions & 0 deletions src/Sitko.Core.Search.OpenSearch/OpenSearchModuleOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using FluentValidation;

namespace Sitko.Core.Search.OpenSearch;

public class OpenSearchModuleOptions : SearchModuleOptions
{
public string Prefix { get; set; } = "";
public string Url { get; set; } = "http://localhost:9200";
public string Login { get; set; } = "";
public string Password { get; set; } = "";
public bool EnableClientLogging { get; set; }
public bool DisableCertificatesValidation { get; set; }
public string CustomStemmer { get; set; } = "";
}

public class OpenSearchModuleOptionsValidator : AbstractValidator<OpenSearchModuleOptions>
{
public OpenSearchModuleOptionsValidator() =>
RuleFor(o => o.Url).NotEmpty().WithMessage("OpenSearch url is empty");
}
Loading

0 comments on commit 9bcfcf7

Please sign in to comment.