Envoy๋กœ ๋“ค์–ด์˜ค๊ณ  ๋‚˜๊ฐ€๋Š” ํŠธ๋ž˜ํ”ฝ์„ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•˜๋Š” ๋ฐฉ๋ฒ•.

4 minute read

์‚ฌ์ „ ์ค€๋น„

k apply -f https://raw.githubusercontent.com/istio/istio/master/samples/helloworld/helloworld.yaml

Enable Access Logging

Telemetry API

apiVersion: telemetry.istio.io/v1alpha1
kind: Telemetry
metadata:
  name: default-ns-logging
  namespace: default
spec:
  accessLogging:
    - providers:
      - name: envoy
$ k exec -it ... -- sh
~ $ curl http://helloworld.default.svc.cluster.local:5000/hello
---
$ k exec -it helloworld... -c istio-proxy -- sh
...
[2024-03-18T23:08:48.020Z] "GET /hello HTTP/1.1" 200 - via_upstream - "-" 0 59 52 51 "-" "curl/8.6.0" "a0698764-a04d-48c8-8914-045808d19898" "helloworld.default.svc.cluster.local:5000" "10.42.0.4:5000" inbound|5000|| 127.0.0.6:60873 10.42.0.4:5000 10.42.0.6:48352 outbound_.5000_._.helloworld.default.svc.cluster.local default
...
[2024-03-18T23:10:51.528Z] "GET /hello HTTP/1.1" 200 - via_upstream - "-" 0 59 38 37 "-" "curl/7.88.1" "5c3abfa9-c806-490b-a5ec-a6659f866490" "helloworld.default.svc.cluster.local:5000" "10.42.0.5:5000" outbound|5000||helloworld.default.svc.cluster.local 10.42.0.4:55914 10.43.135.30:5000 10.42.0.4:41438 - default
...

ํŠน์ • ๋„ค์ž„์ŠคํŽ˜์ด์Šค ๋˜๋Š” Workload์— ๋Œ€ํ•ด์„œ๋งŒ Access Log๋ฅผ ์‚ดํŽด๋ด์•ผ ํ•œ๋‹ค๋ฉด ์š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

Mesh Config

spec:
  meshConfig:
    accessLogFile: /dev/stdout

๋˜๋Š”

$ istioctl install --set meshConfig.accessLogFile=/dev/stdout

๋‘˜๋‹ค ์จ๋ณด๊ธฐ

์ผ๋‹จ Telemetry API ๋ฐฉ์‹๊ณผ Mesh Config ๋ฐฉ์‹ ๋‘˜๋‹ค ๋…๋ฆฝ์ ์ด๋‹ค! ์ฒ˜์Œ์—” ๋‘˜๋‹ค ์„ธํŒ…์„ ํ•ด์•ผ ๋กœ๊น…์ด ๋˜๋Š” ์ค„ ์•Œ์•˜๋Š”๋ฐ, ๊ทธ๊ฒŒ ์•„๋‹ˆ๋ผ ๋‘˜ ์ค‘ ์–ด๋–ค ๋ฐฉ๋ฒ•์„ ์จ๋„ Envoy Logging์ด ๋œ๋‹ค!

๋‹ค๋งŒ, ์ฐจ์ด์ ์€ Telemetry API๋Š” ๋„ค์ž„์ŠคํŽ˜์ด์Šค์™€ ์›Œํฌ๋กœ๋“œ Selector๋ฅผ ํ†ตํ•ด ๋กœ๊น… ๋Œ€์ƒ์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ์–ด์„œ ์ข€๋” ์„ธ๋ฐ€ํ•œ(fine-grained) ๋กœ๊ทธ ์ œ์–ด๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

Access Log Format

Access Log๊ฐ€ ์–ด๋–ค ์ •๋ณด๋“ค์„ ๋ณด์—ฌ์ฃผ๋Š”์ง€ ์ข€๋” ์‚ดํŽด๋ณด์ž.

