log:
    stdout: true
    level: {{ default .Env.LOG_LEVEL "info" }}

persistence:
    numHistoryShards: {{ default .Env.NUM_HISTORY_SHARDS "4" }}
    defaultStore: default
    visibilityStore: visibility
    {{- $es := default .Env.ENABLE_ES "false" | lower -}}
    {{- if eq $es "true" }}
    advancedVisibilityStore: es-visibility
    {{- end }}
    datastores:
        {{- $db := default .Env.DB "cassandra" | lower -}}
        {{- if or (eq $db "cassandra") (eq $db "scylla") }}
        default:
            nosql:
                pluginName: "cassandra"
                hosts: {{ default .Env.CASSANDRA_SEEDS "" }}
                keyspace: {{ default .Env.KEYSPACE "cadence" }}
                user: {{ default .Env.CASSANDRA_USER "" }}
                password: {{ default .Env.CASSANDRA_PASSWORD "" }}
                protoVersion: {{ default .Env.CASSANDRA_PROTO_VERSION "4" }}
        visibility:
            nosql:
                pluginName: "cassandra"
                hosts: {{ default .Env.CASSANDRA_SEEDS "" }}
                keyspace: {{ default .Env.VISIBILITY_KEYSPACE "cadence_visibility" }}
                user: {{ default .Env.CASSANDRA_USER "" }}
                password: {{ default .Env.CASSANDRA_PASSWORD "" }}
                protoVersion: {{ default .Env.CASSANDRA_PROTO_VERSION "4" }}
        {{- else if eq $db "mysql" }}
        default:
            sql:
                pluginName: "mysql"
                databaseName: {{ default .Env.DBNAME "cadence" }}
                connectAddr: "{{ default .Env.MYSQL_SEEDS "" }}:{{ default .Env.DB_PORT "3306" }}"
                connectProtocol: "tcp"
                user: {{ default .Env.MYSQL_USER "" }}
                password: {{ default .Env.MYSQL_PWD "" }}
                {{- if .Env.MYSQL_TX_ISOLATION_COMPAT }}
                connectAttributes:
                    tx_isolation: 'READ-COMMITTED'
                {{- end }}
        visibility:
            sql:
                pluginName: "mysql"
                databaseName: {{ default .Env.VISIBILITY_DBNAME "cadence_visibility" }}
                connectAddr: "{{ default .Env.MYSQL_SEEDS "" }}:{{ default .Env.DB_PORT "3306" }}"
                connectProtocol: "tcp"
                user: {{ default .Env.MYSQL_USER "" }}
                password: {{ default .Env.MYSQL_PWD "" }}
                {{- if .Env.MYSQL_TX_ISOLATION_COMPAT }}
                connectAttributes:
                    tx_isolation: 'READ-COMMITTED'
                {{- end }}
        {{- else if eq $db "postgres" }}
        default:
            sql:
                pluginName: "postgres"
                encodingType: "thriftrw"
                decodingTypes: ["thriftrw"]
                databaseName: {{ default .Env.DBNAME "cadence" }}
                connectAddr: "{{ default .Env.POSTGRES_SEEDS "" }}:{{ default .Env.DB_PORT "5432" }}"
                connectProtocol: "tcp"
                user: {{ default .Env.POSTGRES_USER "" }}
                password: {{ default .Env.POSTGRES_PWD "" }}
                maxConns: 20
                maxIdleConns: 20
                maxConnLifetime: "1h"
        visibility:
            sql:
                pluginName: "postgres"
                encodingType: "thriftrw"
                decodingTypes: ["thriftrw"]
                databaseName: {{ default .Env.VISIBILITY_DBNAME "cadence_visibility" }}
                connectAddr: "{{ default .Env.POSTGRES_SEEDS "" }}:{{ default .Env.DB_PORT "5432" }}"
                connectProtocol: "tcp"
                user: {{ default .Env.POSTGRES_USER "" }}
                password: {{ default .Env.POSTGRES_PWD "" }}
                maxConns: 20
                maxIdleConns: 20
                maxConnLifetime: "1h"
        {{- end }}
        {{- if eq $es "true" }}
        es-visibility:
            elasticsearch:
                version: {{ default .Env.ES_VERSION "" }}
                username: {{ default .Env.ES_USER "" }}
                password: {{ default .Env.ES_PWD "" }}
                url:
                    scheme: "http"
                    host: "{{ default .Env.ES_SEEDS "" }}:{{ default .Env.ES_PORT "9200" }}"
                indices:
                    visibility: {{ default .Env.VISIBILITY_NAME "cadence-visibility-dev" }}
        {{- end }}

