Skip to content

Commit

Permalink
[Extensions.PersistentStorage] Fix analysis warnings (#958)
Browse files Browse the repository at this point in the history
Fix/suppress code analysis warnings in OpenTelemetry.Contrib.Extensions.PersistentStorage.
Contributes to #950.

Co-authored-by: Cijo Thomas <[email protected]>
  • Loading branch information
martincostello and cijothomas authored Feb 6, 2023
1 parent a515f71 commit 8ee613c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ OpenTelemetry.Extensions.PersistentStorage.FileBlob.FileBlob(string fullPath) ->
OpenTelemetry.Extensions.PersistentStorage.FileBlob.FullPath.get -> string
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose() -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.FileBlobProvider(string path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryDelete() -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryLease(int leasePeriodMilliseconds) -> bool
Expand All @@ -12,4 +11,5 @@ override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryWrite(byte[] b
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob>
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
virtual OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ OpenTelemetry.Extensions.PersistentStorage.FileBlob.FileBlob(string fullPath) ->
OpenTelemetry.Extensions.PersistentStorage.FileBlob.FullPath.get -> string
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose() -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.FileBlobProvider(string path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryDelete() -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryLease(int leasePeriodMilliseconds) -> bool
Expand All @@ -12,4 +11,5 @@ override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryWrite(byte[] b
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob>
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
virtual OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ OpenTelemetry.Extensions.PersistentStorage.FileBlob.FileBlob(string fullPath) ->
OpenTelemetry.Extensions.PersistentStorage.FileBlob.FullPath.get -> string
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose() -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.FileBlobProvider(string path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryDelete() -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryLease(int leasePeriodMilliseconds) -> bool
Expand All @@ -12,4 +11,5 @@ override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryWrite(byte[] b
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob>
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
virtual OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Extensions.PersistentStorage/FileBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using OpenTelemetry.Extensions.PersistentStorage.Abstractions;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Extensions.PersistentStorage;

Expand Down Expand Up @@ -57,6 +58,8 @@ protected override bool OnTryRead([NotNullWhen(true)] out byte[] buffer)

protected override bool OnTryWrite(byte[] buffer, int leasePeriodMilliseconds = 0)
{
Guard.ThrowIfNull(buffer);

string path = this.FullPath + ".tmp";

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void Dispose()
GC.SuppressFinalize(this);
}

public void Dispose(bool disposing)
protected virtual void Dispose(bool disposing)
{
if (!this.disposedValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,14 @@ internal static DateTime GetDateTimeFromLeaseName(string filePath)

internal static string GetSHA256Hash(string input)
{
var hashString = new StringBuilder();

byte[] inputBits = Encoding.Unicode.GetBytes(input);

#if NET6_0_OR_GREATER
#pragma warning disable CA1308 // Normalize strings to uppercase
return Convert.ToHexString(SHA256.HashData(inputBits)).ToLowerInvariant();
#pragma warning restore CA1308 // Normalize strings to uppercase
#else
var hashString = new StringBuilder();
using (var sha256 = SHA256.Create())
{
byte[] hashBits = sha256.ComputeHash(inputBits);
Expand All @@ -217,6 +222,7 @@ internal static string GetSHA256Hash(string input)
}

return hashString.ToString();
#endif
}

private static long CalculateFolderSize(string path)
Expand Down

0 comments on commit 8ee613c

Please sign in to comment.