[Grafana] Opentelemetry: spanmetric ๊ตฌ์ฑํ๊ธฐ
์ด์ ํฌ์คํธ
https://blog.naver.com/sssang97/223764113482
https://blog.naver.com/sssang97/223761188760
๋จ์ํ API์ ๋ํ ๊ธฐ๋ก์ ๋ณด๊ณ ์ถ๋ค๋ฉด Tempo ๋ฑ์ ์ฌ์ฉํด์ trace๋ฅผ ๊ธฐ๋กํ๋ฉด ๋๋ค.
๊ทธ๋ฌ๋ฉด API๋ค์ด ์ผ๋ง๋ ํธ์ถ๋์๋์ง, ์ค๋ฅ์จ์ด ์ผ๋ง์ธ์ง ๊ฐ์ ํต๊ณ์ฑ ๋ฐ์ดํฐ๋ฅผ ๋ณด๊ณ ์ถ๋ค๋ฉด ์ด๋ป๊ฒ ํด์ผํ ๊น?
๊ทธ๋ฐ๊ฑธ ์ํ ๊ธฐ๋ฅ์์ ์ค ํ๋๊ฐ ๋ฐ๋ก spanmetric์ด๋ค. ๊ฐ๊ฐ์ span์ ๊ธฐ๋ฐ์ผ๋ก metric์ ๊ตฌ์ฑํ๋ค๋ ์๋ฏธ๋ค.
๋ณธ ํฌ์คํธ์์๋ otel-collector๋ฅผ ๊ธฐ๋ฐ์ผ๋ก prometheus์ ํต๊ณ๋ฅผ ์ค์ ๋ฃ๊ณ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๊ฐ๋จํ ๋ค๋ค๋ณด๊ฒ ๋ค.
otel-collector ์ค์
spanmetric์ ์ค์ ๋ก span-trace ๋ฐ์ดํฐ๋ฅผ ๊ธฐ์ค์ผ๋ก ์์ฑ๋๋ ๋ฉํธ๋ฆญ ๋ฐ์ดํฐ๋ค.
connectos ์ต์ ์ ํตํด์ ๋ฐ์ดํฐ๋ฅผ ์ด๋ป๊ฒ ๋๊ฒจ๋ฐ์ ์ง๋ฅผ ์ ์ํ ์ ์๋ค.
connectors:
spanmetrics:
namespace: http_server_request
dimensions:
- name: http.method
- name: http.status_code
- name: http.route
- name: service.namespace
histogram:
unit: s
exemplars:
enabled: true
events:
enabled: true
dimensions:
- name: exception.type
- name: exception.message
http_server_request๋ผ๋ ์ ๋์ด๋ก metric์ด ์์ด๊ฒ ํ๊ณ , http.method๋ฅผ ๋น๋กฏํ span์ ๋ฐ์ดํฐ๋ค์ ๊ณ์น๋ฐ์์ ์ ์ฅํ๋๋ก ํ๋ค.
๊ทธ๋ฆฌ๊ณ ๊ธฐ๋ก ๋จ์๋ ์ด ๋จ์๋ค. ๊ธฐ๋ณธ๊ฐ์ ๋ฐ๋ฆฌ์ด๋จ์์ธ๋ฐ, ๋ ๊ทธ์ ๋๋ ํ์์์ด์ ์ด๋ ๊ฒ ํ๋ค.
์ด ๋ถ๋ถ์ด ํนํ grafana ๋์๋ณด๋ ํ๊ฒฝ์์ ํนํ ๊ฐ๋ก๊ฐ์ด ๋์ด์๋ ๋ถ๋ถ ์ค ํ๋๋ค.
๋ณดํต์ ๋์๋ณด๋ ํ
ํ๋ฆฟ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ฐ์ ธ๋ค๊ฐ ํธํ๊ฒ ์ฐ๋ ๊ฒ์ ์ํ ๊ฒ์ด๋ค.
๋ก๊ทธ๋ trace๋ ์ด๋ ์ ๋ ์ ํํ๊ฐ ๋์ด์๊ณ ์ ํ์ ์ธ ๋ฐ์ดํฐ๋ผ์ ๋์ถฉ ์ค์
๋ฃ๊ณ ์๋ฌด๊ฑฐ๋ ๋์ฐ๋ฉด ์๊ฐํ๊ฐ ์ ๋๋๋ฐ, ์ด๊ฑด ์ ์๋๋ค.
otel-collector ์์ฒด๊ฐ ํ์ํธํ์ ๋ณด์ฅํ์ง ์๊ณ 0,* ์ํ๋ก ํญ์ฃผ์ค์ธ ๊ฒ๋ ์๊ณ , span์๊ฒ์ ๊ณ์น๋ฐ๋ ๋ฐ์ดํฐ๋ ๋ค ์๊ธฐ๋ค ๋ง๋๋ก ์ฑ์๋ฃ๊ณ ๊ทธ๋ฐ๋ค. ๊ทธ๋์ grafana ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์๋ opentelemetry ํ
ํ๋ฆฟ๋ค ๋ณด๋ฉด ๋ฐ์ดํฐ ํํ๋ metric ์ด๋ฆ์ ๊ฐ์ ํ๊ฒ ๋ค ๋ค๋ฅด๋ค.
์ ๋๋ก ์ฐ๋ ค๋ฉด ์ด๋ ์ ๋ ๋ฐ์ดํฐ ์์ง ๊ตฌ์กฐ๋ฅผ ์๊ณ ์ค์ ํ ์ค๋ ์์์ผ ํ๋ค.
service์๋ spanmetric ๊ด๋ จ ์ต์ ์ ์ ๋นํ ์ฑ์์ค๋ค.
service:
pipelines:
metrics:
receivers: [otlp]
exporters: [prometheus]
metrics/spanmetrics:
receivers: [spanmetrics]
exporters: [prometheus]
traces:
receivers: [otlp]
exporters: [spanmetrics, otlp]
telemetry:
metrics:
address: 0.0.0.0:8888
level: detailed
์ด ์ ๋๋ฉด ๋๋ค.
span->metric ์ ์ด๋ otel-collector ์์ค์์ ๋ค ํด์ฃผ๋๊ฑฐ๋ผ์, ์ด๋ฏธ metric&trace ์ค์ ์ด ์ ๋์ด์๋ค๋ฉด ์ ํ๋ฆฌ์ผ์ด์ ์์ค์์ ์์ด์ ํธ ์กฐ์ ์ ๋ ํด์ค์ผ ํ ๊ฒ์ ์๋ค.
Grafana ๋์๋ณด๋ ํ์ฉ
์ด์ ๋์๋ณด๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๊ฐ์ ธ๋ค๊ฐ ์ง์ ๋์๋ณด๊ณ ์จ๋ณด์.
๋ ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ค.
https://grafana.com/grafana/dashboards/22784-lightweight-apm-for-opentelemetry/
ํน์ ์ญ์ ๋์์ ๋๋ฅผ ๊ฐ์ ํ ๋ค์ด๋ก๋ json ๋ฐฑ์
์ฒจ๋ถํ์ผ22784_rev3.zipํ์ผ ๋ค์ด๋ก๋
์๋ฌดํผ ์ ๊ฑธ importํด์ ๋์๋ณด๋๋ฅผ ๋์๋ณด๋ฉด
๋งค์ฐ ๋์ ํ๋ฅ ๋ก ๋ฐ์ดํฐ๊ฐ ๋ป์ด์์ ๊ฒ์ด๋ค.
์ค์ ๋ก ๋จ์ timeseries๋ก ์กฐํํด๋ณด๋ฉด ๋ฐ์ดํฐ๊ฐ ๋ค ์์์๋.
ํ๋ ์ด์ด์ ๋ณด๊ณ ๊ณ ์น๋ฉด์ ์จ๋ณด์.
ํด์ํด๋ณด๋ฉด, http_server_request_duration_seconds_count๋ผ๋ ๋ฉํธ๋ฆญ์ ์กฐํํ๋, job์ผ๋ก ํํฐ๋ฅผ ๊ฑธ๊ณ , ์ง๊ณํ๊ณ ํด์ ๊ฐ์ ๋ํ๋ธ๋ค๋ ๋ป์ด๋ค.
๋ด ๊ฒฝ์ฐ์ ์์์ http_server_request๋ฅผ namespace๋ก ์ค์ ํ๊ณ , histogram์ second๋ก ์กฐ์ ํ๊ธฐ ๋๋ฌธ์ ์์ ํ ๋์ผํ ์ด๋ฆ์ผ๋ก ๋ฉํธ๋ฆญ์ด ์์ฑ๋์๋ค.
๊ทธ๋ฐ๋ฐ job์ด ์ข ์ด์ํ๋ค. ์ด ๊ฒฝ์ฐ์๋ k8s์์์ ์ฌ์ฉ๋ง์ ์ ์ ํ๊ณ ์ ํ๋๊ฐ ์์ ๊ฒ์ด๋ผ ๊ธฐ๋ํ๋๋ฐ, ์ง๊ธ ๋ด ํ๊ฒฝ๊ณผ ๊ตฌ์ฑ์์๋ service_namespace์ service_name์ด ๋ฐ๋ก ์๋ค.
ํํฐ๋ฅผ ์กฐ์ ํด๋ณด์.
์ด๋ฌ๋ฉด ๋ฐ๋ก๋ฐ๋ก ์กด์ฌํ๋ ํ๋์ ๋ํด์ ํํฐ๋ฅผ ๊ฑธ ๊ฒ์ด๊ณ
์กฐํ๋ ์ ๋๊ธฐ ์์ํ ๊ฒ์ด๋ค.
๋ค๋ฅธ๊ฑฐ ๋ ์๋๋๊ฑธ ๋ณด๋ฉด
http_response_status_code๋ก ์๋ต์ฝ๋๋ฅผ ํํฐ๋งํด์ ์ค๋ฅ๋ฅผ ๋ณด์ฌ์ฃผ๊ณ ์๋ค.
๊ทผ๋ฐ ๋๋ ๋ฐฉ๊ธ ์์์ http.status_code๋ก span ๋ฐ์ดํฐ๋ฅผ ๊ทธ๋๋ก ์ ์ด์์ผฐ๋๋ฐ, ์ด๋ฌ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก http_status_code๋ผ๋ ์ด๋ฆ์ผ๋ก ๋งคํ๋์ด์ ๋ถ์ผ์น๊ฐ ๋ฐ์ํ ๊ฒ์ด๋ค.
๋ค์ ๋ง์ถฐ์ ๋๋ ค๋ณด๋ฉด ์ด์ ๋ ์ ๋ฐ ๊ฒ์ด๋ค.

๋น์ทํ ๋๋์ผ๋ก ์ด๋์ ๋ ์กฐ์ ํ๋ค๋ณด๋ฉด
์ ๋นํ ๊ทธ๋ด๋ฏํ ๋ชจ์ต์ด ๋ ๊ฒ์ด๋ค.