ringpop:
    name: cadence
    bootstrapMode: {{ default .Env.RINGPOP_BOOTSTRAP_MODE "hosts" }}
    {{- if .Env.RINGPOP_SEEDS }}
    bootstrapHosts:
    {{- range $seed := (split .Env.RINGPOP_SEEDS ",") }}
        - {{ . }}
    {{- end }}
    {{- else }}
    bootstrapHosts:
        - {{ .Env.HOST_IP }}:{{ default .Env.FRONTEND_PORT "7933" }}
        - {{ .Env.HOST_IP }}:{{ default .Env.HISTORY_PORT "7934" }}
        - {{ .Env.HOST_IP }}:{{ default .Env.MATCHING_PORT "7935" }}
        - {{ .Env.HOST_IP }}:{{ default .Env.WORKER_PORT "7939" }}
    {{- end }}
    maxJoinDuration: 30s

services:
    frontend:
        rpc:
            port: {{ default .Env.FRONTEND_PORT "7933" }}
            grpcPort: {{ default .Env.GRPC_FRONTEND_PORT "7833" }}
            bindOnIP: {{ default .Env.BIND_ON_IP "127.0.0.1" }}
            {{- if .Env.FRONTEND_HTTP_PORT }}
            http:
                port: {{ .Env.FRONTEND_HTTP_PORT }}
                procedures:
                {{- range $seed := (split .Env.FRONTEND_HTTP_PROCEDURES ",") }}
                    - {{ . }}
                {{- end }}
            {{- end }}
        {{- if .Env.STATSD_ENDPOINT }}
        metrics:
            statsd:
                hostPort: {{ .Env.STATSD_ENDPOINT }}
                prefix: {{ default .Env.STATSD_FRONTEND_PREFIX "cadence-frontend" }}
        {{- else if .Env.PROMETHEUS_ENDPOINT }}
        metrics:
            prometheus:
                timerType: {{ default .Env.PROMETHEUS_TIMER_TYPE "histogram" }}
                listenAddress: {{ .Env.PROMETHEUS_ENDPOINT }}
        {{- else if .Env.PROMETHEUS_ENDPOINT_0 }}
        metrics:
            prometheus:
                timerType: {{ default .Env.PROMETHEUS_TIMER_TYPE "histogram" }}
                listenAddress: {{ .Env.PROMETHEUS_ENDPOINT_0 }}
        {{- end }}

    matching:
        rpc:
            port: {{ default .Env.MATCHING_PORT "7935" }}
            grpcPort: {{ default .Env.GRPC_MATCHING_PORT "7835" }}
            bindOnIP: {{ default .Env.BIND_ON_IP "127.0.0.1" }}
        {{- if .Env.STATSD_ENDPOINT }}
        metrics:
            statsd:
                hostPort: {{ .Env.STATSD_ENDPOINT }}
                prefix: {{ default .Env.STATSD_MATCHING_PREFIX "cadence-matching" }}
        {{- else if .Env.PROMETHEUS_ENDPOINT }}
        metrics:
            prometheus:
                timerType: {{ default .Env.PROMETHEUS_TIMER_TYPE "histogram" }}
                listenAddress: {{ .Env.PROMETHEUS_ENDPOINT }}
        {{- else if .Env.PROMETHEUS_ENDPOINT_1 }}
        metrics:
            prometheus:
                timerType: {{ default .Env.PROMETHEUS_TIMER_TYPE "histogram" }}
                listenAddress: {{ .Env.PROMETHEUS_ENDPOINT_1 }}
        {{- end }}

    history:
        rpc:
            port: {{ default .Env.HISTORY_PORT "7934" }}
            grpcPort: {{ default .Env.GRPC_HISTORY_PORT "7834" }}
            bindOnIP: {{ default .Env.BIND_ON_IP "127.0.0.1" }}
        {{- if .Env.STATSD_ENDPOINT }}
        metrics:
            statsd:
                hostPort: {{ .Env.STATSD_ENDPOINT }}
                prefix: {{ default .Env.STATSD_HISTORY_PREFIX "cadence-history" }}
        {{- else if .Env.PROMETHEUS_ENDPOINT }}
        metrics:
            prometheus:
                timerType: {{ default .Env.PROMETHEUS_TIMER_TYPE "histogram" }}
                listenAddress: {{ .Env.PROMETHEUS_ENDPOINT }}
        {{- else if .Env.PROMETHEUS_ENDPOINT_2 }}
        metrics:
            prometheus:
                timerType: {{ default .Env.PROMETHEUS_TIMER_TYPE "histogram" }}
                listenAddress: {{ .Env.PROMETHEUS_ENDPOINT_2 }}
        {{- end }}

    worker:
        rpc:
            port: {{ default .Env.WORKER_PORT "7939" }}
            bindOnIP: {{ default .Env.BIND_ON_IP "127.0.0.1" }}
        {{- if .Env.STATSD_ENDPOINT }}
        metrics:
            statsd:
                hostPort: {{ .Env.STATSD_ENDPOINT }}
                prefix: {{ default .Env.STATSD_WORKER_PREFIX "cadence-worker" }}
        {{- else if .Env.PROMETHEUS_ENDPOINT }}
        metrics:
            prometheus:
                timerType: {{ default .Env.PROMETHEUS_TIMER_TYPE "histogram" }}
                listenAddress: {{ .Env.PROMETHEUS_ENDPOINT }}
        {{- else if .Env.PROMETHEUS_ENDPOINT_3 }}
        metrics:
            prometheus:
                timerType: {{ default .Env.PROMETHEUS_TIMER_TYPE "histogram" }}
                listenAddress: {{ .Env.PROMETHEUS_ENDPOINT_3 }}
        {{- end }}

