# =============================================================================
# StarRocks Helm Chart - Custom Values for Development Environment
# =============================================================================
# Deploys StarRocks in shared-data mode using Azure Data Lake Storage Gen2
# (ADLS2) as the backend object store. BE (Backend) is disabled; CN
# (Compute Node) is used instead for the shared-data architecture.
# =============================================================================

operator:
  starrocksOperator:
    watchNamespace: "dr-starrocks-ctr-t4"

starrocks:
  # ---------------------------------------------------------------------------
  # Root Password
  # ---------------------------------------------------------------------------
  # Enables password-based authentication for the root user.
  # The password is read from a pre-created Kubernetes secret.
  # Create the secret with:
  #   kubectl create secret generic starrocks-root-pass \
  #     --from-literal=password='g()()dpa$$word' -n starrocks-cn
  initPassword:
    enabled: true
    passwordSecret: starrocks-root-pass

  # ---------------------------------------------------------------------------
  # Metrics / Prometheus ServiceMonitor
  # ---------------------------------------------------------------------------
  # Set to true to enable a Prometheus ServiceMonitor custom resource.
  # Requires the Prometheus Operator to be installed in the cluster.
  metrics:
    serviceMonitor:
      enabled: false

  # ---------------------------------------------------------------------------
  # Cluster Component Topology
  # ---------------------------------------------------------------------------
  # Configures which components are deployed.
  # In shared-data mode, BE is not required — CN handles compute workloads.
  starrocksCluster:
    enabledBe: false   # BE is disabled; not used in shared-data/CN mode
    enabledCn: true    # CN is enabled as the compute layer
    componentValues:
      image:
        tag: "4.0-latest"   # StarRocks image version used by all components

  # ---------------------------------------------------------------------------
  # Frontend (FE) Specification
  # ---------------------------------------------------------------------------
  # The FE manages metadata, query planning, and cluster coordination.
  # Exposed via an internal Azure Load Balancer with Prometheus scrape annotations.
  starrocksFESpec:
    replicas: 2   # Single FE replica for development; increase for HA in production
    startupProbeFailureSeconds: 300   # Allow up to 5 minutes for FE to start up
    annotations:
      prometheus.io/path: /metrics
      prometheus.io/port: "8030"
      prometheus.io/scrape: "true"
    service:
      type: LoadBalancer
      annotations:
        service.beta.kubernetes.io/azure-load-balancer-internal: "true"   # Internal LB only; no public IP
    resources:
      requests:
        cpu: 1
        memory: 2Gi
      limits:
        cpu: 4
        memory: 8Gi
    storageSpec:
      name: fe
      storageSize: 10Gi       # Persistent volume size for FE metadata
      logStorageSize: 10Gi    # Persistent volume size for FE logs
      storageClassName: starrocks-cn

    # Environment variables injected from the ADLS2 Kubernetes secret.
    # These are referenced in the FE config block below via ${VAR_NAME}.
    feEnvVars:
      - name: AZURE_ADLS2_PATH
        valueFrom:
          secretKeyRef:
            name: starrocks-adls2-secret
            key: azure_adls2_path
      - name: AZURE_ADLS2_ENDPOINT
        valueFrom:
          secretKeyRef:
            name: starrocks-adls2-secret
            key: azure_adls2_endpoint
      - name: AZURE_ADLS2_SHARED_KEY
        valueFrom:
          secretKeyRef:
            name: starrocks-adls2-secret
            key: azure_adls2_shared_key

    # FE configuration file (fe.conf).
    # Configures ports, JVM options, logging, load settings,
    # and shared-data storage using Azure ADLS2.
    config: |
      LOG_DIR = ${STARROCKS_HOME}/log
      DATE = "$(date +%Y%m%d-%H%M%S)"
      JAVA_OPTS="-Dlog4j2.formatMsgNoLookups=true -Xmx2048m -XX:+UseG1GC -Xlog:gc*:${LOG_DIR}/fe.gc.log.$DATE:time"

      # Network ports
      http_port = 8030
      rpc_port = 9020
      query_port = 9030
      edit_log_port = 9010

      # MySQL-compatible NIO service
      mysql_service_nio_enabled = true

      # Logging: DEBUG level, keep 5 rolled files, auto-delete after 3 days
      sys_log_level = DEBUG
      sys_log_delete_age = 3d
      sys_log_roll_num = 3

      audit_log_delete_age = 3d
      audit_log_roll_num = 3

      dump_log_delete_age = 3d
      dump_log_roll_num = 3

      internal_log_delete_age = 3d
      internal_log_roll_num = 3

      big_query_log_delete_age = 3d
      big_query_log_roll_num = 3

      profile_log_delete_age = 1d
      profile_log_roll_num = 5

      # Graceful shutdown: wait up to 25 seconds before forcing exit
      min_graceful_exit_time_second = 25

      # Load profile collection for query diagnostics
      enable_load_profile = true
      load_profile_collect_interval_second = 30
      stream_load_profile_collect_threshold_second = 30

      # Trash retention for dropped catalogs: ~15 days (in seconds)
      catalog_trash_expire_second = 1296000

      # Enable loading storage volume config from fe.conf
      enable_load_volume_from_conf = true

      # Collect query detail info for observability
      enable_collect_query_detail_info = true

      # Maximum batch size for stream load (in MB)
      max_stream_load_batch_size_mb = 20480

      # Timeout for tablet deletion operations (in seconds)
      tablet_delete_timeout_second = 10

      automated_cluster_snapshot_interval_seconds = 300

      # Shared-data mode: data stored in object storage, not local BE disks
      run_mode = shared_data
      cloud_native_meta_port = 6090
      cloud_native_storage_type = ADLS2

      # ADLS2 credentials injected via environment variables from Kubernetes secret
      azure_adls2_path = ${AZURE_ADLS2_PATH}
      azure_adls2_endpoint = ${AZURE_ADLS2_ENDPOINT}
      azure_adls2_shared_key = ${AZURE_ADLS2_SHARED_KEY}

  # ---------------------------------------------------------------------------
  # Compute Node (CN) Specification
  # ---------------------------------------------------------------------------
  # CNs handle query execution in shared-data mode.
  # BE is disabled (enabledBe: false), so CN is the sole compute layer.
  # Horizontal Pod Autoscaler (HPA) is configured to scale between 2 and 10 replicas.
  starrocksCnSpec:
    replicas: 2   # Minimum 2 replicas; matches HPA minReplicas
    startupProbeFailureSeconds: 300   # Allow up to 5 minutes for CN to start up
    annotations:
      prometheus.io/path: /metrics
      prometheus.io/port: "8040"
      prometheus.io/scrape: "true"
    resources:
      requests:
        cpu: 1
        memory: 2Gi
      limits:
        cpu: 4
        memory: 8Gi
    storageSpec:
      name: cn
      storageSize: 10Gi       # Persistent volume size for CN local cache/storage
      logStorageSize: 10Gi    # Persistent volume size for CN logs (consistent with FE)
      storageClassName: starrocks-cn

    # CN configuration file (cn.conf).
    # Configures ports, logging, data cache, and memory limits.
    config: |
      # Logging: INFO level, keep 5 rolled files, auto-delete after 4 days
      sys_log_level = INFO
      sys_log_roll_num = 3
      sys_log_delete_age = 3d

      primary_key_limit_size = 640

      # Network ports
      thrift_port = 9060
      webserver_port = 8040
      heartbeat_service_port = 9050
      brpc_port = 8060
      starlet_port = 9070

      # Local storage path for CN data cache
      storage_root_path = ${STARROCKS_HOME}/storage

      # Data cache settings: cache hot data locally to reduce ADLS2 read latency
      datacache_enable = true
      datacache_disk_size = 2G
      datacache_mem_size = 2G

      # Page cache: enabled with a 1G limit for repeated block reads
      disable_storage_page_cache = false
      storage_page_cache_limit = 1G

      # Memory limit as a percentage of the pod's total memory
      mem_limit = 80%

      streaming_load_max_batch_size_mb = 2000
      streaming_load_max_mb = 202400
      flush_thread_num_per_store = 20

    # Horizontal Pod Autoscaler policy for CN scaling.
    # Scales up aggressively (1 pod per 10s) and scales down conservatively
    # (1 pod per 60s with a 5-minute stabilization window).
    autoScalingPolicy:
      maxReplicas: 10
      minReplicas: 2
      hpaPolicy:
        metrics:
          - type: Resource
            resource:
              name: cpu
              target:
                averageUtilization: 90   # Scale up when average CPU exceeds 90%
                type: Utilization
        behavior:
          scaleUp:
            policies:
              - type: Pods
                value: 1          # Add 1 pod at a time
                periodSeconds: 10 # Evaluate every 10 seconds
          scaleDown:
            stabilizationWindowSeconds: 300   # Wait 5 minutes before scaling down
            policies:
              - type: Pods
                value: 1          # Remove 1 pod at a time
                periodSeconds: 60 # Evaluate every 60 seconds
            selectPolicy: Min     # Use the most conservative scale-down policy

  # ---------------------------------------------------------------------------
  # FE Proxy Specification
  # ---------------------------------------------------------------------------
  # An Nginx-based reverse proxy in front of the FE for MySQL and HTTP traffic.
  # Exposed via an internal Azure Load Balancer.
  starrocksFeProxySpec:
    enabled: true
    replicas: 1
    service:
      type: LoadBalancer
      annotations:
        service.beta.kubernetes.io/azure-load-balancer-internal: "true"   # Internal LB only; no public IP
    resources:
      requests:
        cpu: 2
        memory: 2Gi
      limits:
        cpu: 4
        memory: 4Gi


