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

[Exporter.Geneva] Add data validation for MetricExportIntervalMilliseconds #527

Merged
merged 18 commits into from
Jul 28, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace OpenTelemetry.Exporter.Geneva;
public class GenevaMetricExporterOptions
{
private IReadOnlyDictionary<string, object> _prepopulatedMetricDimensions;
private int _metricExporterIntervalMilliseconds = 20000;

/// <summary>
/// Gets or sets the ConnectionString which contains semicolon separated list of key-value pairs.
Expand All @@ -34,7 +35,20 @@ public class GenevaMetricExporterOptions
/// <summary>
/// Gets or sets the metric export interval in milliseconds. The default value is 20000.
/// </summary>
public int MetricExportIntervalMilliseconds { get; set; } = 20000;
public int MetricExportIntervalMilliseconds
{
get
{
return this._metricExporterIntervalMilliseconds;
}

set
{
Guard.ThrowIfOutOfRange(value, min: 1000);

this._metricExporterIntervalMilliseconds = value;
}
}

/// <summary>
/// Gets or sets the pre-populated dimensions for all the metrics exported by the exporter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,27 @@ [new string('a', GenevaMetricExporter.MaxDimensionNameSize + 1)] = "DimensionVal
expectedErrorMessage = $"Value provided for the dimension: DimensionKey exceeds the maximum allowed limit of {GenevaMetricExporter.MaxDimensionValueSize} characters for dimension value.";
Assert.Equal(expectedErrorMessage, invalidDimensionValueException.Message);
}

[Fact]
public void MetricExportIntervalValidationTest()
{
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
var exporterOptions = new GenevaMetricExporterOptions
{
MetricExportIntervalMilliseconds = 999,
};
});

var exception = Record.Exception(() =>
{
var exporterOptions = new GenevaMetricExporterOptions
{
MetricExportIntervalMilliseconds = 1000,
};
});

Assert.Null(exception);
}
}
}