Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inital commit #1

Merged
merged 7 commits into from
Sep 18, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Pack
run: dotnet pack src/MiniProfiler.Elasticsearch/MiniProfiler.Elasticsearch.csproj --configuration Release --include-symbols --no-build
run: dotnet pack src/MiniProfiler.OpenSearch/MiniProfiler.OpenSearch.csproj --configuration Release --include-symbols --no-build
- name: Test
run: dotnet test --configuration Release --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
- name: Coverage
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)
The MIT License (MIT)

Copyright (c) 2022 Raman Paulau
Copyright (c) 2022 Paweł Madurski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31019.35
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniProfiler.Elasticsearch", "src\MiniProfiler.Elasticsearch\MiniProfiler.Elasticsearch.csproj", "{618356CB-5D70-48F3-8B1B-6DA56120E3AC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniProfiler.OpenSearch", "src\MiniProfiler.OpenSearch\MiniProfiler.OpenSearch.csproj", "{618356CB-5D70-48F3-8B1B-6DA56120E3AC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{8991B302-DBA8-4CF8-88D2-5B276C9B37CB}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -23,11 +23,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{16FF3561-A01
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{F57D62CB-485F-4E7A-9A23-8165941D5F41}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Elasticsearch.Core", "samples\Sample.Elasticsearch.Core\Sample.Elasticsearch.Core.csproj", "{275500BB-7676-4B66-93E3-422EF42A4678}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.OpenSearch.Core", "samples\Sample.Opensearch.Core\Sample.OpenSearch.Core.csproj", "{275500BB-7676-4B66-93E3-422EF42A4678}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{C0A0C99B-744D-4C56-A53E-E22C51137ADF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniProfiler.Elasticsearch.Tests", "tests\MiniProfiler.Elasticsearch.Tests\MiniProfiler.Elasticsearch.Tests.csproj", "{2CD0A79C-D950-44AE-BBEA-ACCD50BEF00E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniProfiler.OpenSearch.Tests", "tests\MiniProfiler.OpenSearch.Tests\MiniProfiler.OpenSearch.Tests.csproj", "{2CD0A79C-D950-44AE-BBEA-ACCD50BEF00E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{0A8BCF98-DC77-4CE9-B60B-3760D80E2955}"
EndProject
Expand Down
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
# MiniProfiler.Elasticsearch
Put your [Elasticsearch.Net and NEST](https://github.com/elastic/elasticsearch-net) requests timings directly into [MiniProfiler](https://github.com/MiniProfiler/dotnet).
# MiniProfiler.OpenSearch

[![Build status](https://ci.appveyor.com/api/projects/status/m15gemuqkcs1rbv4/branch/main?svg=true)](https://ci.appveyor.com/project/romansp/miniprofiler-elasticsearch/branch/main) [![Nuget feed](https://img.shields.io/nuget/vpre/MiniProfiler.Elasticsearch.svg)](https://www.nuget.org/packages/MiniProfiler.Elasticsearch)
*** This project has been forked from https://github.com/romansp/MiniProfiler.Elasticsearch and compiled against OpenSearch ***

![profiler-popup](https://user-images.githubusercontent.com/3474842/30780873-de83efd8-a11d-11e7-8735-49dea4a1d4f1.png)
![profiler-queries](https://user-images.githubusercontent.com/3474842/30780952-edf8adea-a11e-11e7-8d64-c65331f389bf.png)
Put your [OpenSearch.Net and OpencSearch.Client](https://github.com/opensearch-project/opensearch-net) requests timings directly into [MiniProfiler](https://github.com/MiniProfiler/dotnet).

[![Build status](https://ci.appveyor.com/api/projects/status/e9axfh54cvn3qqti/branch/main?svg=true)](https://ci.appveyor.com/project/pawel-madurski/miniprofiler-opensearch/branch/main)
![Nuget](https://img.shields.io/nuget/v/DexxLab.MiniProfiler.OpenSearch)

![image](https://github.com/pawel-madurski/MiniProfiler.OpenSearch/assets/11866857/74293aab-6ad3-4ee1-8014-908d831b9646)

## Usage
You have two options on how to start profiling your Elastic requests.
You have two options on how to start profiling your OpenSearch requests.

### Option 1. Register in services collection
In your `Startup.cs`, call `AddElastic()`:
In your `Startup.cs`, call `AddOpenSearch()`:

```c#
public void ConfigureServices(IServiceCollection services)
{
services.AddMiniProfiler(options => {
options.ExcludeElasticAssemblies();
options.ExcludeOpenSearchAssemblies();
})
.AddElastic();
.AddOpenSearch();
}
```

### Option 2. Create profiled client manually
Update usages of `ElasticClient` or `ElasticLowLevelClient` with their respected profiled version `ProfiledElasticClient` or `ProfiledElasticLowLevelClient`.
Update usages of `OpenSearchClient` or `OpenSearchLowLevelClient` with their respected profiled version `ProfiledOpenSearchClient` or `ProfiledOpenSearchLowLevelClient`.

```c#
services.AddSingleton<IElasticClient>(x =>
services.AddSingleton<IOpenSearchClient>(x =>
{
var node = new Uri("http://localhost:9200");
var connectionSettings = new ConnectionSettings(node).DefaultIndex("elasticsearch-sample");
return new ProfiledElasticClient(connectionSettings);
var connectionSettings = new ConnectionSettings(node).DefaultIndex("opensearch-sample");
return new ProfiledOpenSearchClient(connectionSettings);
});
```

## Sample
See [Sample.Elasticsearch.Core](https://github.com/romansp/MiniProfiler.Elasticsearch/tree/main/samples/Sample.Elasticsearch.Core) for working example.
See [Sample.OpenSearch.Core](https://github.com/pawel-madurski/MiniProfiler.OpenSearch/tree/main/samples/Sample.OpenSearch.Core) for working example.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nuget:
before_build:
- cmd: nuget restore
build:
project: MiniProfiler.Elasticsearch.sln
project: MiniProfiler.OpenSearch.sln
verbosity: minimal
publish_nuget: true
publish_nuget_symbols: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Microsoft.AspNetCore.Mvc;
using Nest;
using OpenSearch.Client;
using StackExchange.Profiling;

namespace Sample.Elasticsearch.Core.Controllers;
namespace Sample.OpenSearch.Core.Controllers;

public record Person(string Id, string FirstName, string LastName);

public class HomeController : Controller {
private readonly IElasticClient _client;
private readonly IOpenSearchClient _client;

public HomeController(IElasticClient client) {
public HomeController(IOpenSearchClient client) {
_client = client;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Nest;
using OpenSearch.Client;
using StackExchange.Profiling;

var builder = WebApplication.CreateBuilder(args);

var services = builder.Services;
services.AddControllersWithViews();
services.AddMiniProfiler(options => options.ExcludeElasticAssemblies()).AddElastic();
services.AddSingleton<IElasticClient>(_ => {
services.AddMiniProfiler(options => options.ExcludeOpenSearchAssemblies()).AddOpenSearch();
services.AddSingleton<IOpenSearchClient>(_ => {
var node = new Uri("http://localhost:9200");
var connectionSettings = new ConnectionSettings(node).DefaultIndex("elasticsearch-sample");
return new ElasticClient(connectionSettings);
var connectionSettings = new ConnectionSettings(node).DefaultIndex("opensearch-sample");
return new OpenSearchClient(connectionSettings);
});

services.Configure<RouteOptions>(options => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
},
"profiles": {
"Sample.Elasticsearch.Core._6": {
"Sample.OpenSearch.Core._6": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Sample.Elasticsearch.Core</RootNamespace>
<RootNamespace>Sample.Opensearch.Core</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.2.22" />
<PackageReference Include="NEST" Version="7.12.1" />
<PackageReference Include="OpenSearch.Client" Version="1.5.0" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\..\src\MiniProfiler.Elasticsearch\MiniProfiler.Elasticsearch.csproj" />
<ProjectReference Include="..\..\src\MiniProfiler.OpenSearch\MiniProfiler.OpenSearch.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - Sample.Elasticsearch.Core</title>
<title>@ViewData["Title"] - Sample.OpenSearch.Core</title>

<environment include="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
Expand All @@ -21,7 +21,7 @@
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Sample.Elasticsearch.Core</a>
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Sample.OpenSearch.Core</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@using Sample.Elasticsearch.Core
@using Sample.OpenSearch.Core
@using StackExchange.Profiling

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Expand Down
10 changes: 5 additions & 5 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project>
<PropertyGroup>
<VersionPrefix>7.1.0</VersionPrefix>
<VersionPrefix>1.0.0</VersionPrefix>

<Description>Elasticsearch.Net and NEST client for logging to MiniProfiler.</Description>
<Description>OpenSearch.Net and OpenSearch.Client for logging to MiniProfiler.</Description>
<OutputType>Library</OutputType>
<OutputPath>bin\$(Configuration)\</OutputPath>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>$(AssemblyName)</PackageId>
<PackageTags>MiniProfiler;Elastic;Elasticsearch;ASP.NET;Core;Profiler;Performance</PackageTags>
<PackageTags>MiniProfiler;OpenSearch;ASP.NET;Core;Profiler;Performance</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>See https://github.com/romansp/MiniProfiler.Elasticsearch/releases for more info</PackageReleaseNotes>
<PackageReleaseNotes>See https://github.com/pawel-madurski/MiniProfiler.OpenSearch/releases for more info</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>

<Authors>Raman Paulau</Authors>
<Authors>Paweł Madurski</Authors>

<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
32 changes: 0 additions & 32 deletions src/MiniProfiler.Elasticsearch/Internal/ProfilerUtils.cs

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions src/MiniProfiler.Elasticsearch/ProfiledElasticClient.cs

This file was deleted.

18 changes: 0 additions & 18 deletions src/MiniProfiler.Elasticsearch/ProfiledElasticLowLevelClient.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Linq;
using Elasticsearch.Net;
using OpenSearch.Client;
using OpenSearch.Net;

namespace StackExchange.Profiling.Elasticsearch.Internal;
namespace StackExchange.Profiling.OpenSearch.Internal;

/// <summary>
/// <see cref="IApiCallDetails"/> handler class.
/// </summary>
internal static class MiniProfilerElasticsearch {
internal static class MiniProfilerOpenSearch {
/// <summary>
/// Handles <see cref="IApiCallDetails"/> and pushes <see cref="CustomTiming"/> to current <see cref="MiniProfiler"/> session.
/// </summary>
Expand All @@ -20,7 +21,7 @@ internal static void HandleResponse(IApiCallDetails? apiCallDetails) {
return;
}

profiler.Head.AddCustomTiming("elasticsearch", new CustomTiming(profiler, apiCallDetails.DebugInformation) {
profiler.Head.AddCustomTiming("opensearch", new CustomTiming(profiler, apiCallDetails.DebugInformation) {
DurationMilliseconds = (decimal?)apiCallDetails.AuditTrail?.Sum(c => (c.Ended - c.Started).TotalMilliseconds),
ExecuteType = apiCallDetails.HttpMethod.ToString(),
Errored = !apiCallDetails.Success
Expand Down
31 changes: 31 additions & 0 deletions src/MiniProfiler.OpenSearch/Internal/ProfilerUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using StackExchange.Profiling.Internal;

namespace StackExchange.Profiling.OpenSearch.Internal;

internal static class ProfilerUtils {
/// <summary>
/// OpenSearch-related assemblies to exclude from profiling
/// </summary>
internal static HashSet<string> ExcludedAssemblies { get; } = new HashSet<string> {
"OpenSearch.Client",
"OpenSearch.Net.Diagnostics",
typeof(MiniProfilerOpenSearch).Namespace,
typeof(MiniProfilerOpenSearch).Assembly.GetName().Name,
};

/// <summary>
/// Excludes OpenSearch assemblies from passed in <paramref name="options"/>, so they won't be included into <see cref="MiniProfiler"/> timings' call-stack.
/// </summary>
/// <param name="options"></param>
internal static void ExcludeOpenSearchAssemblies(this MiniProfilerBaseOptions options) {
foreach (var excludedAssembly in ExcludedAssemblies) {
options.ExcludeAssembly(excludedAssembly);
}
}

/// <summary>
/// Excludes OpenSearch assemblies from <see cref="MiniProfiler.DefaultOptions"/>, so they won't be included into <see cref="MiniProfiler"/> timings' call-stack.
/// </summary>
internal static void ExcludeOpenSearchAssemblies() => MiniProfiler.DefaultOptions.ExcludeOpenSearchAssemblies();
}
Loading
Loading