clusterGroupMetadata:
    clusterRedirectionPolicy:
        policy: {{ default .Env.CLUSTER_REDIRECT_POLICY "all-domain-apis-forwarding" }}
    failoverVersionIncrement: 10
    primaryClusterName: "cluster0"
    {{- if .Env.IS_NOT_PRIMARY }}
    currentClusterName: "cluster1"
    {{- else }}
    currentClusterName: "cluster0"
    {{- end }}
    clusterGroup:
        cluster0:
            enabled: true
            initialFailoverVersion: 0
            rpcName: "cadence-frontend"
            rpcAddress: {{ default .Env.PRIMARY_FRONTEND_SERVICE "cadence" }}:{{ default .Env.FRONTEND_PORT "7833" }}
            rpcTransport: "grpc"
            authorizationProvider:
                enable: {{ default .Env.ENABLE_OAUTH "false" }}
                type: "OAuthAuthorization"
                privateKey: {{ default .Env.OAUTH_PRIVATE_KEY "" }}
        {{- if .Env.ENABLE_GLOBAL_DOMAIN }}
        cluster1:
            enabled: true
            initialFailoverVersion: 2
            rpcName: "cadence-frontend"
            rpcAddress: {{ default .Env.SECONDARY_FRONTEND_SERVICE "cadence-secondary" }}:{{ default .Env.FRONTEND_PORT "7833" }}
            rpcTransport: "grpc"
            authorizationProvider:
                enable: {{ default .Env.ENABLE_OAUTH "false" }}
                type: "OAuthAuthorization"
                privateKey: {{ default .Env.OAUTH_PRIVATE_KEY "" }}
        {{- end }}

