首页 > 其他分享 >折腾 Quickwit,Rust 编写的分布式搜索引擎 - 可观测性之日志管理

折腾 Quickwit,Rust 编写的分布式搜索引擎 - 可观测性之日志管理

时间:2024-09-02 12:53:31浏览次数:5  
标签:otel logs quickwit Quickwit https 日志 Rust

折腾 Quickwit,Rust 编写的分布式搜索引擎 - 可观测性之日志管理_AWS

Quickwit 从底层构建,旨在 高效地索引非结构化数据,并在云存储上轻松搜索这些数据。
此外,Quickwit 开箱即支持 OpenTelemetry gRPC 和 HTTP(仅 protobuf)协议,并提供了一个 REST API,可以接收任何 JSON 格式的日志。
这让 Quickwit 成为了日志的理想选择!.

折腾 Quickwit,Rust 编写的分布式搜索引擎 - 可观测性之日志管理_github_02

使用 OTEL Collector 发送日志

如果您已经有了自己的 OpenTelemetry Collector 并希望将日志导出到 Quickwit,您需要在 config.yaml 中配置一个新的 OLTP gRPC exporter:

macOS/Windows

receivers:
  otlp:
    protocols:
      grpc:
      http:

processors:
  batch:

exporters:
  otlp/quickwit:
    endpoint: host.docker.internal:7281
    tls:
      insecure: true  
    # By default, logs are sent to the otel-logs-v0_7.
    # You can customize the index ID By setting this header.
    # headers:
    #   qw-otel-logs-index: otel-logs-v0_7
service:
  pipelines:
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/quickwit]

Linux

receivers:
  otlp:
    protocols:
      grpc:
      http:

processors:
  batch:

exporters:
  otlp/quickwit:
    endpoint: 127.0.0.1:7281
    tls:
      insecure: true
    # By default, logs are sent to the otel-logs-v0_7.
    # You can customize the index ID By setting this header.
    # headers:
    #   qw-otel-logs-index: otel-logs-v0_7

service:
  pipelines:
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/quickwit]

测试您的 OTEL 配置

  1. 安装 并启动一个 Quickwit server:
./quickwit run
  1. 使用之前的配置启动一个 collector:

macOS/Windows

docker run -v ${PWD}/otel-collector-config.yaml:/etc/otelcol/config.yaml -p 4317:4317 -p 4318:4318 -p 7281:7281 otel/opentelemetry-collector

Linux

docker run -v ${PWD}/otel-collector-config.yaml:/etc/otelcol/config.yaml --network=host -p 4317:4317 -p 4318:4318 -p 7281:7281 otel/opentelemetry-collector
  1. 使用 cURL 向您的 collector 发送一条日志:
curl -XPOST "http://localhost:4318/v1/logs" -H "Content-Type: application/json" \
--data-binary @- << EOF
{
 "resource_logs": [
   {
     "resource": {
       "attributes": [
         {
           "key": "service.name",
           "value": {
             "stringValue": "test-with-curl"
           }
         }
       ]
     },
     "scope_logs": [
       {
         "scope": {
           "name": "manual-test"
         },
         "log_records": [
           {
             "time_unix_nano": "1678974011000000000",
             "observed_time_unix_nano": "1678974011000000000",
             "name": "test",
             "severity_text": "INFO"
           }
         ]
       }
     ]
   }
 ]
}
EOF

您应该会在 Quickwit 服务器上看到类似以下的日志:

2023-03-16T13:44:09.369Z  INFO quickwit_indexing::actors::indexer: new-split split_id="01GVNAKT5TQW0T2QGA245XCMTJ" partition_id=6444214793425557444

这意味着 Quickwit 已经收到了日志并创建了一个新的分片。在搜索日志之前,请等待分片被发布。

通过 OTEL 发送 K8s 日志

本指南将帮助您解锁 Kubernetes 集群日志上的日志搜索功能。我们首先使用 Helm 部署 Quickwit 和 OTEL 收集器,然后了解如何索引和搜索这些日志。

