Skip to content
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

Add page to view application errors #357

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions docs/docs/champagne_admin/errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Viewing and Managing Application Errors

The application errors page lets a champagne admin user view and resolve a list of application errors that have occurred in champagne.

![Screenshot](../img/errors.png)

## Resolve a single error

To resolve a single error, find the row with the error to resolve and click the 3 vertical dots to open the action menu and select Resolve.

## Resolve all unresolved errors

To resolve all existing errors that are unresolved, click the button at the top right of the Application Errors card.

## Viewing error details

To view more details about a specific error, then find the row with the error and click the 3 vertical dots to open the action menu and select View Details. This will open a dialog with more information including error causes and stack traces.
Binary file added docs/docs/img/errors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ nav:
- Users: champagne_admin/users.md
- Audits: champagne_admin/audits.md
- Systems: champagne_admin/systems.md
- Errors: champagne_admin/errors.md
4 changes: 2 additions & 2 deletions service/src/main/java/org/kiwiproject/champagne/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.kiwiproject.champagne.dao.mappers.BuildMapper;
import org.kiwiproject.champagne.job.CleanOutAuditsJob;
import org.kiwiproject.champagne.model.Build;
import org.kiwiproject.champagne.resource.ApplicationErrorWithAuthResource;
import org.kiwiproject.champagne.resource.AuditRecordResource;
import org.kiwiproject.champagne.resource.AuthResource;
import org.kiwiproject.champagne.resource.BuildResource;
Expand All @@ -49,7 +50,6 @@
import org.kiwiproject.dropwizard.error.ErrorContextBuilder;
import org.kiwiproject.dropwizard.error.dao.ApplicationErrorDao;
import org.kiwiproject.dropwizard.error.model.ServiceDetails;
import org.kiwiproject.dropwizard.error.resource.ApplicationErrorResource;
import org.kiwiproject.dropwizard.jdbi3.Jdbi3Builders;
import org.kiwiproject.dropwizard.util.config.JacksonConfig;
import org.kiwiproject.dropwizard.util.exception.StandardExceptionMappers;
Expand Down Expand Up @@ -120,7 +120,7 @@ public void run(AppConfig configuration, Environment environment) {
environment.jersey().register(new HostConfigurationResource(hostDao, componentDao, tagDao, auditRecordDao, errorDao));
environment.jersey().register(new TaskResource(releaseDao, releaseStatusDao, taskDao, taskStatusDao, deploymentEnvironmentDao, auditRecordDao, errorDao));
environment.jersey().register(new UserResource(userDao, deployableSystemDao, auditRecordDao, errorDao));
environment.jersey().register(new ApplicationErrorResource(errorDao));
environment.jersey().register(new ApplicationErrorWithAuthResource(errorDao));
environment.jersey().register(new DeployableSystemResource(deployableSystemDao, userDao, deploymentEnvironmentDao, auditRecordDao, errorDao));
environment.jersey().register(new TagResource(tagDao, auditRecordDao, errorDao));
environment.jersey().register(new MetricsResource(buildDao));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.kiwiproject.champagne.resource;

import java.util.OptionalInt;
import java.util.OptionalLong;

import com.codahale.metrics.annotation.ExceptionMetered;
import com.codahale.metrics.annotation.Timed;
import com.google.common.annotations.VisibleForTesting;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.kiwiproject.dropwizard.error.dao.ApplicationErrorDao;
import org.kiwiproject.dropwizard.error.resource.ApplicationErrorResource;

/**
* The purposes of this resource is to add authentication and authorization to the application errors endpoints. The
* application errors library does not have a concept of auth as of this writing.
*/
@Path("/errors")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
public class ApplicationErrorWithAuthResource {

private final ApplicationErrorResource delegate;

public ApplicationErrorWithAuthResource(ApplicationErrorDao errorDao) {
this(new ApplicationErrorResource(errorDao));
}

@VisibleForTesting
ApplicationErrorWithAuthResource(ApplicationErrorResource delegate) {
this.delegate = delegate;
}

@GET
@Path("/{id}")
@RolesAllowed({"admin"})
@Timed
@ExceptionMetered
public Response getById(@PathParam("id") Long id) {
return delegate.getById(OptionalLong.of(id));
}

@GET
@RolesAllowed({"admin"})
@Timed
@ExceptionMetered
public Response getErrors(@QueryParam("status") @DefaultValue("UNRESOLVED") String statusParam, @QueryParam("pageNumber") @DefaultValue("1") Integer pageNumber, @QueryParam("pageSize") @DefaultValue("25") Integer pageSize) {
return delegate.getErrors(statusParam, OptionalInt.of(pageNumber), OptionalInt.of(pageSize));
}

@PUT
@Path("/resolve/{id}")
@RolesAllowed({"admin"})
@Timed
@ExceptionMetered
public Response resolve(@PathParam("id") Long id) {
return delegate.resolve(OptionalLong.of(id));
}

@PUT
@Path("/resolve")
@RolesAllowed({"admin"})
@Timed
@ExceptionMetered
public Response resolveAllUnresolved() {
return delegate.resolveAllUnresolved();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.kiwiproject.champagne.util.DeployableSystems.getSystemIdOrNull;

import java.util.Objects;

import lombok.extern.slf4j.Slf4j;
import org.dhatim.dropwizard.jwt.cookie.authentication.CurrentPrincipal;
import org.kiwiproject.champagne.dao.AuditRecordDao;
Expand All @@ -10,13 +12,11 @@
import org.kiwiproject.dropwizard.error.ApplicationErrorThrower;
import org.kiwiproject.dropwizard.error.dao.ApplicationErrorDao;

import java.util.Objects;

@Slf4j
public abstract class AuditableResource {

private final AuditRecordDao auditRecordDao;
private final ApplicationErrorThrower applicationErrorThrower;
protected final ApplicationErrorThrower applicationErrorThrower;

protected AuditableResource(AuditRecordDao auditRecordDao, ApplicationErrorDao applicationErrorDao) {
this.auditRecordDao = auditRecordDao;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package org.kiwiproject.champagne.resource;

import static jakarta.ws.rs.client.Entity.json;
import static org.kiwiproject.test.jaxrs.JaxrsTestHelper.assertOkResponse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.OptionalInt;
import java.util.OptionalLong;

import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
import io.dropwizard.testing.junit5.ResourceExtension;
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.kiwiproject.champagne.junit.jupiter.DeployableSystemExtension;
import org.kiwiproject.champagne.junit.jupiter.JwtExtension;
import org.kiwiproject.dropwizard.error.resource.ApplicationErrorResource;
import org.kiwiproject.dropwizard.util.exception.JerseyViolationExceptionMapper;
import org.kiwiproject.jaxrs.exception.JaxrsExceptionMapper;

@DisplayName("BuildResource")
@ExtendWith({DropwizardExtensionsSupport.class, DeployableSystemExtension.class})
class ApplicationErrorWithAuthResourceTest {

private static final ApplicationErrorResource DELEGATE = mock(ApplicationErrorResource.class);

private static final ApplicationErrorWithAuthResource RESOURCE = new ApplicationErrorWithAuthResource(DELEGATE);

private static final ResourceExtension RESOURCES = ResourceExtension.builder()
.bootstrapLogging(false)
.addResource(RESOURCE)
.addProvider(JerseyViolationExceptionMapper.class)
.addProvider(JaxrsExceptionMapper.class)
.build();

@RegisterExtension
public final JwtExtension jwtExtension = new JwtExtension("bob");

@AfterEach
void cleanup() {
reset(DELEGATE);
}

@Nested
class GetById {

@Test
void delegateToGetById() {
when(DELEGATE.getById(OptionalLong.of(1L))).thenReturn(Response.ok().build());

var response = RESOURCES.client()
.target("/errors/{id}")
.resolveTemplate("id", 1L)
.request()
.get();

assertOkResponse(response);

verify(DELEGATE).getById(OptionalLong.of(1L));
}
}

@Nested
class GetErrors {

@Test
void shouldDelegateToGetErrors() {
when(DELEGATE.getErrors(anyString(), any(OptionalInt.class), any(OptionalInt.class))).thenReturn(Response.ok().build());

var response = RESOURCES.client()
.target("/errors")
.request()
.get();

assertOkResponse(response);

verify(DELEGATE).getErrors(anyString(), any(OptionalInt.class), any(OptionalInt.class));
}
}

@Nested
class Resolve {

@Test
void shouldDelegateToResolve() {
when(DELEGATE.resolve(OptionalLong.of(1L))).thenReturn(Response.ok().build());

var response = RESOURCES.client()
.target("/errors/resolve/{id}")
.resolveTemplate("id", 1L)
.request()
.put(json(""));

assertOkResponse(response);

verify(DELEGATE).resolve(OptionalLong.of(1L));
}
}

@Nested
class ResolveAllUnresolved {

@Test
void shouldDelegateToResolveAllUnresolved() {
when(DELEGATE.resolveAllUnresolved()).thenReturn(Response.ok().build());

var response = RESOURCES.client()
.target("/errors/resolve")
.request()
.put(json(""));

assertOkResponse(response);

verify(DELEGATE).resolveAllUnresolved();
}
}
}
Loading
Loading