ํŠธ๋ž˜ํ”ฝ์˜ ๋ฐฉํ–ฅ ๊ตฌ๋ถ„ ๊ฐ€๋Šฅ

Access Log๋Š” inbound, outbound ํŠธ๋ž˜ํ”ฝ์˜ ํ๋ฆ„์„ ๊ธฐ๋กํ•œ๋‹ค.

  • inbound
    • ์›Œํฌ๋กœ๋“œ๋กœ ๋“ค์–ด์˜ค๋Š” ํŠธ๋ž˜ํ”ฝ
  • outbound
    • ์›Œํฌ๋กœ๋“œ์—์„œ ๋‚˜๊ฐ€๋Š” ํŠธ๋ž˜ํ”ฝ

upstream, downstream ์ •๋ณด ํ™•์ธ ๊ฐ€๋Šฅ

upstream, downstream ์š”๊ฒƒ๋“ค์€ envoy์˜ ์šฉ์–ด๋‹ค.

๋จผ์ € โ€œupstreamโ€์€ Envoy sidecar๊ฐ€ ๋ฐ›์€ ์š”์ฒญ์„ forward ๋ฐ›๋Š” ํ˜ธ์ŠคํŠธ๋ฅผ ๋งํ•œ๋‹ค. ๊ธฐ์กด ์›Œํฌ๋กœ๋“œ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ upstream ์—ญํ• ์„ ํ•œ๋‹ค.

โ€œdownstreamโ€์€ Envoy sidecar์— ์š”์ฒญ์„ ๋ณด๋‚ด๊ณ , ์‘๋‹ต์„ ๋ฐ›๋Š” ํ˜ธ์ŠคํŠธ๋ฅผ ๋งํ•œ๋‹ค.

  • upstream
    • host
      • ex: 10.42.0.4:5000
    • cluster
      • ex: inbound|5000||, outbound|5000||helloworld.default.svc.cluster.local
      • ํ˜•์‹์€ {direction}|{port}|{subset}|{hostname}
      • โ€œclusterโ€๊ฐ€ Envoy์—์„œ๋Š” โ€œํŠธ๋ž˜ํ”ฝ์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ๋Œ€์ƒ ์›Œํฌ๋กœ๋“œ์˜ ์ง‘ํ•ฉโ€์„ ๋งํ•˜๋Š”๋ฐ, ํ์Œ Istio Envoy Log์—์„œ๋Š” ๋™์ผํ•œ ์˜๋ฏธ๋กœ ์“ฐ์˜€๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค ๐Ÿค”
    • local address
      • ex: 127.0.0.6:60873
  • downstream
    • local address
      • ex: 10.42.0.4:5000
    • remote address
      • ex: 10.42.0.6:48352

