惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
D
Docker
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
美团技术团队
V
V2EX
Last Week in AI
Last Week in AI
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
B
Blog RSS Feed
博客园_首页
B
Blog
博客园 - 叶小钗
I
InfoQ
WordPress大学
WordPress大学
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
The Register - Security
The Register - Security
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Latest news
Latest news
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News and Events Feed by Topic
S
Secure Thoughts
The Hacker News
The Hacker News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News

Logstash

请教下这种情况下如何 logstash 处理时间问题? - V2EX 各位大大,日志监控告警系统,大家有什么好的方案推荐么? - V2EX logstash 如何将时间戳 UNIX_MS 转化为北京时间? - V2EX 使用 ELK(Elasticsearch + Logstash + Kibana) 搭建日志集中分析平台实践 - V2EX logstash+elasticsearch+kibana 问题 - V2EX
使用 logstash 消费 avro 数据出现部分字节被替换为 ef bf bd 导致解析出错。 - V2EX
InDom · 2024-05-06 · via Logstash

这是一个创建于 769 天前的主题,其中的信息可能已经有所发展或是发生改变。

消费渠道 kafka 与 redis 均出现相同问题,直接以 plain => { charset => "BINARY" } 依然出现此问题。

avro 数据原文( 16 进制)

00000000: 00 80 40 00 cc e1 85 98 0e 00 3a 32 30 32 34 2d  ..@.......:2024-
00000010: 30 34 2d 31 38 54 30 36 3a 33 32 3a 30 34 2e 30  04-18T06:32:04.0
00000020: 30 30 2b 30 38 3a 30 30                          00+08:00

logstash 获取到的内容

00000000: 00 ef bf bd 40 00 ef bf bd ef bf bd ef bf bd ef  ....@...........
00000010: bf bd 0e 00 3a 32 30 32 34 2d 30 34 2d 31 38 54  ....:2024-04-18T
00000020: 30 36 3a 33 32 3a 30 34 2e 30 30 30 2b 30 38 3a  06:32:04.000+08:
00000030: 30 30 0a                                         00.

logstash 是通过 docker 起的 8.13.0 ,以下是容器相关配置

docker-compose.yml

  logstash:
    image: logstash:8.13.0
    volumes:
      - /root/kafka-2-es/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
    environment:
      - "XPACK_MONITORING_ENABLED=false"
      - "KAFKA_GROUP_ID"

logstash.conf

input {
  kafka {
    bootstrap_servers => "kafka:9092"
    topics => ["urllog-test-01"]
    codec => plain {
      charset => "BINARY"
    }
    group_id => "${KAFKA_GROUP_ID}"
    auto_offset_reset => "earliest"
  }
  redis {
    host => "192.168.4.101"
    port => 6379
    password => "Fle7YuG22qIh7ZNPkceopo3oZb1UFZrX"
    data_type => "list"
    key => "urllog-test-01"
    codec => plain {
      charset => "BINARY"
    }
  }
}

output {
  stdout {
    codec => rubydebug
  }
  elasticsearch {
    hosts => ["https://192.168.1.4:9200"]
    index => "urllog-test-01"
    user => "elastic"
    password => "123456"
    ssl => true
    ssl_certificate_verification => false
    manage_template => true
  }
}

已经确认的是:

  1. 使用 go 从 kafka 中消费获取到的二进制内容是正确的。
  2. 使用 logstash 从 kafka 与 redis 消费相同的内容,均出现特殊字符被替换为 ef bf bd 的情况
  3. 使用 kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic urllog-test-01 --from-beginning >> /tmp/data-1.txt 直接从 kafka 中得到的内容是正确的

有没有大佬知道是这么回事,给指条路呗?万分感谢。

第 1 条附言  ·  2024 年 5 月 7 日

果真是不发帖就找不到答案,官方文档没找到任何有用的线索,搜索关键词也找不到答案,通过遍历所有的 github 上相关的 issue,被发现了一个早前忽视的东西。

https://github.com/revpoint/logstash-codec-avro_schema_registry?tab=readme-ov-file#basic-usage-with-kafka-input-and-output

在这里看到了一个选项: value_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"

一周前就看到了这个库,但没有时间仔细阅读代码段,不然一周前就应该解决这个问题了。

最后贴一下结果,希望下一个“我”可以看到。

input {
  kafka {
    bootstrap_servers => "kafka:9092"
    topics => ["test-01"]
    codec => avro {
      schema_uri => "/app/test.avsc"
      tag_on_failure => true
      encoding => binary
    }
    value_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"
    group_id => "${KAFKA_GROUP_ID}"
    auto_offset_reset => "earliest"
  }
}
output {
  stdout {
    codec => rubydebug
  }
}

我的一周啊,因为这个破事,甚至险些破坏了我的五一假期。

InDom

1

InDom      2024 年 5 月 7 日

另外,贴一个有意思的东西,相同的问题,解决前和解决后。

对,已经指向这个帖子了。