Skip to content

Commit

Permalink
Remove connected concentrators metric #1378
Browse files Browse the repository at this point in the history
  • Loading branch information
hocinehacherouf committed Nov 14, 2022
1 parent 35dc9d2 commit 4ead540
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
<MudItem xs="12" sm="6" md="3">
<DashboardMetricCounter Title="Concentrators" Counter="portalMetric.ConcentratorCount" Icon="@Icons.Material.Filled.WifiTethering" Color="Color.Info" />
</MudItem>
<MudItem xs="12" sm="6" md="3">
<DashboardMetricCounter Title="Connected Concentrators" Counter="portalMetric.ConnectedConcentratorCount" Icon="@Icons.Material.Filled.WifiTethering" Color="Color.Success" />
</MudItem>
</MudGrid>

@code {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class ConcentratorMetricExporterService : IJob
private readonly PortalMetric portalMetric;

private readonly Counter concentratorCounter = Metrics.CreateCounter(MetricName.ConcentratorCount, "Concentrators count");
private readonly Counter connectedConcentratorCounter = Metrics.CreateCounter(MetricName.ConnectedConcentratorCount, "Connected concentrators count");

public ConcentratorMetricExporterService(ILogger<ConcentratorMetricExporterService> logger, PortalMetric portalMetric)
{
Expand All @@ -30,7 +29,6 @@ public Task Execute(IJobExecutionContext context)
this.logger.LogInformation("Start exporting concentrators metrics");

this.concentratorCounter.IncTo(this.portalMetric.ConcentratorCount);
this.connectedConcentratorCounter.IncTo(this.portalMetric.ConnectedConcentratorCount);

this.logger.LogInformation("End exporting concentrators metrics");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public async Task Execute(IJobExecutionContext context)
this.logger.LogInformation("Start loading concentrators metrics");

await LoadConcentratorsCountMetric();
await LoadConnectedConcentratorsCountMetric();

this.logger.LogInformation("End loading concentrators metrics");
}
Expand All @@ -44,17 +43,5 @@ private async Task LoadConcentratorsCountMetric()
this.logger.LogError($"Unable to load concentrators count metric: {e.Detail}", e);
}
}

private async Task LoadConnectedConcentratorsCountMetric()
{
try
{
this.portalMetric.ConnectedConcentratorCount = await this.externalDeviceService.GetConnectedConcentratorsCount();
}
catch (InternalServerErrorException e)
{
this.logger.LogError($"Unable to load connected concentrators count metric: {e.Detail}", e);
}
}
}
}
16 changes: 0 additions & 16 deletions src/AzureIoTHub.Portal.Server/Services/ExternalDeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,22 +585,6 @@ public async Task<int> GetConcentratorsCount()
}
}

public async Task<int> GetConnectedConcentratorsCount()
{
try
{
var count = await this.registryManager
.CreateQuery("SELECT COUNT() as totalNumber FROM devices WHERE devices.capabilities.iotEdge = false AND devices.tags.deviceType = 'LoRa Concentrator' AND connectionState = 'Connected'")
.GetNextAsJsonAsync();

return !JObject.Parse(count.Single()).TryGetValue("totalNumber", out var result) ? 0 : result.Value<int>();
}
catch (RequestFailedException e)
{
throw new InternalServerErrorException("Unable to get connected LoRaWAN concentrators count", e);
}
}

public async Task<EnrollmentCredentials> GetEnrollmentCredentials(string deviceId)
{
var device = await GetDeviceTwin(deviceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ Task<PaginationResult<Twin>> GetAllEdgeDevice(

Task<int> GetConcentratorsCount();

Task<int> GetConnectedConcentratorsCount();

Task<EnrollmentCredentials> GetEnrollmentCredentials(string deviceId);

Task<EnrollmentCredentials> GetEdgeDeviceCredentials(string edgeDeviceId);
Expand Down
2 changes: 0 additions & 2 deletions src/AzureIoTHub.Portal.Shared/Models/v1.0/PortalMetric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ public class PortalMetric
public int FailedDeploymentCount { get; set; }

public int ConcentratorCount { get; set; }

public int ConnectedConcentratorCount { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public void DashboardMetricShouldRenderCorrectly()
EdgeDeviceCount = 3,
ConnectedEdgeDeviceCount = 4,
FailedDeploymentCount = 5,
ConcentratorCount = 6,
ConnectedConcentratorCount = 7
ConcentratorCount = 6
};

_ = this.mockDashboardMetricsClientService.Setup(c => c.GetPortalMetrics())
Expand All @@ -54,9 +53,9 @@ public void DashboardMetricShouldRenderCorrectly()
var cut = RenderComponent<DashboardMetrics>();

// Assert
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(6));

cut.WaitForAssertion(() => cut.Find("#dashboard-metric-counter-title").TextContent.Should().Be("Devices"));
cut.WaitForAssertion(() => cut.Find("#dashboard-metric-counter-value").TextContent.Should().Be(portalMetric.DeviceCount.ToString(CultureInfo.InvariantCulture)));
Expand All @@ -75,18 +74,17 @@ public void OnRefreshDashboardEventDashboardMetricShouldRefreshMetrics()
EdgeDeviceCount = 3,
ConnectedEdgeDeviceCount = 4,
FailedDeploymentCount = 5,
ConcentratorCount = 6,
ConnectedConcentratorCount = 7
ConcentratorCount = 6
};

_ = this.mockDashboardMetricsClientService.Setup(c => c.GetPortalMetrics())
.ReturnsAsync(portalMetric);

var cut = RenderComponent<DashboardMetrics>();

cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(6));

