Skip to content

Commit

Permalink
Add small readme, make sure Configuration is generic in pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Oct 21, 2020
1 parent ede0d9e commit 9c44ab2
Show file tree
Hide file tree
Showing 31 changed files with 383 additions and 137 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Always be deploying

on:
pull_request:
paths-ignore:
- 'README.md'
- '.editorconfig'
push:
paths-ignore:
- 'README.md'
- '.editorconfig'
branches:
- master
tags:
- "*.*.*"

jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- run: |
git fetch --prune --unshallow --tags
echo exit code $?
git tag --list
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.201'
source-url: https://nuget.pkg.github.com/elastic/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

- run: ./build.sh build -s true
name: Build
- run: ./build.sh generatepackages -s true
name: Generate local nuget packages
- run: ./build.sh validatepackages -s true
name: "validate *.npkg files that were created"
- run: ./build.sh generateapichanges -s true
name: "Inspect public API changes"

- name: publish canary packages github package repository
if: github.event_name == 'push' && startswith(github.ref, 'refs/heads')
shell: bash
run: |
until dotnet nuget push 'build/output/*.nupkg' -k ${{secrets.GITHUB_TOKEN}} --skip-duplicate --no-symbols true; do echo "Retrying"; sleep 1; done;
# Github packages requires authentication, this is likely going away in the future so for now we publish to feedz.io
- run: dotnet nuget push 'build/output/*.nupkg' -k ${{secrets.FEEDZ_IO_API_KEY}} -s https://f.feedz.io/elastic/all/nuget/index.json --skip-duplicate --no-symbols true
name: publish canary packages to feedz.io
if: github.event_name == 'push' && startswith(github.ref, 'refs/heads')

- run: ./build.sh generatereleasenotes -s true
name: Generate release notes for tag
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags')
- run: ./build.sh createreleaseongithub -s true --token ${{secrets.GITHUB_TOKEN}}
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags')
name: Create or update release for tag on github

