보존 규칙

보존 규칙 (Retention rules) API

Apache Druid에서 데이터 보존 규칙을 관리하는 API 엔드포인트를 다룹니다. 웹 콘솔이나 API로 보존 규칙을 설정할 수 있어요.

출처: 문서

본문

이 문서는 Apache Druid에서 보존 규칙(retention rules)을 관리하기 위한 API 엔드포인트를 설명합니다. Druid 웹 콘솔이나 API에서 보존 규칙을 구성할 수 있어요.

Druid는 보존 규칙을 사용해 클러스터에 어떤 데이터를 유지할지 결정합니다. Druid는 로드(load), 드롭(drop), 브로드캐스트(broadcast) 규칙을 지원해요. 자세한 내용은 Using rules to drop and retain data를 참고하세요.

이 문서에서 http://ROUTER_IP:ROUTER_PORT는 여러분의 Router 서비스 주소와 포트를 위한 자리표시자입니다. 이를 배포 정보로 교체하세요. 예를 들어 quickstart 배포라면 http://localhost:8888을 사용합니다.

데이터소스의 보존 규칙 업데이트

데이터소스에 대한 하나 이상의 보존 규칙을 업데이트합니다. 요청 본문은 보존 규칙 객체의 배열을 받습니다. 보존 규칙 정의에 대한 자세한 내용은 다음 소스를 참고하세요.

이 요청은 데이터소스의 기존 규칙을 모두 덮어씁니다. Druid는 규칙이 나타나는 순서대로 읽어요. 자세한 내용은 rule structure를 참고하세요.

이 엔드포인트는 데이터소스가 존재하지 않아도 HTTP 200 OK를 반환합니다.

URL

POST /druid/coordinator/v1/rules/{dataSource}

헤더 파라미터

이 엔드포인트는 감사 기록(audit history)을 위해 auditInfo 속성의 author와 comment 필드를 채울 수 있는 선택적 헤더 파라미터 집합을 지원합니다.

  • X-Druid-Author (선택) — 타입: String. 구성 변경을 수행하는 작성자를 나타내는 문자열.
  • X-Druid-Comment (선택) — 타입: String. 업데이트를 설명하는 문자열.

응답

  • 200 SUCCESS — 지정된 데이터소스의 보존 규칙을 성공적으로 업데이트함

샘플 요청

다음 예시는 kttm1 데이터소스에 브로드캐스트, 로드, 드롭 보존 규칙 집합을 설정합니다.

cURL

curl "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/rules/kttm1" \
--header 'X-Druid-Author: doc intern' \
--header 'X-Druid-Comment: submitted via api' \
--header 'Content-Type: application/json' \
--data '[
    {
        "type": "broadcastForever"
    },
    {
        "type": "loadForever",
        "tieredReplicants": {
            "_default_tier": 2
        },
        "useDefaultTierForNull": true
    },
    {
        "type": "dropByPeriod",
        "period": "P1M"
    }
]'

HTTP

POST /druid/coordinator/v1/rules/kttm1 HTTP/1.1
Host: http://ROUTER_IP:ROUTER_PORT
X-Druid-Author: doc intern
X-Druid-Comment: submitted via api
Content-Type: application/json
Content-Length: 273

[
    {
        "type": "broadcastForever"
    },
    {
        "type": "loadForever",
        "tieredReplicants": {
            "_default_tier": 1
        },
        "useDefaultTierForNull": true
    },
    {
        "type": "dropByPeriod",
        "period": "P1M"
    }
]

샘플 응답

성공한 요청은 HTTP 200 OK 메시지 코드와 빈 응답 본문을 반환합니다.

모든 데이터소스의 기본 보존 규칙 업데이트

모든 데이터소스에 대한 하나 이상의 기본 보존 규칙을 업데이트합니다. 보존 규칙을 요청 본문의 객체 배열로 제출하세요. 보존 규칙 정의에 대한 자세한 내용은 다음 소스를 참고하세요.

이 요청은 모든 데이터소스의 기존 규칙을 덮어씁니다. 모든 데이터소스의 기본 보존 규칙을 제거하려면 요청 본문에 빈 규칙 배열을 제출하세요. 규칙은 나타나는 순서대로 읽어요. 자세한 내용은 rule structure를 참고하세요.

URL

POST /druid/coordinator/v1/rules/_default

헤더 파라미터

