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 configuration property to disable getTaskTypes endpoint #198

Merged
merged 1 commit into from
Apr 18, 2024
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
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
Loading