cut.WaitForAssertion(() => cut.Find("#dashboard-metric-counter-title").TextContent.Should().Be("Devices"));
cut.WaitForAssertion(() => cut.Find("#dashboard-metric-counter-value").TextContent.Should().Be(portalMetric.DeviceCount.ToString(CultureInfo.InvariantCulture)));
Expand All @@ -95,9 +93,9 @@ public void OnRefreshDashboardEventDashboardMetricShouldRefreshMetrics()
TestContext?.Services.GetRequiredService<IDashboardLayoutService>().RefreshDashboard();

// Assert
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(6));

cut.WaitForAssertion(() => cut.Find("#dashboard-metric-counter-title").TextContent.Should().Be("Devices"));
cut.WaitForAssertion(() => cut.Find("#dashboard-metric-counter-value").TextContent.Should().Be(portalMetric.DeviceCount.ToString(CultureInfo.InvariantCulture)));
Expand All @@ -117,9 +115,9 @@ public void DashboardMetricShouldProcessProblemDetailsExceptionWhenIssueOccurs()
var cut = RenderComponent<DashboardMetrics>();

// Assert
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(6));

cut.WaitForAssertion(() => cut.Find("#dashboard-metric-counter-title").TextContent.Should().Be("Devices"));
cut.WaitForAssertion(() => cut.Find("#dashboard-metric-counter-value").TextContent.Should().Be("0"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public void DashboardShouldRenderCorrectly()
EdgeDeviceCount = 3,
ConnectedEdgeDeviceCount = 4,
FailedDeploymentCount = 5,
ConcentratorCount = 6,
ConnectedConcentratorCount = 7
ConcentratorCount = 6
};

_ = this.mockDashboardMetricsClientService.Setup(c => c.GetPortalMetrics())
Expand All @@ -54,9 +53,9 @@ public void DashboardShouldRenderCorrectly()
var cut = RenderComponent<Dashboard>();

// Assert
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(6));

cut.WaitForAssertion(() => cut.Find("#dashboard-metric-counter-title").TextContent.Should().Be("Devices"));
cut.WaitForAssertion(() => cut.Find("#dashboard-metric-counter-value").TextContent.Should().Be(portalMetric.DeviceCount.ToString(CultureInfo.InvariantCulture)));
Expand All @@ -75,8 +74,7 @@ public void OnCLickOnRefreshShouldRaiseRefreshDashboardEvent()
EdgeDeviceCount = 3,
ConnectedEdgeDeviceCount = 4,
FailedDeploymentCount = 5,
ConcentratorCount = 6,
ConnectedConcentratorCount = 7
ConcentratorCount = 6
};

var receivedEvents = new List<string>();
Expand Down
6 changes: 3 additions & 3 deletions src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/IndexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public void IndexShouldRenderCorrectly()
var cut = RenderComponent<Index>();

// Assert
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(7));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-icon").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-title").Count.Should().Be(6));
cut.WaitForAssertion(() => cut.FindAll("#dashboard-metric-counter-value").Count.Should().Be(6));

cut.WaitForAssertion(() => MockRepository.VerifyAll());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public async Task GetPortalMetricsMustReturnLogsWhenNoError()
EdgeDeviceCount = 3,
ConnectedEdgeDeviceCount = 4,
FailedDeploymentCount = 5,
ConcentratorCount = 6,
ConnectedConcentratorCount = 7
ConcentratorCount = 6
};

using var mockHttp = new MockHttpMessageHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public void GetPortalMetricsShouldReturnMetrics()
EdgeDeviceCount = 3,
ConnectedEdgeDeviceCount = 4,
FailedDeploymentCount = 5,
ConcentratorCount = 6,
ConnectedConcentratorCount = 7
ConcentratorCount = 6
};

var dashboardController = new DashboardController(portalMetric);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ public void ConcentratorMetricExporterServiceShouldExportConcentratorCountAndCon
_ = this.mockLogger.Setup(x => x.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<It.IsAnyType>(), It.IsAny<Exception>(), It.IsAny<Func<It.IsAnyType, Exception, string>>()));

this.portalMetric.ConcentratorCount = 15;
this.portalMetric.ConnectedConcentratorCount = 8;

// Act
_ = this.concentratorMetricExporterService.Execute(null);

