Skip to content

Commit

Permalink
add configuration property to disable getTaskTypes endpoint (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieltaets-tw authored Apr 18, 2024
1 parent 279b911 commit 9d3af41
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

#### 1.41.6 - 2024/04/17
### Added
- `/getTaskTypes` endpoint may be disabled through configuration property `tw-tasks.core.tasks-management.enable-get-task-types: false`. Services with extreme amount of tasks might benefit from this.

#### 1.41.5 - 2024/04/05
### Changed
* Use static methods to create BeanPostProcessors.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=1.41.5
version=1.41.6
org.gradle.internal.http.socketTimeout=120000
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.transferwise.tasks.BaseIntTest;
import com.transferwise.tasks.ITaskDataSerializer;
import com.transferwise.tasks.TaskTestBuilder;
import com.transferwise.tasks.TasksProperties;
import com.transferwise.tasks.dao.ITaskDao;
import com.transferwise.tasks.domain.FullTaskRecord;
import com.transferwise.tasks.domain.TaskStatus;
Expand Down Expand Up @@ -45,6 +46,8 @@ public class TasksManagementPortIntTest extends BaseIntTest {
private ITaskDao taskDao;
@Autowired
private ITaskDataSerializer taskDataSerializer;
@Autowired
private TasksProperties tasksProperties;

@Test
void erroneousTasksWillBeCorrectlyFound() {
Expand Down Expand Up @@ -566,6 +569,18 @@ void getTaskTypesWillReturnFiltered() {
assertTrue(types.get(1).getSubTypes().isEmpty());
}

@Test
void getTaskTypesFailsIfEndpointIsDisabled() {
tasksProperties.getTasksManagement().setEnableGetTaskTypes(false);
ResponseEntity<GetTaskTypesResponse> response = goodEngineerTemplate().getForEntity(
"/v1/twTasks/getTaskTypes?status=ERROR,PROCESSING",
GetTaskTypesResponse.class
);

assertEquals(410, response.getStatusCodeValue());
tasksProperties.getTasksManagement().setEnableGetTaskTypes(true);
}

private TestRestTemplate goodEngineerTemplate() {
return testRestTemplate.withBasicAuth("goodEngineer", "q1w2e3r4");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ public static class TasksManagement {
@jakarta.validation.Valid
private List<TypeSpecificTaskManagement> typeSpecific = Collections.emptyList();

/**
* Services with lots of tasks might cause the endpoint to timeout, service owners may disable it to avoid high db load.
**/
private boolean enableGetTaskTypes = true;

@Data
public static class TypeSpecificTaskManagement {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ public ResponseEntity<GetTasksStuckResponse> getTasksStuck(@RequestBody(required

@Override
public ResponseEntity<GetTaskTypesResponse> getTaskTypes(@RequestParam(name = "status", required = false) List<String> status) {
if (!tasksProperties.getTasksManagement().isEnableGetTaskTypes()) {
return ResponseEntity.status(HttpStatus.GONE).build();
}
return callWithAuthentication(() -> {
ITasksManagementService.GetTaskTypesResponse serviceResponse = tasksManagementService.getTaskTypes(status);

Expand Down

0 comments on commit 9d3af41

Please sign in to comment.