diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java index 0f94e858..5c6a8a3a 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactController.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.hs.office.contact; +import io.micrometer.core.annotation.Timed; import net.hostsharing.hsadminng.mapper.StandardMapper; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeContactsApi; @@ -33,7 +34,8 @@ public class HsOfficeContactController implements HsOfficeContactsApi { @Override @Transactional(readOnly = true) - public ResponseEntity> listContacts( + @Timed("app.contacts.api.getListOfContacts") + public ResponseEntity> getListOfContacts( final String currentSubject, final String assumedRoles, final String caption) { @@ -47,7 +49,8 @@ public class HsOfficeContactController implements HsOfficeContactsApi { @Override @Transactional - public ResponseEntity addContact( + @Timed("app.contacts.api.postNewContact") + public ResponseEntity postNewContact( final String currentSubject, final String assumedRoles, final HsOfficeContactInsertResource body) { @@ -69,7 +72,8 @@ public class HsOfficeContactController implements HsOfficeContactsApi { @Override @Transactional(readOnly = true) - public ResponseEntity getContactByUuid( + @Timed("app.contacts.api.getSingleContactByUuid") + public ResponseEntity getSingleContactByUuid( final String currentSubject, final String assumedRoles, final UUID contactUuid) { @@ -85,6 +89,7 @@ public class HsOfficeContactController implements HsOfficeContactsApi { @Override @Transactional + @Timed("app.contacts.api.deleteContactByUuid") public ResponseEntity deleteContactByUuid( final String currentSubject, final String assumedRoles, @@ -101,6 +106,7 @@ public class HsOfficeContactController implements HsOfficeContactsApi { @Override @Transactional + @Timed("app.contacts.api.patchContact") public ResponseEntity patchContact( final String currentSubject, final String assumedRoles, diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepository.java index e893bced..58f9ba61 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRbacRepository.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.hs.office.contact; +import io.micrometer.core.annotation.Timed; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; @@ -9,18 +10,23 @@ import java.util.UUID; public interface HsOfficeContactRbacRepository extends Repository { + @Timed("app.contacts.repo.findByUuid.rbac") Optional findByUuid(UUID id); @Query(""" SELECT c FROM HsOfficeContactRbacEntity c WHERE :caption is null OR c.caption like concat(cast(:caption as text), '%') - """) + """) + @Timed("app.contacts.repo.findContactByOptionalCaptionLike.rbac") List findContactByOptionalCaptionLike(String caption); + @Timed("app.contacts.repo.save.rbac") HsOfficeContactRbacEntity save(final HsOfficeContactRbacEntity entity); + @Timed("app.contacts.repo.deleteByUuid.rbac") int deleteByUuid(final UUID uuid); + @Timed("app.contacts.repo.count.rbac") long count(); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRealRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRealRepository.java index b4099422..a42c2226 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRealRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContactRealRepository.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.hs.office.contact; +import io.micrometer.core.annotation.Timed; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; @@ -9,18 +10,23 @@ import java.util.UUID; public interface HsOfficeContactRealRepository extends Repository { + @Timed("app.repo.contacts.findByUuid.real") Optional findByUuid(UUID id); @Query(""" SELECT c FROM HsOfficeContactRealEntity c WHERE :caption is null OR c.caption like concat(cast(:caption as text), '%') - """) + """) + @Timed("app.repo.contacts.findContactByOptionalCaptionLike.real") List findContactByOptionalCaptionLike(String caption); + @Timed("app.repo.contacts.save.real") HsOfficeContactRealEntity save(final HsOfficeContactRealEntity entity); + @Timed("app.repo.contacts.deleteByUuid.real") int deleteByUuid(final UUID uuid); + @Timed("app.repo.contacts.count.real") long count(); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonController.java index ac746aab..d1c1c018 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonController.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.hs.office.person; +import io.micrometer.core.annotation.Timed; import net.hostsharing.hsadminng.mapper.StandardMapper; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficePersonsApi; @@ -30,7 +31,8 @@ public class HsOfficePersonController implements HsOfficePersonsApi { @Override @Transactional(readOnly = true) - public ResponseEntity> listPersons( + @Timed("app.persons.api.getListOfPersons") + public ResponseEntity> getListOfPersons( final String currentSubject, final String assumedRoles, final String caption) { @@ -44,7 +46,8 @@ public class HsOfficePersonController implements HsOfficePersonsApi { @Override @Transactional - public ResponseEntity addPerson( + @Timed("app.persons.api.postNewPerson") + public ResponseEntity postNewPerson( final String currentSubject, final String assumedRoles, final HsOfficePersonInsertResource body) { @@ -66,7 +69,8 @@ public class HsOfficePersonController implements HsOfficePersonsApi { @Override @Transactional(readOnly = true) - public ResponseEntity getPersonByUuid( + @Timed("app.persons.api.getSinglePersonByUuid") + public ResponseEntity getSinglePersonByUuid( final String currentSubject, final String assumedRoles, final UUID personUuid) { @@ -82,6 +86,7 @@ public class HsOfficePersonController implements HsOfficePersonsApi { @Override @Transactional + @Timed("app.persons.api.deletePersonByUuid") public ResponseEntity deletePersonByUuid( final String currentSubject, final String assumedRoles, @@ -98,6 +103,7 @@ public class HsOfficePersonController implements HsOfficePersonsApi { @Override @Transactional + @Timed("app.persons.api.patchPerson") public ResponseEntity patchPerson( final String currentSubject, final String assumedRoles, diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonRepository.java index f7481339..41d195ce 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonRepository.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.hs.office.person; +import io.micrometer.core.annotation.Timed; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; @@ -9,6 +10,7 @@ import java.util.UUID; public interface HsOfficePersonRepository extends Repository { + @Timed("app.persons.repo.findByUuid.rbac") Optional findByUuid(UUID personUuid); @Query(""" @@ -17,12 +19,16 @@ public interface HsOfficePersonRepository extends Repository findPersonByOptionalNameLike(String name); + @Timed("app.persons.repo.save.rbac") HsOfficePersonEntity save(final HsOfficePersonEntity entity); + @Timed("app.persons.repo.deleteByUuid.rbac") int deleteByUuid(final UUID personUuid); + @Timed("app.persons.repo.count.rbac") long count(); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java index 29078bb3..5778d864 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.hs.office.relation; +import io.micrometer.core.annotation.Timed; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository; import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeRelationsApi; @@ -21,7 +22,6 @@ import java.util.function.BiConsumer; @RestController - public class HsOfficeRelationController implements HsOfficeRelationsApi { @Autowired @@ -44,7 +44,8 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { @Override @Transactional(readOnly = true) - public ResponseEntity> listRelations( + @Timed("app.relations.api.getListOfRelations") + public ResponseEntity> getListOfRelations( final String currentSubject, final String assumedRoles, final UUID personUuid, @@ -66,7 +67,8 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { @Override @Transactional - public ResponseEntity addRelation( + @Timed("app.relations.api.postNewRelation") + public ResponseEntity postNewRelation( final String currentSubject, final String assumedRoles, final HsOfficeRelationInsertResource body) { @@ -100,7 +102,8 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { @Override @Transactional(readOnly = true) - public ResponseEntity getRelationByUuid( + @Timed("app.relations.api.getSingleRelationByUuid") + public ResponseEntity getSingleRelationByUuid( final String currentSubject, final String assumedRoles, final UUID relationUuid) { @@ -116,6 +119,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { @Override @Transactional + @Timed("apprelations.api..deleteRelationByUuid") public ResponseEntity deleteRelationByUuid( final String currentSubject, final String assumedRoles, @@ -132,6 +136,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { @Override @Transactional + @Timed("app.relations.api.patchRelation") public ResponseEntity patchRelation( final String currentSubject, final String assumedRoles, diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java index cce31305..23889745 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.hs.office.relation; +import io.micrometer.core.annotation.Timed; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; @@ -10,12 +11,14 @@ import java.util.UUID; public interface HsOfficeRelationRbacRepository extends Repository { + @Timed("app.relations.repo.findByUuid.rbac") Optional findByUuid(UUID id); @Query(value = """ SELECT p.* FROM hs_office.relation_rv AS p WHERE p.anchorUuid = :personUuid OR p.holderUuid = :personUuid """, nativeQuery = true) + @Timed("app.relations.repo.findRelationRelatedToPersonUuid.rbac") List findRelationRelatedToPersonUuid(@NotNull UUID personUuid); /** @@ -51,16 +54,20 @@ public interface HsOfficeRelationRbacRepository extends Repository findRelationRelatedToPersonUuidRelationTypePersonAndContactDataImpl( final UUID personUuid, final String relationType, final String personData, final String contactData); + @Timed("app.relations.repo.save.rbac") HsOfficeRelationRbacEntity save(final HsOfficeRelationRbacEntity entity); + @Timed("app.relations.repo.count.rbac") long count(); + @Timed("app.relations.repo.deleteByUuid.rbac") int deleteByUuid(UUID uuid); private static String toSqlLikeOperand(final String text) { diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRealRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRealRepository.java index 292f9034..bd1eac0c 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRealRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRealRepository.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.hs.office.relation; +import io.micrometer.core.annotation.Timed; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; @@ -10,6 +11,7 @@ import java.util.UUID; public interface HsOfficeRelationRealRepository extends Repository { + @Timed("app.repo.relations.findByUuid.real") Optional findByUuid(UUID id); default List findRelationRelatedToPersonUuidAndRelationType(@NotNull UUID personUuid, HsOfficeRelationType relationType) { @@ -20,6 +22,7 @@ public interface HsOfficeRelationRealRepository extends Repository findRelationRelatedToPersonUuid(@NotNull UUID personUuid); @Query(value = """ @@ -27,11 +30,15 @@ public interface HsOfficeRelationRealRepository extends Repository findRelationRelatedToPersonUuidAndRelationTypeString(@NotNull UUID personUuid, String relationType); + @Timed("app.repo.relations.save.real") HsOfficeRelationRealEntity save(final HsOfficeRelationRealEntity entity); + @Timed("app.repo.relations.count.real") long count(); + @Timed("app.repo.relations.deleteByUuid.real") int deleteByUuid(UUID uuid); } diff --git a/src/main/resources/api-definition/hs-office/hs-office-contacts-with-uuid.yaml b/src/main/resources/api-definition/hs-office/hs-office-contacts-with-uuid.yaml index a6561e8d..9f808b25 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-contacts-with-uuid.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-contacts-with-uuid.yaml @@ -2,7 +2,7 @@ get: tags: - hs-office-contacts description: 'Fetch a single business contact by its uuid, if visible for the current subject.' - operationId: getContactByUuid + operationId: getSingleContactByUuid parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/api-definition/hs-office/hs-office-contacts.yaml b/src/main/resources/api-definition/hs-office/hs-office-contacts.yaml index cc3f56af..f7412ddf 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-contacts.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-contacts.yaml @@ -3,7 +3,7 @@ get: description: Returns the list of (optionally filtered) contacts which are visible to the current subject or any of it's assumed roles. tags: - hs-office-contacts - operationId: listContacts + operationId: getListOfContacts parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' @@ -31,7 +31,7 @@ post: summary: Adds a new contact. tags: - hs-office-contacts - operationId: addContact + operationId: postNewContact parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/api-definition/hs-office/hs-office-persons-with-uuid.yaml b/src/main/resources/api-definition/hs-office/hs-office-persons-with-uuid.yaml index fe63c509..a983e90f 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-persons-with-uuid.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-persons-with-uuid.yaml @@ -2,7 +2,7 @@ get: tags: - hs-office-persons description: 'Fetch a single business person by its uuid, if visible for the current subject.' - operationId: getPersonByUuid + operationId: getSinglePersonByUuid parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/api-definition/hs-office/hs-office-persons.yaml b/src/main/resources/api-definition/hs-office/hs-office-persons.yaml index e761957c..b17f1a93 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-persons.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-persons.yaml @@ -3,7 +3,7 @@ get: description: Returns the list of (optionally filtered) persons which are visible to the current subject or any of it's assumed roles. tags: - hs-office-persons - operationId: listPersons + operationId: getListOfPersons parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' @@ -31,7 +31,7 @@ post: summary: Adds a new person. tags: - hs-office-persons - operationId: addPerson + operationId: postNewPerson parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/api-definition/hs-office/hs-office-relations-with-uuid.yaml b/src/main/resources/api-definition/hs-office/hs-office-relations-with-uuid.yaml index 3dbe1391..b492f322 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-relations-with-uuid.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-relations-with-uuid.yaml @@ -2,7 +2,7 @@ get: tags: - hs-office-relations description: 'Fetch a single person relation by its uuid, if visible for the current subject.' - operationId: getRelationByUuid + operationId: getSingleRelationByUuid parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/api-definition/hs-office/hs-office-relations.yaml b/src/main/resources/api-definition/hs-office/hs-office-relations.yaml index 77d9dda0..70218c00 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-relations.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-relations.yaml @@ -5,7 +5,7 @@ get: To match data, all given query parameters must be fulfilled ('and' / logical conjunction). tags: - hs-office-relations - operationId: listRelations + operationId: getListOfRelations parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' @@ -52,7 +52,7 @@ post: summary: Adds a new person relation. tags: - hs-office-relations - operationId: addRelation + operationId: postNewRelation parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9cfd265f..27020234 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -9,9 +9,11 @@ management: web: exposure: include: info, health, metrics + observations: + annotations: + enabled: true spring: - datasource: driver-class-name: org.postgresql.Driver password: password @@ -33,3 +35,11 @@ liquibase: hsadminng: postgres: leakproof: + +metrics: + distribution: + percentiles-histogram: + http: + server: + requests: true + diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonControllerAcceptanceTest.java index 7ab55de0..d0228ad2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/person/HsOfficePersonControllerAcceptanceTest.java @@ -52,7 +52,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup EntityManager em; @Nested - class ListPersons { + class GetListOfPersons { @Test void globalAdmin_withoutAssumedRoles_canViewAllPersons_ifNoCriteriaGiven() { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java index b65ae95e..02a228f5 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java @@ -54,7 +54,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean JpaAttempt jpaAttempt; @Nested - class ListRelations { + class GetListOfRelations { @Test void globalAdmin_withoutAssumedRoles_canViewAllRelationsOfGivenPersonAndType() {