이 엔드포인트는 감사 기록을 위해 auditInfo 속성의 author와 comment 필드를 채울 수 있는 선택적 헤더 파라미터 집합을 지원합니다.

  • X-Druid-Author (선택) — 타입: String. 구성 변경을 수행하는 작성자를 나타내는 문자열.
  • X-Druid-Comment (선택) — 타입: String. 업데이트를 설명하는 문자열.

응답

  • 200 SUCCESS — 기본 보존 규칙을 성공적으로 업데이트함
  • 500 SERVER ERROR — 요청 본문에 오류가 있음

샘플 요청

다음 예시는 모든 데이터소스의 기본 보존 규칙을 loadByInterval 규칙으로 업데이트합니다.

cURL

curl "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/rules/_default" \
--header 'Content-Type: application/json' \
--data '[
    {
        "type": "loadByInterval",
        "tieredReplicants": {},
        "useDefaultTierForNull": false,
        "interval": "2010-01-01/2020-01-01"
    }
]'

HTTP

POST /druid/coordinator/v1/rules/_default HTTP/1.1
Host: http://ROUTER_IP:ROUTER_PORT
Content-Type: application/json
Content-Length: 205

[
    {
        "type": "loadByInterval",
        "tieredReplicants": {},
        "useDefaultTierForNull": false,
        "interval": "2010-01-01/2020-01-01"
    }
]

샘플 응답

성공한 요청은 HTTP 200 OK 메시지 코드와 빈 응답 본문을 반환합니다.

모든 보존 규칙의 배열 가져오기

기본 보존 규칙을 포함해 클러스터의 모든 현재 보존 규칙을 가져옵니다. 각 데이터소스와 그에 연결된 보존 규칙의 객체 배열을 반환합니다.

URL

GET /druid/coordinator/v1/rules

응답

  • 200 SUCCESS — 보존 규칙을 성공적으로 조회함

샘플 요청

cURL

curl "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/rules"

HTTP

GET /druid/coordinator/v1/rules HTTP/1.1
Host: http://ROUTER_IP:ROUTER_PORT

샘플 응답

{
  "_default": [
      {
          "tieredReplicants": {
              "_default_tier": 2
          },
          "type": "loadForever"
      }
  ],
  "social_media": [
      {
          "interval": "2023-01-01T00:00:00.000Z/2023-02-01T00:00:00.000Z",
          "type": "dropByInterval"
      }
  ],
  "wikipedia_api": [],
}

한 데이터소스의 보존 규칙 배열 가져오기

단일 데이터소스에 대한 규칙 객체 배열을 가져옵니다. 보존 규칙이 없으면 빈 배열을 반환합니다.

이 엔드포인트는 데이터소스가 존재하지 않아도 HTTP 200 OK 메시지 코드를 반환합니다.

URL

GET /druid/coordinator/v1/rules/{dataSource}

쿼리 파라미터

  • full (선택) — 응답에 데이터소스의 기본 보존 규칙을 포함합니다.

응답

  • 200 SUCCESS — 보존 규칙을 성공적으로 조회함

샘플 요청

다음 예시는 이름이 social_media인 데이터소스의 커스텀 보존 규칙과 기본 보존 규칙을 조회합니다.

cURL

curl "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/rules/social_media?full=null"

HTTP

GET /druid/coordinator/v1/rules/social_media?full=null HTTP/1.1
Host: http://ROUTER_IP:ROUTER_PORT

샘플 응답

[
  {
      "interval": "2020-01-01T00:00:00.000Z/2022-02-01T00:00:00.000Z",
      "type": "dropByInterval"
  },
  {
      "interval": "2010-01-01T00:00:00.000Z/2020-01-01T00:00:00.000Z",
      "tieredReplicants": {
          "_default_tier": 2
      },
      "type": "loadByInterval"
  },
  {
      "tieredReplicants": {
          "_default_tier": 2
      },
      "type": "loadForever"
  }
]

모든 데이터소스의 감사 기록 가져오기

일정 시간 간격 동안 모든 데이터소스의 규칙 감사 기록을 가져옵니다. 기본 간격은 1주일입니다. 이 기간은 Coordinator의 runtime.properties 파일에서 druid.audit.manager.auditHistoryMillis를 설정해 변경할 수 있어요.

URL

GET /druid/coordinator/v1/rules/history

쿼리 파라미터

다음 쿼리 파라미터들은 연결(chaining)할 수 없습니다.

  • interval (선택) — 타입: ISO 8601. 결과 수를 지정된 시간 간격으로 제한합니다. /로 구분하세요. 예: 2023-07-13/2023-07-19.
  • count (선택) — 타입: Int. 결과 수를 마지막 n개 항목으로 제한합니다.