Request ๊ธฐ๋ณธ ์ •๋ณด ํ™•์ธ ๊ฐ€๋Šฅ

  • Method & Path
    • ex: GET /hello HTTP/1.1
  • X-ENVOY-UPSTREAM-SERVICE-TIME
    • ์š”์ฒญ์ด Envoy์— ๋„์ฐฉํ•œ ํ›„ ์—…์ŠคํŠธ๋ฆผ ์„œ๋น„์Šค์— ์˜ํ•ด ์ฒ˜๋ฆฌ๊ฐ€ ์™„๋ฃŒ ๋˜๊ณ  Envoy๋กœ ๋Œ์•„์˜ฌ ๋•Œ๊นŒ์ง€ ๊ฑธ๋ฆฐ ์ „์ฒด ์‹œ๊ฐ„ (๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„)
  • X-FORWARDED-FOR (XFF ํ—ค๋”)
    • ์š”์ฒญ์ด proxy ์„œ๋ฒ„๋‚˜ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ์™€ ๊ฐ™์€ ์ค‘๊ฐ„ ์„œ๋ฒ„๋ฅผ ํ†ต๊ณผํ•  ๋•Œ, ์›๋ž˜ ํด๋ผ์ด์–ธํŠธ์˜ IP ์ฃผ์†Œ๋ฅผ ๋ณด์กดํ•˜๋Š”๋ฐ ์‚ฌ์šฉ
  • User Agent
    • ex: curl/8.6.0
  • X-REQUEST-ID
    • ex: a0698764-a04d-48c8-8914-045808d19898
    • ๊ฐœ๋ฒŒ HTTP ์š”์ฒญ์„ ์‹๋ณ„ํ•˜๊ณ , ๊ทธ๊ฒƒ๋“ค์„ ์ถ”์ (tracing) ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ํ—ค๋”
  • Authority
    • ex: helloworld.default.svc.cluster.local:5000
    • ์š”์ฒญ์ด ์ „์†ก๋˜๋Š”, ์š”์ฒญ์ด ํƒ€๊นƒ์œผ๋กœ ํ•˜๋Š” ํ˜ธ์ŠคํŠธ ์ด๋ฆ„๊ณผ ํฌํŠธ ๋ฒˆํ˜ธ๊ฐ€ ๋‹ด๊ธด ํ—ค๋”.
    • HTTP/1.x์˜ Host ํ—ค๋”์™€ ์œ ์‚ฌํ•œ ์—ญํ• .
    • ์„œ๋ฒ„ ๋˜๋Š” ํ”„๋ก์‹œ๊ฐ€ ์—ฌ๋Ÿฌ ๋„๋ฉ”์ธ์„ ์„œ๋น„์Šค ํ•˜๋Š” ๊ฒฝ์šฐ, ์˜ˆ๋ฅผ ๋“ค์–ด example.com๊ณผ another.com์ด IP ์ฃผ์†Œ๋ฅผ ๊ณต์œ ํ•˜๋Š” ๊ฒฝ์šฐ, ์š”์ฒญ์ด ์–ด๋–ค ๋„๋ฉ”์ธ์„ ๋Œ€์ƒ์œผ๋กœ ํ•˜๋Š”์ง€ ๊ตฌ๋ถ„ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.

Response ์ •๋ณด ํ™•์ธ ๊ฐ€๋Šฅ

  • Response Code
    • ex: 200
  • Response Code Details
    • Response Code๊ฐ€ ์ƒ์„ฑ๋œ ๊ตฌ์ฒด์ ์ธ ์ด์œ ๋‚˜ ์กฐ๊ฑด์„ ์„ค๋ช…. ๋””๋ฒ„๊น… ์šฉ๋„.
  • Response Flag
    • ex: via_upstream
      • ์š”๊ฑด โ€œThe response code was set by the upstreamโ€๋ผ๋Š” ์˜๋ฏธ.
    • ์š”์ฒญ์ด ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌ๋˜์—ˆ๋Š”์ง€ ํ‘œ์‹œ.
    • Envoy ๋ฌธ์„œ์—์„œ ์ „์ฒด ๋ชฉ๋ก ํ™•์ธ ๊ฐ€๋Šฅ.

Header์™€ Body ์ •๋ณด๋Š” ํ™•์ธ ๋ถˆ๊ฐ€

Envoy Access Log๋Š” Header์™€ Body ์ •๋ณด๋Š” ๋ณด์—ฌ์ฃผ์ง€ ์•Š๋Š”๋‹ค.

curl http://helloworld.default.svc.cluster.local:5000/hello --header "haha: hoho"

์š”๋ ‡๊ฒŒ ์š”์ฒญ์„ ๋ณด๋‚ด๋„, header ์ •๋ณด๋Š” ํ™•์ธ ๋ถˆ๊ฐ€๋Šฅ!

๋‹จ, ๋ช‡๋ช‡ ํ—ค๋”(X-FORWARDED-FOR, X-REQUEST-ID, AUTHORITY)๋Š” Access Log์— ํ‘œ์‹œ๋œ๋‹ค.

์ฐธ๊ณ ์ž๋ฃŒ