前提条件

完成本教程,您需要以下工具:

  • 一个 Kubernetes 集群。
  • 命令行工具 kubectl
  • 命令行工具 Helm
  • 对象存储(如 AWS S3、GCS、Azure Blob 存储或 Scaleway)的访问权限,用于存储索引数据。

使用 Helm 安装

首先,让我们创建一个命名空间来隔离我们的实验,并将其设置为默认命名空间。

kubectl create namespace qw-tutorial
kubectl config set-context --current --namespace=qw-tutorial

然后添加 QuickwitOtel Helm 仓库:

helm repo add quickwit https://helm.quickwit.io
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts

现在您应该能在 Helm 中看到这两个仓库:

helm repo list
NAME                	URL
quickwit            	https://helm.quickwit.io
open-telemetry      	https://open-telemetry.github.io/opentelemetry-helm-charts

部署 Quickwit

让我们创建一个基本的 chart 配置:

export AWS_REGION=us-east-1
export AWS_ACCESS_KEY_ID=XXXX
export AWS_SECRET_ACCESS_KEY=XXXX
export DEFAULT_INDEX_ROOT_URI=s3://your-bucket/indexes
# Create Quickwit config file.
echo "
searcher:
  replicaCount: 1
indexer:
  replicaCount: 1
metastore:
  replicaCount: 1
janitor:
  enabled: true
control_plane:
  enabled: true

environment:
  # Remove ANSI colors.
  NO_COLOR: 1

# Quickwit configuration
config:
  storage:
    s3:
      region: ${AWS_REGION}
      access_key_id: ${AWS_ACCESS_KEY_ID}
      secret_access_key: ${AWS_SECRET_ACCESS_KEY}
      # If you are not on AWS S3, you can define a flavor (gcs, minio, garage...)
      # and additional variables for your object storage.
      # flavor: gcs
      # endpoint: https://storage.googleapis.com

  # Metastore on S3.
  metastore_uri: ${DEFAULT_INDEX_ROOT_URI}

  default_index_root_uri: ${DEFAULT_INDEX_ROOT_URI}

  # Indexer settings
  indexer:
    # By activating the OTEL service, Quickwit will be able
    # to receive gRPC requests from OTEL collectors.
    enable_otlp_endpoint: true
" > qw-tutorial-values.yaml

在安装 Quickwit chart 之前,请确保您能访问 S3 并且 default_index_root_uri 中没有拼写错误。这可以通过 aws CLI 使用简单的 ls 命令轻松完成:

aws s3 ls ${DEFAULT_INDEX_ROOT_URI}

如果 CLI 没有返回错误,那么您就可以安装 chart 了:

helm install quickwit quickwit/quickwit -f qw-tutorial-values.yaml

过一会儿,您会看到正在运行 Quickwit 服务的 pod:

kubectl get pods
NAME                                      READY   STATUS    RESTARTS      AGE
quickwit-control-plane-7fc495f4c4-slqv4   1/1     Running   2 (84s ago)   87s
quickwit-indexer-0                        1/1     Running   2 (84s ago)   87s
quickwit-janitor-7f75f4bc8-jrfv6          1/1     Running   2 (84s ago)   87s
quickwit-metastore-6989978fc-9s82j        1/1     Running   2 (85s ago)   87s
quickwit-searcher-0                       1/1     Running   2 (84s ago)   87s

让我们检查 Quickwit 是否正常工作:

kubectl port-forward svc/quickwit-searcher 7280

然后在浏览器中打开 http://localhost:7280/ui/indexes。您应该能看到索引列表。如果一切正常,请继续运行 kubectl 命令,并打开一个新的终端。

部署 OTEL 收集器

我们需要对收集器进行一些配置,以便:

  • 从 Kubernetes 收集日志
  • 用 Kubernetes 属性丰富日志
  • 将日志导出到 Quickwit 索引器。
echo "
mode: daemonset
presets:
  logsCollection:
    enabled: true
  kubernetesAttributes:
    enabled: true