archival:
  history:
    status: {{ default .Env.HISTORY_ARCHIVAL_STATUS "disabled" }}
    enableRead: {{ default .Env.HISTORY_ARCHIVAL_ENABLE_READ "false" }}
    provider:
      filestore:
        fileMode: {{ default .Env.HISTORY_ARCHIVAL_FILE_MODE "" }}
        dirMode: {{ default .Env.HISTORY_ARCHIVAL_DIR_MODE "" }}
  visibility:
    status: {{ default .Env.VISIBILITY_ARCHIVAL_STATUS "disabled" }}
    enableRead: {{ default .Env.VISIBILITY_ARCHIVAL_ENABLE_READ "false" }}
    provider:
      filestore:
        fileMode: {{ default .Env.VISIBILITY_ARCHIVAL_FILE_MODE "" }}
        dirMode: {{ default .Env.VISIBILITY_ARCHIVAL_DIR_MODE "" }}

domainDefaults:
  archival:
    history:
      status: {{ default .Env.DOMAIN_DEFAULTS_HISTORY_ARCHIVAL_STATUS "disabled" }}
      URI: {{ default .Env.DOMAIN_DEFAULTS_HISTORY_ARCHIVAL_URI "" }}
    visibility:
      status: {{ default .Env.DOMAIN_DEFAULTS_VISIBILITY_ARCHIVAL_STATUS "disabled" }}
      URI: {{ default .Env.DOMAIN_DEFAULTS_VISIBILITY_ARCHIVAL_URI "" }}

kafka:
    tls:
        enabled: false
    clusters:
        test:
            brokers:
                - {{ default .Env.KAFKA_SEEDS "" }}:{{ default .Env.KAFKA_PORT "9092" }}
    topics:
        {{ default .Env.VISIBILITY_NAME "cadence-visibility-dev" }}:
            cluster: test
        {{ default .Env.VISIBILITY_NAME "cadence-visibility-dev" }}-dlq:
            cluster: test
    applications:
        visibility:
            topic: {{ default .Env.VISIBILITY_NAME "cadence-visibility-dev" }}
            dlq-topic: {{ default .Env.VISIBILITY_NAME "cadence-visibility-dev" }}-dlq

publicClient:
    hostPort: {{ default .Env.FRONTEND_SERVICE "cadence" }}:{{ default .Env.FRONTEND_PORT "7933" }}

dynamicconfig:
  client: filebased
  filebased:
    filepath: {{ default .Env.DYNAMIC_CONFIG_FILE_PATH "/etc/cadence/config/dynamicconfig/development.yaml" }}
    pollInterval: "60s"

blobstore:
  filestore:
    outputDirectory: {{ default .Env.FILE_BLOB_STORE_OUTPUT_DIRECTYORY "" }}

authorization:
    oauthAuthorizer:
        enable: {{ default .Env.ENABLE_OAUTH "false" }}
        maxJwtTTL: {{ default .Env.OAUTH_MAX_JWT_TTL "86400" }}
        jwtCredentials:
            algorithm: "RS256"
            publicKey: {{ default .Env.OAUTH_PUBLIC_KEY "" }}

{{- if .Env.ASYNC_WF_KAFKA_QUEUE_ENABLED }}
asyncWorkflowQueues:
  queue1:
    type: "kafka"
    config:
      connection:
        brokers:
          - {{ default .Env.KAFKA_SEEDS "" }}:{{ default .Env.KAFKA_PORT "9092" }}
      topic: {{ default .Env.ASYNC_WF_KAFKA_QUEUE_TOPIC "default-topic" }}
{{- end }}
