Skip to content

Commit

Permalink
[Exporter.Geneva] Add data validation for MetricExportIntervalMillise…
Browse files Browse the repository at this point in the history
…conds (#527)
  • Loading branch information
Yun-Ting authored Jul 28, 2022
1 parent a55cbad commit 551c960
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/OpenTelemetry.Exporter.Geneva/GenevaMetricExporterOptions.cs
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);
}
}
}

0 comments on commit 551c960

Please sign in to comment.