kyucumber
전체 글 보기

ElasticsearchSinkConnector timestamp format - week based year

운영중인 시스템에서 Kafka에서 Elasticsearch로의 데이터 적재를 위해 ElasticsearchSinkConnector를 사용하고 있습니다. Connector의 설정을 통해 인덱스 이름이 월 단위로 롤링되도록 구성해두었는데, 연말에 인덱스 이름이 의도하지 않은 형태로 생성되었습니다.

Elasticsearch나 Connector의 문제가 아닌 DateTimeFormat을 제대로 알지 못하고 있어 발생한 문제였습니다. 관련 내용을 아래에 정리했습니다.

ElasticsearchSinkConnector 설정

connector.class: io.confluent.connect.elasticsearch.ElasticsearchSinkConnector transforms.TimestampRouter.timestamp.format: YYYY-'W'ww transforms.TimestampRouter.topic.format: index-pattern-v1-${timestamp}

문제가 된 인덱스

기준일 2020/12/28

의도한 인덱스 패턴: index-pattern-v1-2020-w53

실제로 생성된 인덱스: index-pattern-v1-2020-w01

아래와 같이 코드 레벨에서 확인한 결과 index-pattern-2020-w01이 출력되었습니다.

DateTimeFormatter.ofPattern("YYYY-MM-'w'ww") requestTimeRange = localDate("2020-12-28") until localDate("2021-01-02") [index-pattern-2020-w01, index-pattern-2021-w01]

코드에서 w01이 나오는 것으로 보아 w01이라는 값은 정상적인 값으로 보입니다.

다만 2021년의 첫주라 index-pattern-2021-w01이 나오길 기대했으나 index-pattern-2020-w01이 나와 문제가 됐습니다.

결론부터 정리하면 아래와 같습니다.

주 단위 기준 년도를 사용하려면 YYYY가 아닌 Y를 사용하면 된다.

Symbol Meaning Presentation Examples ------ ------- ------------ ------- G era text AD; Anno Domini; A u year year 2004; 04 y year-of-era year 2004; 04 D day-of-year number 189 M/L month-of-year number/text 7; 07; Jul; July; J d day-of-month number 10 Q/q quarter-of-year number/text 3; 03; Q3; 3rd quarter Y week-based-year year 1996; 96

변경 후 ElasticsearchSinkConnector 설정

connector.class: io.confluent.connect.elasticsearch.ElasticsearchSinkConnector transforms.TimestampRouter.timestamp.format: Y-'W'ww transforms.TimestampRouter.topic.format: index-pattern-v1-${timestamp}

Table of contents