반응형
상황
DAG에 대한 로그보기를 하려고 했는데
로그크기가 크면 부하가 심함
해결책으로 full_content=false와 token을 이용
String airflowLogUrl = String.format(
dagUrl + "/%s/dagRuns/%s/taskInstances/%s/logs/%d?full_content=false%s",
dagId, dagRunId, taskId, taskTryNumber,
(continuationToken != null ? "&continuation_token=" + continuationToken : "")
);
그래서 로그를 잘라서 가져오는데 성공!
그런데 아래와 같은 오류 발생!
오류
ERROR
com.fasterxml.jackson.core.exc.StreamConstraintsException: String value length (20051112) exceeds the maximum allowed (20000000, from `StreamReadConstraints.getMaxStringLength()`)
아래의 코드에서 Json Parsing중 문자열 길이가 초과해서 발생!
디폴트로 허용이 20,000,000임을 알 수 있음
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> responseBody = objectMapper.readValue(response.getBody(), new TypeReference<>() {});
return ResponseEntity.ok(responseBody);
해결
해결을 하기 위해서 아래와 같이 JacksonConfig를 만들어서 maxStringLength를 늘려줌!
package com.kakao.www.admin.config;
import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JacksonConfig {
@Bean
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.getFactory().setStreamReadConstraints(
StreamReadConstraints.builder()
.maxStringLength(50_000_000)
.build()
);
return objectMapper;
}
}
그러나 위 소스는 사용하지 않았다고 한다..ㅋㅋ 나중엔 stream으로 처리해서 json형태가 아니라 text/plain으로 받았습니다 ㅎㅎ
그래도 Json관련 소중한 경험을 한거 같습니다:)
끝~
반응형
'OpenSource > Spring Boot' 카테고리의 다른 글
Spring Boot GraphQL Client (0) | 2024.07.03 |
---|---|
이론만 공부했던 패턴을 적용해보자:) (0) | 2024.05.22 |
json to dto or json to values (0) | 2024.05.13 |
springboot-RestClient?? (0) | 2024.04.07 |
springboot - RestTemplate 적용 (0) | 2024.04.07 |