스토리지 연동 목록을 살펴보면 Loki 2.0 이상에서 싱글 스토어(boltdb-shipper)가 추가되었고 연동으로 추천하고 있다. (기본 스토리지도 싱글 스토어이다.) 이유를 살펴보니 비용 감소인데 로컬에서 인덱스를 저장하기 때문에 외부 스토리지에 대한 종속성이 줄기 때문이라 한다. 다만, 원격 저장소로 백업하고 복원하는데 추가 작업이 필요하다. (앞 글에서는 S3로 연동했으나 시간 텀이 15분 정도 있었음)
비용은 발생하지만, DyanmoDB 연동 목적은 다음과 같다.
복원력 : 실시간으로 데이터가 적재되어 로키 파드가 죽어도 데이터가 유지된다.
확장성 : 멀티 클러스터에서의 실시간 로깅 확인 (로컬인 경우 S3에 적재가 가능하지만 시간 텀이 있다.)
결론적으로, 소규모 프로젝트나 초기 설정에 초점을 맞추는 경우 BoltDB & S3 옵션을 고려할 수 있다. 반면, 대규모 프로젝트나 장기적인 운영에 초점을 맞추는 경우 S3 & DynamoDB 옵션이 더 적합하다.
연동 트러블슈팅
DynamoDB 연동을 위해 해결했던 문제점은 두가지였다. 항목별로 살펴보겠다.
Helm Value Override 문제
Loki 스토리지 연동 설정 문제
Helm Value Override 문제
지난 글에서 스토리지 설정을 S3 및 기타 스토리지로 설정했음에도 기본 스토리지 (boltdb & snipper) 가 설정되어 관련 문제를 확인하였다. helm template 명령어를 통해서 스토리지 차트 랜더링을 확인하니 Values 오버라이드 값이 아닌 기본 값(boltdb & snipper)이 입력되어 있는 것을 확인할 수 있다.
# vaule.yamlLoki:...config:| ....table_manager:retention_deletes_enabled:trueretention_period:336hindex_tables_provisioning:provisioned_write_throughput:5provisioned_read_throughput:5chunk_tables_provisioning:provisioned_write_throughput:5provisioned_read_throughput:5...# vaule.yamlLoki:...# -- Check https://grafana.com/docs/loki/latest/configuration/#schema_config for more info on how to configure schemasschemaConfig:configs:- from:"2022-01-11"store:awsobject_store:s3schema:v12index:prefix:loki_# -- Check https://grafana.com/docs/loki/latest/configuration/#ruler for more info on configuring rulerrulerConfig:{}# -- Structured loki configuration, takes precedence over `loki.config`, `loki.schemaConfig`, `loki.storageConfig`structuredConfig:{}# -- Additional query scheduler configquery_scheduler:{}# -- Additional storage configstorage_config:hedging:at:"250ms"max_per_second:20up_to:3aws:s3:s3.ap-northeast-2.amazonaws.combucketnames:han-lokiregion:ap-northeast-2access_key_id:<access-key> secret_access_key:<aws-secret-key>dynamodb:dynamodb_url:dynamodb.ap-northeast-2.amazonaws.com...config:| ....table_manager:retention_deletes_enabled:trueretention_period:336hindex_tables_provisioning:provisioned_write_throughput:5provisioned_read_throughput:5chunk_tables_provisioning:provisioned_write_throughput:5provisioned_read_throughput:5...
## Loki 스토리지 연동 설정 문제
DynamoDB 스토리지로 선택이 되나, loki-read Pod에서 다음의 연동 오류가 발생한다.
```bash
level=info ts=2023-04-16T13:31:40.414190216Z caller=http.go:279 org_id=fake msg="ended tailing logs" tenant=fake selectors="{stream=\"stdout\",pod=\"loki-canary-c8s22\"}"
level=info ts=2023-04-16T13:31:50.419151688Z caller=http.go:276 org_id=fake msg="starting to tail logs" tenant=fake selectors="{stream=\"stdout\",pod=\"loki-canary-c8s22\"}"
level=error ts=2023-04-16T13:31:50.422289139Z caller=series_index_store.go:583 org_id=fake msg="error querying storage" err="QueryPages error: table=loki_: MissingRegion: could not find region configuration"
level=error ts=2023-04-16T13:31:50.422642663Z caller=series_index_store.go:583 org_id=fake msg="error querying storage" err="QueryPages error: table=loki_: MissingRegion: could not find region configuration"
level=info ts=2023-04-16T13:31:50.422757665Z caller=http.go:279 org_id=fake msg="ended tailing logs" tenant=fake selectors="{stream=\"stdout\",pod=\"loki-canary-c8s22\"}"
level=info ts=2023-04-16T13:32:00.112792136Z caller=http.go:276 org_id=fake msg="starting to tail logs" tenant=fake selectors="{stream=\"stdout\",pod=\"loki-canary-q52t8\"}"
level=error ts=2023-04-16T13:32:00.11538504Z caller=series_index_store.go:583 org_id=fake msg="error querying storage" err="QueryPages error: table=loki_: MissingRegion: could not find region configuration"
level=error ts=2023-04-16T13:32:00.115479121Z caller=series_index_store.go:583 org_id=fake msg="error querying storage" err="QueryPages error: table=loki_: MissingRegion: could not find region configuration"
필자의 경우 에러 메세지를 기반으로 소스 코드를 분석했다. 결론적으로는 DynamoDB Struct에 Region 설정값이 없어서 생긴 오류였다. 코드 분석 과정은 다음과 같다.
에러 메세지을 찾아 확인하니 ValidateEndpointHandler 함수에서 발생하는 에러였다.
해당 함수는 AWS SDK의 일부로 AWS 서비스 요청에 대한 엔드포인트와 리전 정보를 검증하는 함수이다.
해당 함수의 호출은 AWS 클라이언트를 생성하고, 이를 사용하여 서비스 요청을 시작할 때 발생한다. 각 스토리지 S3, DyanmoDB 클라이언트 구조체는 다음과 같은데 S3에는 region이 있지만, Dynamodb 에서는 해당 변수가 없었다.
아래와 같이 DynamoDB는 변수 dynamdb.dynamodb_url 이 Endpoint 및 시크릿 키를 입력받도록 되어 있다. 이는 Loki 버전 업데이트 전(Version 2.0 이하)의 변수 입력과 동일하다. 필자가 추정하건데 차트와 연동하여 스토리지 변수 설정 부분은 S3, GCS, Azure 만 업데이트되어 있는 것 같다.
오류 해결은 간단하다. Loki 스토리지 예제를 참고하여 DynamoDB_URL에 Region 과 AWS 키 값 형식을 확인하며 차트에 반영하면 된다. Loki 스토리지 예제는 다음과 같이 확인할 수 있었다.
# values.yamlLoki:......config:| ....table_manager:retention_deletes_enabled:trueretention_period:336hindex_tables_provisioning:provisioned_write_throughput:5provisioned_read_throughput:5chunk_tables_provisioning:provisioned_write_throughput:5provisioned_read_throughput:5...# -- Check https://grafana.com/docs/loki/latest/configuration/#schema_config for more info on how to configure schemasschemaConfig:configs:- from:"2022-01-11"store:awsobject_store:s3schema:v12index:prefix:loki_...# -- Check https://grafana.com/docs/loki/latest/configuration/#ruler for more info on configuring rulerrulerConfig:{}# -- Structured loki configuration, takes precedence over `loki.config`, `loki.schemaConfig`, `loki.storageConfig`structuredConfig:{}# -- Additional query scheduler configquery_scheduler:{}# -- Additional storage configstorage_config:hedging:at:"250ms"max_per_second:20up_to:3aws:s3:s3://<AWS-ACCESS-KEY>:<AWS-SECRET-KEY>@ap-northeast-2/han-lokidynamodb:dynamodb_url:dynamodb:///<AWS-ACCESS-KEY>:<AWS-SECRET-KEY>@ap-northeast-2
앞선 깃 이슈에서 dynamodb_url에 inmemory:/// 로 변수를 설정하는 것이 있었는데 이는 가상의 인메모리로 구현시 사용된다고 한다. 연동시 헷갈리지 말자