// Assert
_ = this.concentratorCounter.Value.Should().Be(this.portalMetric.ConcentratorCount);
_ = this.connectedConcentratorCounter.Value.Should().Be(this.portalMetric.ConnectedConcentratorCount);
this.mockRepository.VerifyAll();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ public void ConcentratorMetricLoaderServiceShouldLoadConcentratorCountAndConnect
_ = this.mockLogger.Setup(x => x.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<It.IsAnyType>(), It.IsAny<Exception>(), It.IsAny<Func<It.IsAnyType, Exception, string>>()));

_ = this.mockDeviceService.Setup(service => service.GetConcentratorsCount()).ReturnsAsync(10);
_ = this.mockDeviceService.Setup(service => service.GetConnectedConcentratorsCount()).ReturnsAsync(3);

// Act
_ = this.concentratorMetricLoaderService.Execute(null);

// Assert
_ = this.portalMetric.ConcentratorCount.Should().Be(10);
_ = this.portalMetric.ConnectedConcentratorCount.Should().Be(3);
this.mockRepository.VerifyAll();
}

Expand All @@ -61,14 +59,12 @@ public void ConcentratorMetricLoaderServiceShouldHandleInternalServerErrorExcept
_ = this.mockLogger.Setup(x => x.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<It.IsAnyType>(), It.IsAny<Exception>(), It.IsAny<Func<It.IsAnyType, Exception, string>>()));

_ = this.mockDeviceService.Setup(service => service.GetConcentratorsCount()).ThrowsAsync(new InternalServerErrorException("test"));
_ = this.mockDeviceService.Setup(service => service.GetConnectedConcentratorsCount()).ReturnsAsync(3);

// Act
_ = this.concentratorMetricLoaderService.Execute(null);

// Assert
_ = this.portalMetric.ConcentratorCount.Should().Be(0);
_ = this.portalMetric.ConnectedConcentratorCount.Should().Be(3);
this.mockRepository.VerifyAll();
}

Expand All @@ -80,14 +76,12 @@ public void ConcentratorMetricLoaderServiceShouldHandleInternalServerErrorExcept
_ = this.mockLogger.Setup(x => x.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<It.IsAnyType>(), It.IsAny<Exception>(), It.IsAny<Func<It.IsAnyType, Exception, string>>()));

_ = this.mockDeviceService.Setup(service => service.GetConcentratorsCount()).ReturnsAsync(10);
_ = this.mockDeviceService.Setup(service => service.GetConnectedConcentratorsCount()).ThrowsAsync(new InternalServerErrorException("test"));

// Act
_ = this.concentratorMetricLoaderService.Execute(null);

// Assert
_ = this.portalMetric.ConcentratorCount.Should().Be(10);
_ = this.portalMetric.ConnectedConcentratorCount.Should().Be(0);
this.mockRepository.VerifyAll();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1595,56 +1595,6 @@ public async Task GetConcentratorsCountShouldInternalServerErrorExceptionWhenIss
this.mockRepository.VerifyAll();
}

[Test]
public async Task GetConnectedConcentratorsCountShouldReturnConnectedConcentratorsCount()
{
// Arrange
var service = CreateService();

var mockCountQuery = this.mockRepository.Create<IQuery>();

_ = mockCountQuery.Setup(c => c.GetNextAsJsonAsync())
.ReturnsAsync(new[]
{
/*lang=json*/
"{ totalNumber: 1}"
});

_ = this.mockRegistryManager.Setup(c => c.CreateQuery(
It.Is<string>(x => x == "SELECT COUNT() as totalNumber FROM devices WHERE devices.capabilities.iotEdge = false AND devices.tags.deviceType = 'LoRa Concentrator' AND connectionState = 'Connected'")))
.Returns(mockCountQuery.Object);

// Act
var result = await service.GetConnectedConcentratorsCount();

// Assert
_ = result.Should().Be(1);
this.mockRepository.VerifyAll();
}

[Test]
public async Task GetConnectedConcentratorsCountShouldInternalServerErrorExceptionWhenIssueOccursOnGettingConnectedConcentratorsCount()
{
// Arrange
var service = CreateService();

var mockCountQuery = this.mockRepository.Create<IQuery>();

_ = mockCountQuery.Setup(c => c.GetNextAsJsonAsync())
.ThrowsAsync(new RequestFailedException("test"));

_ = this.mockRegistryManager.Setup(c => c.CreateQuery(
It.Is<string>(x => x == "SELECT COUNT() as totalNumber FROM devices WHERE devices.capabilities.iotEdge = false AND devices.tags.deviceType = 'LoRa Concentrator' AND connectionState = 'Connected'")))
.Returns(mockCountQuery.Object);

// Act
var act = () => service.GetConnectedConcentratorsCount();

// Assert
_ = await act.Should().ThrowAsync<InternalServerErrorException>();
this.mockRepository.VerifyAll();
}

[Test]
public async Task GetEnrollmentCredentialsShouldReturnEnrollmentCredentials()
{
Expand Down

0 comments on commit 4ead540

Please sign in to comment.