kikocis/dataspace-portal public
Changesets · Branches · Tags · Compare
| Changeset | c39ccfa2d12fc3616a2e8dbcfd66d0c97e76478f5c43c850503f7b70b56360d4 |
|---|---|
| Author | Christophe Loiseau <uuh116@gmail.com> · 2024-08-12 16:07 +02:00 |
| Committer | GitHub <noreply@github.com> · 2024-08-12 14:07 UTC |
| Parents | 371742f0f792 |
4 files changed
modified CHANGELOG.md +9 −7
| @@ -13,18 +13,20 @@ | ||
| 13 | 13 | |
| 14 | 14 | #### Minor |
| 15 | 15 | |
| 16 | +- Copyable contact email and subject fields on data offer detail dialogs | |
| 17 | +- Catalog: Organization filter is no longer split into ID and name | |
| 18 | +- Catalog: Connector filter is no longer split into ID and endpoint | |
| 19 | +- Catalog: Removed dataspace filter when only one dataspace is known | |
| 20 | +- Added a message when the CaaS request feature is not available | |
| 21 | + | |
| 16 | 22 | #### Patch |
| 17 | 23 | |
| 18 | -- Copyable contact email and subject fields on data offer detail dialogs | |
| 19 | -- Fixed the close button on the self-hosted/CaaS connector choice page [#258](https://github.com/sovity/authority-portal/issues/258) | |
| 24 | +- Fixed Dashboard showing uptimes of over 100% | |
| 25 | +- Organization list: Data offer and connector counts now show the correct numbers according to the active environment | |
| 20 | 26 | - Fixed provider organization ID not showing up on CaaS connectors [#206](https://github.com/sovity/authority-portal/issues/206) |
| 21 | 27 | - Keep in mind that sovity needs to be registered in the portal for the ID to show up. |
| 22 | 28 | - Already registered connectors will be updated automatically, this process can take up to 24 hours |
| 23 | -- Added a message when the CaaS request feature is not available | |
| 24 | -- Catalog: Removed dataspace filter when only one dataspace is known | |
| 25 | -- Catalog: Organization filter is no longer split into ID and name | |
| 26 | -- Catalog: Connector filter is no longer split into ID and endpoint | |
| 27 | -- Organization list: Data offer and connector counts now show the correct numbers according to the active environment | |
| 29 | +- Fixed the close button on the self-hosted/CaaS connector choice page [#258](https://github.com/sovity/authority-portal/issues/258) | |
| 28 | 30 | |
| 29 | 31 | ### Known issues |
| 30 | 32 |
modified authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/pages/ComponentStatusApiService.kt +26 −50
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | |
| 16 | 16 | import de.sovity.authorityportal.api.model.ComponentStatusOverview |
| 17 | 17 | import de.sovity.authorityportal.api.model.UptimeStatusDto |
| 18 | -import de.sovity.authorityportal.db.jooq.enums.ComponentOnlineStatus | |
| 18 | +import de.sovity.authorityportal.db.jooq.enums.ComponentOnlineStatus.UP | |
| 19 | 19 | import de.sovity.authorityportal.db.jooq.enums.ComponentType |
| 20 | 20 | import de.sovity.authorityportal.db.jooq.enums.ConnectorOnlineStatus |
| 21 | 21 | import de.sovity.authorityportal.db.jooq.tables.records.ComponentDowntimesRecord |
| @@ -25,11 +25,9 @@ | ||
| 25 | 25 | import de.sovity.authorityportal.web.utils.TimeUtils |
| 26 | 26 | import jakarta.enterprise.context.ApplicationScoped |
| 27 | 27 | import org.jooq.DSLContext |
| 28 | -import java.text.DecimalFormat | |
| 29 | -import java.text.DecimalFormatSymbols | |
| 30 | 28 | import java.time.Duration |
| 29 | +import java.time.Duration.between | |
| 31 | 30 | import java.time.OffsetDateTime |
| 32 | -import java.util.Locale | |
| 33 | 31 | |
| 34 | 32 | @ApplicationScoped |
| 35 | 33 | class ComponentStatusApiService( |
| @@ -47,7 +45,8 @@ | ||
| 47 | 45 | } |
| 48 | 46 | |
| 49 | 47 | fun getComponentsStatusForOrganizationId(environmentId: String, organizationId: String): ComponentStatusOverview { |
| 50 | - val connectorStatuses = connectorStatusQuery.getConnectorStatusInfoByOrganizationIdAndEnvironment(organizationId, environmentId) | |
| 48 | + val connectorStatuses = | |
| 49 | + connectorStatusQuery.getConnectorStatusInfoByOrganizationIdAndEnvironment(organizationId, environmentId) | |
| 51 | 50 | val statusCount = countConnectorStatuses(connectorStatuses) |
| 52 | 51 | |
| 53 | 52 | return buildComponenStatusOverview(statusCount, environmentId) |
| @@ -60,7 +59,8 @@ | ||
| 60 | 59 | val latestDapsStatus = componentStatusService.getLatestComponentStatus(ComponentType.DAPS, environmentId) |
| 61 | 60 | val latestLoggingHouseStatus = |
| 62 | 61 | componentStatusService.getLatestComponentStatus(ComponentType.LOGGING_HOUSE, environmentId) |
| 63 | - val latestBrokerCrawlerStatus = componentStatusService.getLatestComponentStatus(ComponentType.CATALOG_CRAWLER, environmentId) | |
| 62 | + val latestBrokerCrawlerStatus = | |
| 63 | + componentStatusService.getLatestComponentStatus(ComponentType.CATALOG_CRAWLER, environmentId) | |
| 64 | 64 | val now = timeUtils.now() |
| 65 | 65 | |
| 66 | 66 | return ComponentStatusOverview( |
| @@ -82,12 +82,12 @@ | ||
| 82 | 82 | return null |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - val upSince = Duration.between(latestStatus.timeStamp.toInstant(), now.toInstant()).abs() | |
| 85 | + val upSince = between(latestStatus.timeStamp.toInstant(), now.toInstant()).abs() | |
| 86 | 86 | val timeSpan = Duration.ofDays(30) |
| 87 | 87 | |
| 88 | 88 | return UptimeStatusDto( |
| 89 | 89 | componentStatus = latestStatus.status.toDto(), |
| 90 | - upSinceSeconds = upSince.toSeconds().takeIf { latestStatus.status == ComponentOnlineStatus.UP } ?: 0, | |
| 90 | + upSinceSeconds = upSince.toSeconds().takeIf { latestStatus.status == UP } ?: 0, | |
| 91 | 91 | timeSpanSeconds = timeSpan.toSeconds(), |
| 92 | 92 | uptimePercentage = calculateUptimePercentage(latestStatus.component, timeSpan, environmentId, now) |
| 93 | 93 | ) |
| @@ -100,55 +100,31 @@ | ||
| 100 | 100 | now: OffsetDateTime |
| 101 | 101 | ): Double { |
| 102 | 102 | val limit = now.minus(timeSpan) |
| 103 | - var statusHistoryAsc = componentStatusService.getStatusHistoryAscSince(component, limit, environmentId) | |
| 104 | - // If no status was found before the limit, the first record in the history is used as base for the calculation | |
| 105 | - val initialRecord = | |
| 106 | - componentStatusService.getFirstRecordBefore(component, limit, environmentId) ?: statusHistoryAsc.first() | |
| 107 | - | |
| 108 | - // If no "UP" status was found, return 0.00 | |
| 109 | - // Also, drop all entries before first "UP" status, to avoid wrong uptime calculation | |
| 110 | - var tmpLastUpStatus = if (initialRecord.status == ComponentOnlineStatus.UP) initialRecord else { | |
| 111 | - statusHistoryAsc = statusHistoryAsc.dropWhile { it.status != ComponentOnlineStatus.UP } | |
| 112 | - statusHistoryAsc.firstOrNull() | |
| 113 | - } | |
| 114 | 103 | |
| 115 | - if (tmpLastUpStatus == null) { | |
| 116 | - return 0.00 | |
| 117 | - } | |
| 104 | + val statusHistoryAsc = componentStatusService.getStatusHistoryAscSince(component, limit, environmentId) | |
| 118 | 105 | |
| 119 | - // Sum up the total duration of "UP" statuses | |
| 120 | - var totalUptimeDuration = Duration.ZERO | |
| 121 | - for (componentRecord in statusHistoryAsc) { | |
| 122 | - if (componentRecord.status == ComponentOnlineStatus.UP) { | |
| 123 | - tmpLastUpStatus = componentRecord | |
| 124 | - } else { | |
| 125 | - totalUptimeDuration += Duration.between( | |
| 126 | - tmpLastUpStatus!!.timeStamp.toInstant(), | |
| 127 | - componentRecord.timeStamp.toInstant() | |
| 128 | - ).abs() | |
| 129 | - } | |
| 130 | - } | |
| 106 | + val first = statusHistoryAsc.first() | |
| 131 | 107 | |
| 132 | - // Add time if last status is "UP" | |
| 133 | - val lastRecord = statusHistoryAsc.lastOrNull() ?: tmpLastUpStatus | |
| 134 | - if (lastRecord!!.status == ComponentOnlineStatus.UP) { | |
| 135 | - totalUptimeDuration += Duration.between(lastRecord.timeStamp.toInstant(), now.toInstant()).abs() | |
| 108 | + val head = when { | |
| 109 | + first.timeStamp.isBefore(limit) -> ComponentDowntimesRecord(component, first.status, environmentId, limit) | |
| 110 | + else -> first | |
| 136 | 111 | } |
| 137 | 112 | |
| 138 | - // Subtract potential uptime before the limit | |
| 139 | - if (initialRecord.status == ComponentOnlineStatus.UP && initialRecord.timeStamp.isBefore(limit)) { | |
| 140 | - totalUptimeDuration -= Duration.between(initialRecord.timeStamp.toInstant(), limit.toInstant()).abs() | |
| 113 | + val body = statusHistoryAsc.drop(1) | |
| 114 | + val tail = ComponentDowntimesRecord(component, statusHistoryAsc.last().status, environmentId, now) | |
| 115 | + | |
| 116 | + val whole = listOf(head) + body + listOf(tail) | |
| 117 | + | |
| 118 | + val duration = whole.zipWithNext().fold(Duration.ZERO) { acc, (start, end) -> | |
| 119 | + when (start.status) { | |
| 120 | + UP -> acc + between(start.timeStamp, end.timeStamp) | |
| 121 | + else -> acc | |
| 122 | + } | |
| 141 | 123 | } |
| 142 | 124 | |
| 143 | - // Calculate uptime percentage | |
| 144 | - val totalDuration = | |
| 145 | - Duration.between(initialRecord.timeStamp.toInstant(), now.toInstant()).coerceAtMost(timeSpan).abs() | |
| 146 | - val uptimePercentage = totalUptimeDuration.toMillis().toDouble() / totalDuration.toMillis().toDouble() * 100 | |
| 147 | - | |
| 148 | - // Round value to two decimal places | |
| 149 | - val symbols = DecimalFormatSymbols(Locale.US) | |
| 150 | - val formatter = DecimalFormat("#.##", symbols) | |
| 151 | - return formatter.format(uptimePercentage).toDouble() | |
| 125 | + val uptime = 100.0 * duration.toMillis() / between(head.timeStamp, now).toMillis() | |
| 126 | + | |
| 127 | + return uptime | |
| 152 | 128 | } |
| 153 | 129 | |
| 154 | 130 | private fun countConnectorStatuses( |
modified authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/services/ComponentStatusService.kt +16 −16
| @@ -49,21 +49,7 @@ | ||
| 49 | 49 | val c = Tables.COMPONENT_DOWNTIMES |
| 50 | 50 | |
| 51 | 51 | return dsl.selectFrom(c) |
| 52 | - .where(c.COMPONENT.eq(component)).and(c.ENVIRONMENT.eq(environment)) | |
| 53 | - .orderBy(c.TIME_STAMP.desc()) | |
| 54 | - .limit(1) | |
| 55 | - .fetchOne() | |
| 56 | - } | |
| 57 | - | |
| 58 | - fun getFirstRecordBefore( | |
| 59 | - component: ComponentType, | |
| 60 | - limit: OffsetDateTime, | |
| 61 | - environment: String | |
| 62 | - ): ComponentDowntimesRecord? { | |
| 63 | - val c = Tables.COMPONENT_DOWNTIMES | |
| 64 | - | |
| 65 | - return dsl.selectFrom(c) | |
| 66 | - .where(c.COMPONENT.eq(component)).and(c.ENVIRONMENT.eq(environment)).and(c.TIME_STAMP.lessThan(limit)) | |
| 52 | + .where(c.COMPONENT.eq(component), c.ENVIRONMENT.eq(environment)) | |
| 67 | 53 | .orderBy(c.TIME_STAMP.desc()) |
| 68 | 54 | .limit(1) |
| 69 | 55 | .fetchOne() |
| @@ -77,7 +63,21 @@ | ||
| 77 | 63 | val c = Tables.COMPONENT_DOWNTIMES |
| 78 | 64 | |
| 79 | 65 | return dsl.selectFrom(c) |
| 80 | - .where(c.COMPONENT.eq(component)).and(c.ENVIRONMENT.eq(environment)).and(c.TIME_STAMP.greaterOrEqual(limit)) | |
| 66 | + .where( | |
| 67 | + c.COMPONENT.eq(component), | |
| 68 | + c.ENVIRONMENT.eq(environment), | |
| 69 | + c.TIME_STAMP.lessThan(limit) | |
| 70 | + ) | |
| 71 | + .orderBy(c.TIME_STAMP.desc()) | |
| 72 | + .limit(1) | |
| 73 | + .union( | |
| 74 | + dsl.selectFrom(c) | |
| 75 | + .where( | |
| 76 | + c.COMPONENT.eq(component), | |
| 77 | + c.ENVIRONMENT.eq(environment), | |
| 78 | + c.TIME_STAMP.greaterOrEqual(limit) | |
| 79 | + ) | |
| 80 | + ) | |
| 81 | 81 | .orderBy(c.TIME_STAMP.asc()) |
| 82 | 82 | .fetch() |
| 83 | 83 | } |
modified authority-portal-backend/authority-portal-quarkus/src/test/kotlin/de/sovity/authorityportal/web/tests/services/ComponentStatusApiServiceTest.kt +21 −2
| @@ -54,7 +54,8 @@ | ||
| 54 | 54 | val now = OffsetDateTime.now() |
| 55 | 55 | val env1 = "test" |
| 56 | 56 | val env2 = "dev" |
| 57 | - setupStatusHistory(now, env1, env2) | |
| 57 | + val env3 = "env3" | |
| 58 | + setupStatusHistory(now, env1, env2, env3) | |
| 58 | 59 | |
| 59 | 60 | useMockNow(now) |
| 60 | 61 | |
| @@ -96,6 +97,7 @@ | ||
| 96 | 97 | // act |
| 97 | 98 | val resultEnv1 = componentStatusApiService.getComponentsStatus(env1) |
| 98 | 99 | val resultEnv2 = componentStatusApiService.getComponentsStatus(env2) |
| 100 | + val resultEnv3 = componentStatusApiService.getComponentsStatus(env3) | |
| 99 | 101 | |
| 100 | 102 | // assert |
| 101 | 103 | assertThat(resultEnv1.dapsStatus?.componentStatus).isEqualTo(ComponentOnlineStatus.MAINTENANCE.toDto()) |
| @@ -115,9 +117,19 @@ | ||
| 115 | 117 | assertThat(resultEnv2.dapsStatus?.timeSpanSeconds).isEqualTo(Duration.ofDays(30).toSeconds()) |
| 116 | 118 | assertThat(resultEnv2.dapsStatus?.upSinceSeconds).isEqualTo(Duration.ZERO.toSeconds()) |
| 117 | 119 | assertThat(resultEnv2.loggingHouseStatus).isNull() |
| 120 | + | |
| 121 | + assertThat(resultEnv3.loggingHouseStatus?.componentStatus).isEqualTo(ComponentOnlineStatus.DOWN.toDto()) | |
| 122 | + assertThat(resultEnv3.loggingHouseStatus?.uptimePercentage).isCloseTo(50.0, Offset.offset(0.1)) | |
| 123 | + assertThat(resultEnv3.loggingHouseStatus?.timeSpanSeconds).isEqualTo(Duration.ofDays(30).toSeconds()) | |
| 124 | + assertThat(resultEnv3.loggingHouseStatus?.upSinceSeconds).isEqualTo(Duration.ZERO.toSeconds()) | |
| 125 | + | |
| 126 | + assertThat(resultEnv3.dapsStatus?.componentStatus).isEqualTo(ComponentOnlineStatus.UP.toDto()) | |
| 127 | + assertThat(resultEnv3.dapsStatus?.uptimePercentage).isCloseTo(100.0, Offset.offset(0.1)) | |
| 128 | + assertThat(resultEnv3.dapsStatus?.timeSpanSeconds).isEqualTo(Duration.ofDays(30).toSeconds()) | |
| 129 | + assertThat(resultEnv3.dapsStatus?.upSinceSeconds).isCloseTo(Duration.ofDays(15).toSeconds(), Offset.offset(1L)) | |
| 118 | 130 | } |
| 119 | 131 | |
| 120 | - private fun setupStatusHistory(now: OffsetDateTime, environment1: String, environment2: String) { | |
| 132 | + private fun setupStatusHistory(now: OffsetDateTime, environment1: String, environment2: String, environment3: String) { | |
| 121 | 133 | val c = Tables.COMPONENT_DOWNTIMES |
| 122 | 134 | |
| 123 | 135 | dsl.insertInto(c) |
| @@ -137,6 +149,13 @@ | ||
| 137 | 149 | // DAPS: Only "DOWN" status, older than 30 days |
| 138 | 150 | .values(ComponentType.DAPS, ComponentOnlineStatus.DOWN, environment2, now.minus(Duration.ofDays(31))) |
| 139 | 151 | // LH: Empty |
| 152 | + // Environment 3 | |
| 153 | + // LH: Up | |
| 154 | + .values(ComponentType.LOGGING_HOUSE, ComponentOnlineStatus.UP, environment3, now.minus(Duration.ofDays(10))) | |
| 155 | + .values(ComponentType.LOGGING_HOUSE, ComponentOnlineStatus.PENDING, environment3, now.minus(Duration.ofDays(5))) | |
| 156 | + .values(ComponentType.LOGGING_HOUSE, ComponentOnlineStatus.DOWN, environment3, now.minus(Duration.ofSeconds(1))) | |
| 157 | + // DAPS: Only "UP" status | |
| 158 | + .values(ComponentType.DAPS, ComponentOnlineStatus.UP, environment3, now.minus(Duration.ofDays(15))) | |
| 140 | 159 | .execute() |
| 141 | 160 | } |
| 142 | 161 | } |