- run: dotnet nuget push 'build/output/*.nupkg' -k ${{secrets.NUGET_ORG_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols true
name: release to nuget.org
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags')
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# elastic-transport-net

Transport classes and utilities shared among .NET Elastic client libraries

This library was lifted from [elasticsearch-net](https://github.com/elastic/elasticsearch-net) and then transformed to be used across all Elastic services rather than only Elasticsearch.


Provides the clients connectivity components, exposes a (potentially) cluster aware request pipeline that can be resilient to nodes dropping in & out of rotation.
This package is heavily optimized for the Elastic (elastic.co) product suite and Elastic Cloud (cloud.elastic.co) SAAS offering.




2 changes: 1 addition & 1 deletion build/scripts/Paths.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Paths
open System
open System.IO

let ToolName = "ecs-dotnet"
let ToolName = "elastic-transport-net"
let Repository = sprintf "elastic/%s" ToolName
let MainTFM = "netstandard2.0"
let SignKey = "069ca2728db333c1"
Expand Down
8 changes: 3 additions & 5 deletions elastic-transport-net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "scripts", "build\scripts\scripts.fsproj", "{4779DD6F-AE49-4A80-9F67-D9F2DB05E557}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7610B796-BB3E-4CB2-8296-79BBFF6D23FC}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
EndProjectSection
ProjectSection(SolutionItems) = preProject
src\Directory.Build.props = src\Directory.Build.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{3582B07D-C2B0-49CC-B676-EAF806EB010E}"
EndProject
Expand All @@ -22,9 +22,7 @@ ProjectSection(SolutionItems) = preProject
README.md = README.md
build.bat = build.bat
build.sh = build.sh
nuget.config = nuget.config
Directory.Build.props = Directory.Build.props
.ci\Jenkinsfile = .ci\Jenkinsfile
.github\workflows\ci.yml = .github\workflows\ci.yml
EndProjectSection
EndProject
Expand Down
6 changes: 0 additions & 6 deletions nuget.config

This file was deleted.

37 changes: 37 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))"/>
<PropertyGroup>
<Authors>Elastic and contributors</Authors>
<Copyright>Elasticsearch BV</Copyright>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/elastic/elastic-transport-net</RepositoryUrl>
<PackageProjectUrl>https://github.com/elastic/elastic-transport-net</PackageProjectUrl>
<PackageReleaseNotes>https://github.com/elastic/elastic-transport-net/releases</PackageReleaseNotes>

<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(SolutionRoot)\build\keys\keypair.snk</AssemblyOriginatorKeyFile>

<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PackageIcon>nuget-icon.png</PackageIcon>

</PropertyGroup>

<ItemGroup>
<Content Include="../../nuget-icon.png" CopyToOutputDirectory="PreserveNewest">
<Link>nuget-icon.png</Link>
<Pack>True</Pack>
<PackagePath>nuget-icon.png</PackagePath>
</Content>
<None Include="../../license.txt" CopyToOutputDirectory="PreserveNewest">
<Pack>True</Pack>
<PackagePath>license.txt</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="ConfigureAwaitChecker.Analyzer" Version="4.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ namespace Elastic.Transport.VirtualizedCluster.Components
/// <summary>
/// An implementation that exposes all the components so that <see cref="VirtualCluster"/> can reference them directly.
/// </summary>
public class ExposingPipelineFactory : IRequestPipelineFactory
public class ExposingPipelineFactory<TConfiguration> : IRequestPipelineFactory<TConfiguration> where TConfiguration : class, ITransportConfigurationValues
{
public ExposingPipelineFactory(ITransportConfigurationValues connectionSettings, IDateTimeProvider dateTimeProvider)
public ExposingPipelineFactory(TConfiguration connectionSettings, IDateTimeProvider dateTimeProvider)
{
DateTimeProvider = dateTimeProvider;
MemoryStreamFactory = TransportConfiguration.DefaultMemoryStreamFactory;

Settings = connectionSettings;
Pipeline = Create(Settings, DateTimeProvider, MemoryStreamFactory, new RequestParameters(HttpMethod.GET, supportsBody: false));
Transport = new Transport<ITransportConfigurationValues>(Settings, this, DateTimeProvider, MemoryStreamFactory);
Transport = new Transport<TConfiguration>(Settings, this, DateTimeProvider, MemoryStreamFactory);
}

// ReSharper disable once MemberCanBePrivate.Global
public IRequestPipeline Pipeline { get; }

private IDateTimeProvider DateTimeProvider { get; }
private IMemoryStreamFactory MemoryStreamFactory { get; }
private ITransportConfigurationValues Settings { get; }
private TConfiguration Settings { get; }
public ITransport<ITransportConfigurationValues> Transport { get; }


public IRequestPipeline Create(ITransportConfigurationValues configurationValues, IDateTimeProvider dateTimeProvider,
public IRequestPipeline Create(TConfiguration configurationValues, IDateTimeProvider dateTimeProvider,
IMemoryStreamFactory memoryStreamFactory, IRequestParameters requestParameters
) =>
new RequestPipeline(Settings, DateTimeProvider, MemoryStreamFactory, requestParameters ?? new RequestParameters(HttpMethod.GET, supportsBody: false));
new RequestPipeline<TConfiguration>(Settings, DateTimeProvider, MemoryStreamFactory, requestParameters ?? new RequestParameters(HttpMethod.GET, supportsBody: false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Elastic.Transport.Products.Elasticsearch;
using Elastic.Transport.VirtualizedCluster.Products;
using Elastic.Transport.VirtualizedCluster.Products.Elasticsearch;
using Elastic.Transport.VirtualizedCluster.Providers;
Expand Down Expand Up @@ -105,12 +106,9 @@ private void UpdateCluster(VirtualCluster cluster)
}
}

private static bool IsSniffRequest(RequestData requestData) =>
requestData.PathAndQuery.StartsWith(RequestPipeline.SniffPath, StringComparison.Ordinal);
private bool IsSniffRequest(RequestData requestData) => _productRegistration.IsSniffRequest(requestData);

private static bool IsPingRequest(RequestData requestData) =>
requestData.Method == HttpMethod.HEAD &&
(requestData.PathAndQuery == string.Empty || requestData.PathAndQuery.StartsWith("?"));
private bool IsPingRequest(RequestData requestData) => _productRegistration.IsPingRequest(requestData);

/// <inheritdoc cref="IConnection.RequestAsync{TResponse}"/>>
public override Task<TResponse> RequestAsync<TResponse>(RequestData requestData, CancellationToken cancellationToken) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Elastic.Transport.VirtualizedCluster.Components
{
public class VirtualizedCluster
{
private readonly ExposingPipelineFactory _exposingRequestPipeline;
private readonly ExposingPipelineFactory<TransportConfiguration> _exposingRequestPipeline;
private readonly TestableDateTimeProvider _dateTimeProvider;
private readonly TransportConfiguration _settings;

Expand All @@ -25,7 +25,7 @@ internal VirtualizedCluster(TestableDateTimeProvider dateTimeProvider, Transport
{
_dateTimeProvider = dateTimeProvider;
_settings = settings;
_exposingRequestPipeline = new ExposingPipelineFactory(settings, _dateTimeProvider);
_exposingRequestPipeline = new ExposingPipelineFactory<TransportConfiguration>(settings, _dateTimeProvider);

_syncCall = (t, r) => t.Request<VirtualResponse>(
HttpMethod.GET, "/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System.Collections.Generic;
using Elastic.Transport.Products;
using Elastic.Transport.Products.Elasticsearch;
Expand All @@ -20,5 +21,12 @@ public class ElasticsearchMockProductRegistration : IMockProductRegistration
/// <inheritdoc cref="IMockProductRegistration.CreateSniffResponseBytes"/>>
public byte[] CreateSniffResponseBytes(IReadOnlyList<Node> nodes, string stackVersion, string publishAddressOverride, bool returnFullyQualifiedDomainNames) =>
ElasticsearchSniffResponseFactory.Create(nodes, stackVersion, publishAddressOverride, returnFullyQualifiedDomainNames);

public bool IsSniffRequest(RequestData requestData) =>
requestData.PathAndQuery.StartsWith(ElasticsearchProductRegistration.SniffPath, StringComparison.Ordinal);

public bool IsPingRequest(RequestData requestData) =>
requestData.Method == HttpMethod.HEAD &&
(requestData.PathAndQuery == string.Empty || requestData.PathAndQuery.StartsWith("?"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@ public interface IMockProductRegistration
/// <param name="publishAddressOverride">Return this hostname instead of some IP</param>
/// <param name="returnFullyQualifiedDomainNames">If the sniff can return internal + external information return both</param>
byte[] CreateSniffResponseBytes(IReadOnlyList<Node> nodes, string stackVersion, string publishAddressOverride, bool returnFullyQualifiedDomainNames);

/// <summary>
/// see <see cref="VirtualClusterConnection.Request{TResponse}"/> uses this to determine if the current request is a sniff request and should follow
/// the sniffing rules
/// </summary>
bool IsSniffRequest(RequestData requestData);

bool IsPingRequest(RequestData requestData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Elastic.Transport
{
/// <summary>
/// A pipeline exception is throw when ever a known failing exit point is reached in <see cref="RequestPipeline"/>
/// A pipeline exception is throw when ever a known failing exit point is reached in <see cref="RequestPipeline{TConfiguration}"/>
/// <para>See <see cref="PipelineFailure"/> for known exits points</para>
/// </summary>
public class PipelineException : Exception
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Transport/Components/Pipeline/PipelineFailure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Elastic.Transport
{
/// <summary>
/// A failure in <see cref="RequestPipeline"/>'s workflow that caused it to end prematurely.
/// A failure in <see cref="RequestPipeline{TConfiguration}"/>'s workflow that caused it to end prematurely.
/// </summary>
public enum PipelineFailure
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public enum PipelineFailure
MaxRetriesReached,

/// <summary>
/// An exception occurred during <see cref="RequestPipeline"/> that could not be handled
/// An exception occurred during <see cref="RequestPipeline{TConfiguration}"/> that could not be handled
/// </summary>
Unexpected,

Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Transport/Components/Pipeline/RequestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ IMemoryStreamFactory memoryStreamFactory
PingTimeout =
local?.PingTimeout
?? global.PingTimeout
?? (global.ConnectionPool.UsingSsl ? TransportConfiguration.DefaultPingTimeoutOnSSL : TransportConfiguration.DefaultPingTimeout);
?? (global.ConnectionPool.UsingSsl ? TransportConfiguration.DefaultPingTimeoutOnSsl : TransportConfiguration.DefaultPingTimeout);

KeepAliveInterval = (int)(global.KeepAliveInterval?.TotalMilliseconds ?? 2000);
KeepAliveTime = (int)(global.KeepAliveTime?.TotalMilliseconds ?? 2000);
Expand Down
Loading

0 comments on commit 9c44ab2

Please sign in to comment.