Skip to content

Add infra config loading from IConfiguration #17

@askrinnik

Description

@askrinnik

The current implementation allows the loading of configuration data from a JSON file.
Under the hood, it is loaded and provided as IConfiguration to the NBomberContext.
It would be great to have the ability to load this data from IConfiguration directly. It will allow to pass parameters from environment variables or command line arguments,

Currently, I have developed the following extension method:

internal static class InfluxDbSinkExtensions
{
    internal static NBomberContext WithInfluxDbSink(this NBomberContext context, IConfiguration config)
    {
        // It is expected that the configuration may contain values like: InfluxDBSink:Url, InfluxDBSink:Database
        var influxDbConfig = config.GetSection("InfluxDBSink").Get<InfluxDbSinkConfig>();
        if (influxDbConfig == null)
            return context; // InfluxDb is not configured.

        // The configuration values are present, and we must path that IConfiguration instance to NBomberContext.
        // Since NBomberContext is immutable, we must manually create a new instance. The rest of the properties need to be passed as is.
        var newContext = new NBomberContext(
            context.TestSuite, 
            context.TestName, 
            context.RegisteredScenarios, 
            context.NBomberConfig, 
            FSharpOption<IConfiguration>.Some(config), 
            context.CreateLoggerConfig, 
            context.Reporting,
            context.WorkerPlugins, 
            context.TargetScenarios,
            context.MinimumLogLevel,
            context.EnableStopTestForcibly,
            context.License,
            context.SessionId,
            context.EnableLocalDevCluster,
            context.ClusterId,
            context.AgentsCount,
            context.AgentGroup,
            context.NodeType,
            context.ScenarioCompletionTimeout,
            context.DisplayConsoleMetrics
            );
        return newContext.WithReportingSinks(new InfluxDBSink());
    }
}

Would it be possible to include something similar out of the box?
Thank you in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions