Skip to content

Uptime percentage #61

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

Open
wants to merge 80 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
1314096
Added method getRecordsInTimeSpan to retrieve records in specific tim…
OrleneMitchell Jul 15, 2024
ae484df
Code for calculating the total uptime percentage for a given service …
OrleneMitchell Jul 15, 2024
4d33e7b
Code extracting the closing opening hour which is used to determine t…
OrleneMitchell Jul 15, 2024
bf555a6
Exclude the period of time starting before the requested start date t…
OrleneMitchell Jul 16, 2024
96adad3
Added code for managing opening hours on a starting day
OrleneMitchell Jul 16, 2024
0e45425
Added code to retrieve opening hours from service record. The rules o…
OrleneMitchell Jul 16, 2024
8307ba2
loops through the last record to tally opening times in minutes if th…
OrleneMitchell Jul 16, 2024
a5eab29
calculates the time duration to the user requested end date
OrleneMitchell Jul 17, 2024
0cdbda8
Manages calculations of totaluptime up time that is under a day.
OrleneMitchell Jul 18, 2024
b0a1646
Assertion tests of to and from entry dates to show they function as …
OrleneMitchell Jul 18, 2024
406f5e4
Update and test of code that throws an exception if no records are f…
OrleneMitchell Jul 18, 2024
91f789a
Code for expected totaluptime calculation works for one record.
OrleneMitchell Jul 21, 2024
c24b4f9
Should have read sumOfExpectedUptime.
OrleneMitchell Jul 21, 2024
7a05f24
Tidying up of fields sumOfActualUptime, sumOfExpectedUptime to improv…
OrleneMitchell Jul 21, 2024
f928931
Addition of code for last record to calculate the actual uptime of a …
OrleneMitchell Jul 21, 2024
af537a3
calculatePercentageUptime in UpTimeCalculator is only accessible t…
OrleneMitchell Jul 22, 2024
ccf6883
This code manages the tallying of the actual and expected uptimes for…
OrleneMitchell Jul 22, 2024
d028c99
Added code for managing tallying of the actual uptimes for managing m…
OrleneMitchell Jul 22, 2024
350f282
Tidying up of code to improve readability.
OrleneMitchell Jul 22, 2024
439eb13
Tidying up of code to duplicate coding and to improve readability.
OrleneMitchell Jul 22, 2024
e4f9453
The class access was changed from a static global variable to a priva…
OrleneMitchell Aug 5, 2024
d32fc41
Code refactored to simplify and improve readability.
OrleneMitchell Aug 5, 2024
e22c4ba
Removed class variable for uptimeTotal and introduced TimeSpan as a c…
OrleneMitchell Aug 6, 2024
bafd4ce
Fixed a bug in the TimeSpan validation. Calling a method didn't work …
OrleneMitchell Aug 6, 2024
a4c1ec4
Fixe compiler errors due to the use of using ZonedDateTime.
OrleneMitchell Aug 7, 2024
248d860
The corresponding opening hours for each day in the duration are obta…
OrleneMitchell Aug 8, 2024
011a550
The corresponding opening hours for each day in the duration are obta…
OrleneMitchell Aug 8, 2024
d36830e
Corrected a fail which occurred using the wrong import caused by usin…
OrleneMitchell Aug 9, 2024
a567b92
Converted the class openinghours to a record to make it immutable and…
OrleneMitchell Aug 13, 2024
925fa08
Updated Record entity to include Local date time, date and time versi…
OrleneMitchell Aug 15, 2024
c75de84
Updated UpTimeCalculator to use the method time() from theclss Record…
OrleneMitchell Aug 15, 2024
17a990b
Updated UpTimeCalculator to use the method time() from the RecordEnti…
OrleneMitchell Aug 15, 2024
29bbbda
Chane current to currentRecord to aid readability.
OrleneMitchell Aug 15, 2024
a485c34
startOfDay and endOFDay uses currentRecord dateTime to aid readability.
OrleneMitchell Aug 15, 2024
8620635
Updated nextRecord variables to improve readability.
OrleneMitchell Aug 15, 2024
5c37a15
Updated sumfullDays method arguments to improve readability.
OrleneMitchell Aug 15, 2024
5273ccd
Created an alternative solution with smaller building blocks
tlheen Aug 16, 2024
1ca3b8c
I removed redundant code when managing the last day, setting the vari…
OrleneMitchell Aug 20, 2024
d92f867
Redundant code removed as it its is no longer needed after the previo…
OrleneMitchell Aug 20, 2024
8e63a22
The code was updated to include the calculation to manage the first d…
OrleneMitchell Aug 20, 2024
5d73eb6
The expected up-time calculation requires a duration in date-time for…
OrleneMitchell Aug 20, 2024
a0c0945
The method sumLastDays was created to include the calculation to man…
OrleneMitchell Aug 20, 2024
351ee76
The service's actual uptime is now assigned to a single routine to re…
OrleneMitchell Aug 21, 2024
54a3ee7
Fungerende versjon, men hvor kallkjeden ikke er optimal
tlheen Aug 21, 2024
ae4f71b
Tidied by removing superfluous variables used in the sumFullDays meth…
OrleneMitchell Aug 22, 2024
4f3b4a6
Tidied by removing superfluous variables used in the sumLastDay metho…
OrleneMitchell Aug 22, 2024
fe4dad5
Fixes a bug where to-date was null i the RecordIntervals
tlheen Aug 23, 2024
43ea7b8
Tar i bruk ny kode i UptimeCalculator
tlheen Aug 23, 2024
e817553
Fixed calculation of total ActualExpectedUptime
tlheen Aug 26, 2024
c63a440
Moves functionality for summing actual expected uptime to uptimeTotal
tlheen Aug 26, 2024
aeca92b
Tidying up - reducing visibility for some classes/methods
tlheen Aug 26, 2024
8cc1f90
Moves calculation of opening hours in minutes
tlheen Aug 27, 2024
acc9e49
Removes methods that are not in use.
tlheen Aug 29, 2024
03dd08b
Takes into account that the start and the end of a timespan can happe…
tlheen Aug 29, 2024
3ba3021
Fixes the issue with opening hours until 23:59
tlheen Aug 29, 2024
3236971
Makes use of the same metod for calculating duration between to times…
tlheen Aug 29, 2024
31d9604
Merge branch 'UptimePercentage' into uptimePercentage-v4
OrleneMitchell Aug 30, 2024
f88768b
Uptime percentage v4 (#62)
tlheen Aug 30, 2024
7dbf55b
Fixed the missing test - it was related to timestamp accuracy
tlheen Aug 30, 2024
a7d955b
Merge branch 'UptimePercentage' into uptimePercentage-v4
tlheen Aug 30, 2024
3a02299
Merge pull request #63 from tlheen/uptimePercentage-v4
OrleneMitchell Aug 30, 2024
adb90e9
Added a new message for clarity
OrleneMitchell Sep 2, 2024
ba1f112
Added TimeSpan, UptimeTotals and configuration for /UpTime/{Service_i…
OrleneMitchell Sep 9, 2024
4b33387
Changes include Up time percent solution including end point coding
OrleneMitchell Sep 10, 2024
8fdeda8
Changes include Up time percent solution including end point coding
OrleneMitchell Oct 1, 2024
db35d3f
feat: can now mark/add external dashboards
Jonas-Juvet Oct 24, 2024
6dafc34
Endpoint coding for UpTimeTotals
OrleneMitchell Oct 25, 2024
7ea0457
feat: samarbeidspartner v1.0 now ready
Jonas-Juvet Oct 30, 2024
00d11d1
fix: urlEncoder didnt replace white-space with %20
Jonas-Juvet Oct 31, 2024
a3f0bae
Refactor configuration and endpoints for UpTime service; added defaul…
rfc3092 Mar 7, 2025
2f44aa6
Testing commit.
OrleneMitchell Mar 7, 2025
ce10b5a
The new case returns a value of zero when a service is down but close…
OrleneMitchell Nov 27, 2024
9bb7eac
The new case returns a value of zero when a service is down but close…
OrleneMitchell Mar 7, 2025
3c11461
Fixing of errors and warnings.
OrleneMitchell Mar 10, 2025
9b9607a
Merge branch 'main' into UptimePercentage
rfc3092 Mar 26, 2025
2dc5721
Merge pull request #65 from rfc3092/UptimePercentage
paomoo May 2, 2025
56fc726
Fixing of errors and warnings
OrleneMitchell May 6, 2025
0a46186
Merge remote-tracking branch 'upstream/UptimePercentage' into UptimeP…
OrleneMitchell May 6, 2025
7d74345
fix 1: openhours is 0, then actural hours should be 0. 2.fix to is be…
OrleneMitchell May 13, 2025
e00d010
Add test for retrievedUpTimeTotalsDto based on concrete data, not ran…
paomoo May 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ node_modules
# Nix stuffs
/.direnv
result*
/.m2/
22 changes: 22 additions & 0 deletions .run/StatusplattformServer.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="StatusplattformServer" type="Application" factoryName="Application" nameIsGenerated="true">
<envs>
<env name="AZURE_APP_CLIENT_ID" value="local" />
<env name="AZURE_APP_CLIENT_SECRET" value="local" />
<env name="swagger-api-key" value="key" />
<env name="teamkatalogApiUrl" value="https://teamkatalog-api.intern.dev.nav.no" />
<env name="ENV" value="dev" />
</envs>
<option name="MAIN_CLASS_NAME" value="no.nav.statusplattform.server.StatusplattformServer" />
<module name="server" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="no.nav.statusplattform.server.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="docker-compose.yaml.postgres-db: Compose Deployment (Postgres only)" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
<deployment type="docker-compose.yml">
<settings>
<option name="envFilePath" value="" />
<option name="services">
<list>
<option value="postgres-db" />
</list>
</option>
<option name="sourceFilePath" value="docker-compose.yaml" />
<option name="upNoDeps" value="true" />
</settings>
</deployment>
<method v="2" />
</configuration>
</component>
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM library/maven:3-amazoncorretto-21 as maven
FROM library/maven:3-amazoncorretto-21 AS maven

COPY pom.xml pom.xml
COPY . .

RUN mvn clean dependency:go-offline -B
RUN mvn package
RUN mvn clean dependency:go-offline package -B


FROM library/openjdk:21
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

## Statusportalen api
Repository inneholder apiet til statusportalen.
For å kunne kjøre lokalt trengs en kjørende Postgres server, med databasen navstatus.
For å kunne kjøre lokalt trengs en kjørende Postgres server, med databasen navstatus.
(Se DataSourceTransformer).

Miljøvariable for lokal kjøring:
Se [AppConfig.java](config/src/main/java/no/nav/statusplattform/AppConfig.java) for miljøvariabler for lokal kjøring, med defaults.

teamkatalogApiUrl=https://teamkatalog-api.intern.dev.nav.no
swagger-api-key=key
DB_PASSWORD=xxxxx
DB_USERNAME="some username"
AZURE_APP_CLIENT_ID: local
AZURE_APP_CLIENT_SECRET: local
ENV:
12 changes: 12 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
<configOptions>
<dateLibrary>java8</dateLibrary>
</configOptions>
<!-- ORLENE: Added explicit type mapping from number (e.g. type: number) to BigDecimal, to import in generated files. -->
<typeMappings>
<typeMapping>number=java.math.BigDecimal</typeMapping>
</typeMappings>
</configuration>
</execution>
</executions>
Expand All @@ -113,5 +117,13 @@
<version>2.22.2</version>
</plugin>
</plugins>
<resources>
<resource>
<directory>target/generated-sources/openapi-java</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</project>
24 changes: 24 additions & 0 deletions api/src/main/java/no/nav/statusplattform/api/EntityDtoMappers.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
import nav.statusplattform.core.enums.RuleType;
import nav.statusplattform.core.enums.ServiceStatus;
import nav.statusplattform.core.enums.ServiceType;
import nav.statusplattform.core.openingHours.TimeSpan;
import nav.statusplattform.core.openingHours.UpTimeTotals;
import no.nav.statusplattform.api.TeamKatalogIntegrasjon.TeamKatalogKlient;


import no.nav.statusplattform.generated.api.AreaDto;
import no.nav.statusplattform.generated.api.DashboardDto;
import no.nav.statusplattform.generated.api.DashboardNameIdDto;
Expand All @@ -32,7 +36,10 @@
import no.nav.statusplattform.generated.api.ServiceTypeDto;
import no.nav.statusplattform.generated.api.StatusDto;
import no.nav.statusplattform.generated.api.SubAreaDto;
import no.nav.statusplattform.generated.api.UpTimeTotalsDto;


import java.math.BigDecimal;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -171,6 +178,7 @@ public static OpsMessageEntity toOpsMessageEntity(OPSmessageDto opsMessageDto) {
return opsMessageEntity;
}


public static ServiceDto toServiceDtoDeep(ServiceEntity service ,List<ServiceEntity> dependencies){
Map<ServiceEntity, List<ServiceEntity>> map = new HashMap<>();
map.put(service,dependencies);
Expand Down Expand Up @@ -257,6 +265,14 @@ public static DashboardDto toDashboardDtoDeep(Map.Entry<DashboardEntity,List<Are
return dto;
}

// Convert a list of entries into a list of DashboardDto objects
public static List<DashboardDto> toDashboardDtoDeepList(List<Map.Entry<DashboardEntity, List<AreaWithServices>>> dashboardEntries) {
return dashboardEntries.stream()
.map(EntityDtoMappers::toDashboardDtoDeep) // Using the existing conversion method for each entry
.collect(Collectors.toList());
}


public static DashboardNameIdDto toDashboardDtoShallow(DashboardEntity entity){
DashboardNameIdDto dto = new DashboardNameIdDto();
dto.setId(entity.getId());
Expand Down Expand Up @@ -381,4 +397,12 @@ public static HelpTextEntity toHelpTextEntity(HelpTextDto dto){
entity.setContent(dto.getContent());
return entity;
}

public static UpTimeTotalsDto toUpTimeTotalsDto(final UpTimeTotals upTimeTotals) {
//Orlene: Using BigDecimal as expected by the DTO.
var dto = new UpTimeTotalsDto();
dto.setSumOfActualUptime(BigDecimal.valueOf(upTimeTotals.sumOfActualUptime()));
dto.setSumOfExpectedUptime(BigDecimal.valueOf(upTimeTotals.sumOfExpectedUptime()));
return dto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
import org.fluentjdbc.DbContext;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import java.util.*;
import java.util.stream.Collectors;

public class OpeningHoursHelper {
Expand Down Expand Up @@ -119,4 +117,5 @@ public void setOpeningHoursToService(UUID groupId, UUID serviceId) {
OpeningHoursDailyMap.populateMap(openingHoursRepository);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,14 @@ public List<OPSmessageDto> getOpsMessagesForDashboard(DashboardDto dashboardDto)

return result;
}

public List<OPSmessageDto> getOpsMessagesByServiceIds(List<String> serviceIds) {
// Convert list of service IDs to UUIDs
List<UUID> serviceUUIDs = serviceIds.stream().map(UUID::fromString).collect(Collectors.toList());

// Fetch messages from the repository
return opsRepository.findOpsMessagesByServiceIds(serviceUUIDs).stream()
.map(EntityDtoMappers::toOpsMessageDtoShallow)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package no.nav.statusplattform.api.Helpers;


import no.nav.statusplattform.generated.api.UpTimeTotalsDto;
import nav.statusplattform.core.openingHours.TimeSpan;
import nav.statusplattform.core.openingHours.UpTimeCalculator;
import nav.statusplattform.core.repositories.OpeningHoursRepository;
import nav.statusplattform.core.repositories.RecordRepository;
import no.nav.statusplattform.api.EntityDtoMappers;
import org.fluentjdbc.DbContext;


import java.util.UUID;

public class UpTimeHelper {

private final UpTimeCalculator upTimeCalculator;


public UpTimeHelper(DbContext dbContext) {
this.upTimeCalculator = new UpTimeCalculator(new RecordRepository(dbContext), new OpeningHoursRepository(dbContext));
}

public UpTimeTotalsDto getServiceUpTimeSums(UUID service_id, TimeSpan timeSpan) {
return EntityDtoMappers.toUpTimeTotalsDto(upTimeCalculator.calculateUpTimeForService(service_id, timeSpan));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
package no.nav.statusplattform.api;

import no.nav.statusplattform.api.v3.controllers.AreaController;
import no.nav.statusplattform.api.v3.controllers.DashboardController;
import no.nav.statusplattform.api.v3.controllers.HealthCheck;
import no.nav.statusplattform.api.v3.controllers.OpeningHoursController;
import no.nav.statusplattform.api.v3.controllers.OpsController;
import no.nav.statusplattform.api.v3.controllers.RecordController;
import no.nav.statusplattform.api.v3.controllers.ServiceController;
import no.nav.statusplattform.api.v3.controllers.UserController;
import no.nav.statusplattform.api.v3.controllers.WcagController;
import no.nav.statusplattform.api.v3.controllers.*;
import no.nav.statusplattform.infrastructure.ApiFilter;
import no.nav.statusplattform.infrastructure.AuthenticationFilter;
import no.nav.statusplattform.infrastructure.CORSFilter;
Expand Down Expand Up @@ -37,6 +29,7 @@ public StatusplattformApi(String context) {
corsFilter = new CORSFilter();
addFilter(new FilterHolder(corsFilter),"/*", EnumSet.of(DispatcherType.REQUEST));
addServlet(new ServletHolder(new WebJarServlet("swagger-ui")), "/swagger/*");
var dbContext = new DbContext();
addServlet(new ServletHolder(new ApiServlet(List.of(
new AreaController(dbContext),
new DashboardController(dbContext),
Expand All @@ -46,7 +39,9 @@ public StatusplattformApi(String context) {
new OpeningHoursController(dbContext),
new HealthCheck(dbContext),
new UserController(),
new WcagController()
new WcagController(),
new UpTimeController(dbContext),
new TeamKatalogController()
))), "/*");

addFilter(new FilterHolder( new AuthenticationFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));
Expand Down
Loading