본문 바로가기

인프라,데이터/Elasticsearch, Logstash, Kibana

Logstash는 로그를 왜 message라는 field로 저장할까?

왜지? 왜일까

요새 Fluent Bit를 써서 EKS 안의 애플리케이션 로그를 수집하고 Kinesis firehose를 버퍼로 사용한 후, 이를 Logstash에서 수집한 후 ES로 보내 Kibana에서 분석하는 환경을 구성 중이다.

"log"=>"* 2022-02-16 12:38:44,245 [Timer-0] INFO  |c.e.demo.SpringBootLoggerApplication: 12:38:44 ::: Hello World ::: 1"}

그 중에서 Fluent Bit는 로그 파일을 "log"라는 key에 저장해서, 기존 Logstash 설정을 사용하기 위해서는 "log" 를 "message"로 바꿔주어야 했다.

{ "message" => "Hello Logstash!" }

그럼 애초에 왜 Logstash는 "message"라는 field(Fluent Bit의 key)에 로그를 저장하나 궁금해서 찾아보니, 여러 글들이 있었다.

 

먼저 elastic.co의 블로그 글 A Practical Introduction to Logstash 을 보면,

“Hello Logstash!” 라는 텍스트가 들어간 파일을 로그스태시에서 읽어오는 예시를 보인다. 
{
 "message" => "Hello Logstash!",
 "@version" => "1",
 "path" => "/home/logstash/testdata.log",
 "@timestamp" => 2018-04-24T12:40:09.105Z,
 "host" => "localhost"
}
그러면 로그스태시는 이벤트를 이렇게 처리한다.
"Hello Logstash!" 라는 로그 텍스트가 message 필드에 저장되는 것을 볼 수 있다.
( 왜 message field에 저장되는지 이유는 나오지 않는다. )
 

다음으로, Logstash Docs의 Accessing event data and fields in the configuration 문서의 metadata field 부분을 보면,

"STDIN input에서 넣은 데이터가 무엇이든간에 message 필드로 저장된다"
(This configuration file yields events from STDIN. Whatever you type becomes the message field in the event.") 라는 말만 나오고 역시 왜 하필 그 field의 이름이 message인지는 알려주지 않는다.

ㅎㅎ...

더 찾아보니, 2015년 discuss.elastic.co 에 어떤 사람이
"Logstash에서 message field의 목적은 뭐냐? message란게 이름 지정 규칙 혹은 표준이냐?" 라고 질문한 에,

로그스태시 플러그인 maintainer가 단 답변이 있다.

The message field is like a default field. It's where most input plugins place the payload that they receive from the network, read from a file, or whatever. So no, it's not just a convention.
In many log formats the message field starts with a timestamp, maybe a severity level, possibly a hostname, and so on, and ends with the actual message. In such cases one typically extract the timestamp etc into fields of their own and remove them from the message field. In other cases like HTTP logs there is no free-text message.
message 필드는 디폴트 필드같은 거라고, 규칙같은 건 아니라며
message 필드에서 timestamp, level, hostname ... 같은 정보를 추출할 수 있다 라는 말을 한다.

찾아보며 느낀 바로는, "애초에 Logstash를 만든 사람들이 input플러그인에서 들어오는 텍스트를 message란 field에 담는다" 라고 지정해서 그런 것 같다.
그게 표준 아닌가? 싶지만... ㅎㅎ
결론은, Logstash는 log를 "message" 라는 field에 담고,
Fluent Bit 는 log를 "log"라는 key에 담는다는 것이다.