config:
  exporters:
    otlp:
      endpoint: quickwit-indexer.qw-tutorial.svc.cluster.local:7281
      tls:
        insecure: true
      # By default, logs are sent to the otel-logs-v0_7.
      # You can customize the index ID By setting this header.
      # headers:
      #   qw-otel-logs-index: otel-logs-v0_7
  service:
    pipelines:
      logs:
        exporters:
          - otlp
" > otel-values.yaml
helm install otel-collector open-telemetry/opentelemetry-collector -f otel-values.yaml

几秒钟后,您应该会在索引器上看到显示索引已开始的日志。看起来像这样:

2022-11-30T18:27:37.628Z  INFO spawn_merge_pipeline{index=otel-log-v0 gen=0}: quickwit_indexing::actors::merge_pipeline: Spawning merge pipeline. index_id=otel-log-v0 source_id=_ingest-api-source pipeline_ord=0 root_dir=/quickwit/qwdata/indexing/otel-log-v0/_ingest-api-source merge_policy=StableLogMergePolicy { config: StableLogMergePolicyConfig { min_level_num_docs: 100000, merge_factor: 10, max_merge_factor: 12, maturation_period: 172800s }, split_num_docs_target: 10000000 }
2022-11-30T18:27:37.628Z  INFO quickwit_serve::grpc: Starting gRPC server. enabled_grpc_services={"otlp-log", "otlp-trace"} grpc_listen_addr=0.0.0.0:7281
2022-11-30T18:27:37.628Z  INFO quickwit_serve::rest: Starting REST server. rest_listen_addr=0.0.0.0:7280
2022-11-30T18:27:37.628Z  INFO quickwit_serve::rest: Searcher ready to accept requests at http://0.0.0.0:7280/
2022-11-30T18:27:42.654Z  INFO quickwit_indexing::actors::indexer: new-split split_id="01GK4WPTXK8GH3AGTRNBN9A8YG" partition_id=0
2022-11-30T18:27:52.643Z  INFO quickwit_indexing::actors::indexer: send-to-index-serializer commit_trigger=Timeout split_ids=01GK4WPTXK8GH3AGTRNBN9A8YG num_docs=22
2022-11-30T18:27:52.652Z  INFO index_batch{index_id=otel-log-v0 source_id=_ingest-api-source pipeline_ord=0}:packager: quickwit_indexing::actors::packager: start-packaging-splits split_ids=["01GK4WPTXK8GH3AGTRNBN9A8YG"]
2022-11-30T18:27:52.652Z  INFO index_batch{index_id=otel-log-v0 source_id=_ingest-api-source pipeline_ord=0}:packager: quickwit_indexing::actors::packager: create-packaged-split split_id="01GK4WPTXK8GH3AGTRNBN9A8YG"
2022-11-30T18:27:52.653Z  INFO index_batch{index_id=otel-log-v0 source_id=_ingest-api-source pipeline_ord=0}:uploader: quickwit_indexing::actors::uploader: start-stage-and-store-splits split_ids=["01GK4WPTXK8GH3AGTRNBN9A8YG"]
2022-11-30T18:27:52.733Z  INFO index_batch{index_id=otel-log-v0 source_id=_ingest-api-source pipeline_ord=0}:uploader:stage_and_upload{split=01GK4WPTXK8GH3AGTRNBN9A8YG}:store_split: quickwit_indexing::split_store::indexing_split_store: store-split-remote-success split_size_in_megabytes=0.018351 num_docs=22 elapsed_secs=0.07654519 throughput_mb_s=0.23974074 is_mature=false

如果您在此处看到一些错误,可能是由于对象存储配置错误导致的。如果您需要帮助,请在 GitHub 上提交问题或加入我们的 Discord 服务器

准备好搜索日志

现在您可以开始搜索了,等待 30 秒,您将看到第一批索引的日志:只需 打开 UI 并开始使用。有趣的是,您会在这个 UI 中看到 Quickwit 的日志