응답

  • 200 SUCCESS — 감사 기록을 성공적으로 조회함
  • 400 BAD REQUEST — 요청 형식이 잘못됨
  • 404 NOT FOUND — count 쿼리 파라미터가 너무 큼

샘플 요청

다음 예시는 2023-07-13부터 2023-07-19까지 모든 데이터소스의 감사 기록을 조회합니다.

cURL

curl "http://ROUTER_IP:ROUTER_PORT/druid/coordinator/v1/rules/history?interval=2023-07-13%2F2023-07-19"

HTTP

GET /druid/coordinator/v1/rules/history?interval=2023-07-13/2023-07-19 HTTP/1.1
Host: http://ROUTER_IP:ROUTER_PORT

샘플 응답

[
  {
      "key": "social_media",
      "type": "rules",
      "auditInfo": {
          "author": "console",
          "comment": "test",
          "ip": "127.0.0.1"
      },
      "payload": "[{\"interval\":\"2023-01-01T00:00:00.000Z/2023-02-01T00:00:00.000Z\",\"type\":\"dropByInterval\"}]",
      "auditTime": "2023-07-13T18:05:33.066Z"
  },
  {
      "key": "social_media",
      "type": "rules",
      "auditInfo": {
          "author": "console",
          "comment": "test",
          "ip": "127.0.0.1"
      },
      "payload": "[]",
      "auditTime": "2023-07-18T18:10:21.203Z"
  },
  {
      "key": "wikipedia_api",
      "type": "rules",
      "auditInfo": {
          "author": "console",
          "comment": "test",
          "ip": "127.0.0.1"
      },
      "payload": "[{\"tieredReplicants\":{\"_default_tier\":2},\"type\":\"loadForever\"}]",
      "auditTime": "2023-07-18T18:10:44.519Z"
  },
  {
      "key": "wikipedia_api",
      "type": "rules",
      "auditInfo": {
          "author": "console",
          "comment": "test",
          "ip": "127.0.0.1"
      },
      "payload": "[]",
      "auditTime": "2023-07-18T18:11:02.110Z"
  },
  {
      "key": "social_media",
      "type": "rules",
      "auditInfo": {
          "author": "console",
          "comment": "test",
          "ip": "127.0.0.1"
      },
      "payload": "[{\"interval\":\"2023-07-03T18:49:54.848Z/2023-07-03T18:49:55.861Z\",\"type\":\"dropByInterval\"}]",
      "auditTime": "2023-07-18T18:32:50.060Z"
  },
  {
      "key": "social_media",
      "type": "rules",
      "auditInfo": {
          "author": "console",
          "comment": "test",
          "ip": "127.0.0.1"
      },
      "payload": "[{\"interval\":\"2020-01-01T00:00:00.000Z/2022-02-01T00:00:00.000Z\",\"type\":\"dropByInterval\"}]",
      "auditTime": "2023-07-18T18:34:09.657Z"
  },
  {
      "key": "social_media",
      "type": "rules",
      "auditInfo": {
          "author": "console",
          "comment": "test",
          "ip": "127.0.0.1"
      },
      "payload": "[{\"interval\":\"2020-01-01T00:00:00.000Z/2022-02-01T00:00:00.000Z\",\"type\":\"dropByInterval\"},{\"tieredReplicants\":{\"_default_tier\":2},\"type\":\"loadForever\"}]",
      "auditTime": "2023-07-18T18:38:37.223Z"
  },
  {
      "key": "social_media",
      "type": "rules",
      "auditInfo": {
          "author": "console",
          "comment": "test",
          "ip": "127.0.0.1"
      },
      "payload": "[{\"interval\":\"2020-01-01T00:00:00.000Z/2022-02-01T00:00:00.000Z\",\"type\":\"dropByInterval\"},{\"interval\":\"2010-01-01T00:00:00.000Z/2020-01-01T00:00:00.000Z\",\"tieredReplicants\":{\"_default_tier\":2},\"type\":\"loadByInterval\"}]",
      "auditTime": "2023-07-18T18:49:43.964Z"
  }
]

더 알아보기 (Learn more)

  • 보존 규칙의 구조와 옵션은 rule configuration 문서를 참고하세요.
  • 데이터 관리 API 전반은 data-management API 문서를 확인해 보세요.