标签:otel,logs,quickwit,Quickwit,https,日志,Rust
From: https://blog.51cto.com/u_15168528/11896871

相关文章

  • 折腾 Quickwit,Rust 编写的分布式搜索引擎 - 可观测性之分布式追踪
    概述分布式追踪是一种跟踪应用程序请求流经不同服务(如前端、后端、数据库等)的过程。它是一个强大的工具,可以帮助您了解应用程序的工作原理并调试性能问题。Quickwit是一个用于索引和搜索非结构化数据的云原生引擎,这使其非常适合用作追踪数据的后端。此外,Quickwit本地支持OpenTel......
  • MySQL日志
    MySQL基础日志日志分类在任何一种数据库中,都会有各种各样的日志,记录着数据库工作的方方面面,以帮助数据库管理员追踪数据库曾经发生过的各种事件。MySQL有多种类型的日志,用于记录数据库的操作和状态。以下是一些常见的MySQL日志:1、错误日志(ErrorLog):记录MySQL服务器在启动、运行过......
  • 又一个Rust练手项目-wssh(SSH over Websocket Client)
    原文地址https://blog.fanscore.cn/a/61/1.wssh1.1开发背景公司内部的发布系统提供一个连接到k8spod的web终端,可以在网页中连接到k8spod内。实现原理大概为通过websocket协议代理了k8spodssh,然后在前端通过xterm.js+websocket实现了web终端的效果。但是每次需要进pod内......
  • 【学习】VirusTotal威胁研究发布详细指南
    https://mp.weixin.qq.com/s/psge60vK8t3gYj1PatDLvw......
  • MyBatis如何自定义项目中SQL日志
    说明:用过MyBatis框架的同学们都知道,打印SQL日志,可以通过在application.yml配置文件中加入下面配置来设置:mybatis:configuration:log-impl:org.apache.ibatis.logging.stdout.StdOutImpl但打印出来的SQL如下,丑陋不堪,不够优雅本文介绍如何自定义SQL日志拦截器......
  • Java日志框架:Log4j2与SLF4J的比较与选择
    Java日志框架:Log4j2与SLF4J的比较与选择大家好,我是微赚淘客返利系统3.0的小编,是个冬天不穿秋裤,天冷也要风度的程序猿!日志记录是Java应用程序中一个重要的功能,它帮助开发者监控应用的运行状态和调试问题。Log4j2和SLF4J是Java中两个广泛使用的日志框架,它们各有特点和优势。本文将......
  • nginx日志分析工具goaccess
    nginx日志分析工具goaccess wgethttp://tar.goaccess.io/goaccess-1.2.tar.gztarxfgoaccess-1.2.tar.gzcdgoaccess-1.2/./configure--enable-utf8--enable-geoip=legacymakemakeinstall报错:  ......
  • 【运维系列】如何为日志开放安全策略
    网络中日志流量的典型组网如【图1】所示。通常,路由器、交换机、服务器等设备向日志主机发送Syslog日志信息使用UDP514端口。如果日志流经防火墙,需要在防火墙上开放安全策略。【图1】日志输出典型组网防火墙支持输出多种类型的日志。在输出日志信息到日志服务器时,部分日志......
  • 机械学习—零基础学习日志(概率论总笔记1)
    概率论的起源在历史上有明确记载的最早研究随机性的数学家是帕斯卡和费马。帕斯卡就是最早发明机械计算机的那位数学家,他并不是赌徒,但是他有些赌徒朋友,那些人常常玩一种掷骰子游戏,游戏规则是由玩家连续掷4次骰子,如果其中没有6点出现,玩家赢,如果出现一次6点,则庄家赢。在这个赌......
  • 机械学习—零基础学习日志(如何理解概率论12)
    假设检验假设检验是有一些参数,已知条件,让你检验某种假设是否成立。我们通过具体的题目来说明:这里我们需要确认使用什么公式:使用下面的公式如下图:题目中,以21作为分界线,所以我们将是21与不是21两种对应的数值进行计算。具体计算使用到图中的公式。算出对应的数值,然后比......