github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/scripts/development/m3_prom_remote_stack/start_m3.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  set -xe
     4  
     5  source "$(pwd)/../../docker-integration-tests/common.sh"
     6  
     7  # Locally don't care if we hot loop faster
     8  export MAX_TIMEOUT=4
     9  
    10  RELATIVE="./../../.."
    11  prepare_build_cmd() {
    12      build_cmd="cd $RELATIVE && make clean-build docker-dev-prep && cp -r ./docker ./bin/ && $1"
    13  }
    14  DOCKER_ARGS="--detach --renew-anon-volumes"
    15  PROMETHEUS_DOCKER_ARGS="--detach"
    16  
    17  M3COORDINATOR_DEV_IMG=$(docker images m3coordinator:dev | fgrep -iv repository | wc -l | xargs)
    18  M3AGGREGATOR_DEV_IMG=$(docker images m3aggregator:dev | fgrep -iv repository | wc -l | xargs)
    19  
    20  docker-compose -f docker-compose.yml up $DOCKER_ARGS etcd01
    21  
    22  cp ./m3coordinator-admin.yml ./m3coordinator.yml.tmp
    23  
    24  if [[ "$M3COORDINATOR_DEV_IMG" == "0" ]] || [[ "$FORCE_BUILD" == true ]] || [[ "$BUILD_M3COORDINATOR" == true ]]; then
    25      prepare_build_cmd "make m3coordinator-linux-amd64"
    26      echo "Building m3coordinator binary first"
    27      bash -c "$build_cmd"
    28  
    29      docker-compose -f docker-compose.yml up --build $DOCKER_ARGS m3coordinator01
    30  else
    31      docker-compose -f docker-compose.yml up $DOCKER_ARGS m3coordinator01
    32  fi
    33  
    34  echo "Wait for coordinator API to be up"
    35  ATTEMPTS=10 MAX_TIMEOUT=4 TIMEOUT=1 retry_with_backoff \
    36      'curl -vvvsSf localhost:7201/health'
    37  
    38  echo "Running aggregator pipeline"
    39  curl -vvvsSf -X POST localhost:7201/api/v1/services/m3aggregator/placement/init -d '{
    40      "num_shards": 64,
    41      "replication_factor": 1,
    42      "instances": [
    43          {
    44              "id": "m3aggregator01",
    45              "isolation_group": "rack-a",
    46              "zone": "embedded",
    47              "weight": 1024,
    48              "endpoint": "m3aggregator01:6000",
    49              "hostname": "m3aggregator01",
    50              "port": 6000
    51          }
    52      ]
    53  }'
    54  
    55  echo "Initializing m3msg inbound topic for m3aggregator ingestion from m3coordinators"
    56  curl -vvvsSf -X POST -H "Topic-Name: aggregator_ingest" -H "Cluster-Environment-Name: default_env" localhost:7201/api/v1/topic/init -d '{
    57      "numberOfShards": 64
    58  }'
    59  
    60  echo "Adding m3aggregator as a consumer to the aggregator ingest topic"
    61  curl -vvvsSf -X POST -H "Topic-Name: aggregator_ingest" -H "Cluster-Environment-Name: default_env" localhost:7201/api/v1/topic -d '{
    62      "consumerService": {
    63          "serviceId": {
    64          "name": "m3aggregator",
    65          "environment": "default_env",
    66          "zone": "embedded"
    67          },
    68          "consumptionType": "REPLICATED",
    69          "messageTtlNanos": "600000000000"
    70      }
    71  }' # msgs will be discarded after 600000000000ns = 10mins
    72  
    73  # Create outbound m3msg topic for m3 aggregators to coordinators
    74  echo "Initializing m3msg outbound topic for m3 aggregators to coordinators"
    75  curl -vvvsSf -X POST -H "Topic-Name: aggregated_metrics" -H "Cluster-Environment-Name: default_env" localhost:7201/api/v1/topic/init -d '{
    76      "numberOfShards": 64
    77  }'
    78  
    79  if [[ "$M3AGGREGATOR_DEV_IMG" == "0" ]] || [[ "$FORCE_BUILD" == true ]] || [[ "$BUILD_M3AGGREGATOR" == true ]]; then
    80      prepare_build_cmd "make m3aggregator-linux-amd64"
    81      echo "Building m3aggregator binary first"
    82      bash -c "$build_cmd"
    83  
    84      docker-compose -f docker-compose.yml up --build $DOCKER_ARGS m3aggregator01
    85  else
    86      docker-compose -f docker-compose.yml up $DOCKER_ARGS m3aggregator01
    87  fi
    88  
    89  echo "Initializing M3Coordinator topology"
    90  curl -vvvsSf -X POST localhost:7201/api/v1/services/m3coordinator/placement/init -d '{
    91      "instances": [
    92          {
    93              "id": "m3coordinator01",
    94              "zone": "embedded",
    95              "endpoint": "m3coordinator01:7507",
    96              "hostname": "m3coordinator01",
    97              "port": 7507
    98          }
    99      ]
   100  }'
   101  echo "Done initializing M3Coordinator topology"
   102  
   103  echo "Validating M3Coordinator topology"
   104  [ "$(curl -sSf localhost:7201/api/v1/services/m3coordinator/placement | jq .placement.instances.m3coordinator01.id)" == '"m3coordinator01"' ]
   105  echo "Done validating topology"
   106  
   107  # Do this after placement for m3coordinator is created.
   108  echo "Adding coordinator as a consumer to the aggregator outbound topic"
   109  curl -vvvsSf -X POST -H "Topic-Name: aggregated_metrics" -H "Cluster-Environment-Name: default_env" localhost:7201/api/v1/topic -d '{
   110      "consumerService": {
   111              "serviceId": {
   112              "name": "m3coordinator",
   113              "environment": "default_env",
   114              "zone": "embedded"
   115          },
   116          "consumptionType": "SHARED",
   117          "messageTtlNanos": "600000000000"
   118      }
   119  }' # msgs will be discarded after 600000000000ns = 10mins
   120  
   121  # Restart with aggregator coordinator config
   122  docker-compose -f docker-compose.yml stop m3coordinator01
   123  
   124  # Note: Use ".tmp" suffix to be git ignored.
   125  cp ./m3coordinator.yml ./m3coordinator.yml.tmp
   126  
   127  docker-compose -f docker-compose.yml up $DOCKER_ARGS m3coordinator01
   128  
   129  ./emit_scrape_configs.sh
   130  
   131  echo "Starting Prometheus"
   132  if [[ "$FORCE_BUILD" == true ]] || [[ "$BUILD_PROMETHEUS" == true ]]; then
   133      docker-compose -f docker-compose.yml up --build $PROMETHEUS_DOCKER_ARGS prometheusraw
   134  else
   135      docker-compose -f docker-compose.yml up $PROMETHEUS_DOCKER_ARGS prometheusraw
   136  fi
   137  docker-compose -f docker-compose.yml up $PROMETHEUS_DOCKER_ARGS prometheusagg
   138  docker-compose -f docker-compose.yml up $DOCKER_ARGS prometheusscraper
   139  
   140  echo "Starting Grafana"
   141  if [[ "$FORCE_BUILD" == true ]] || [[ "$BUILD_GRAFANA" == true ]]; then
   142      docker-compose -f docker-compose.yml up --build $DOCKER_ARGS grafana
   143  else
   144      docker-compose -f docker-compose.yml up $DOCKER_ARGS grafana
   145  fi
   146  
   147  echo "Grafana available at localhost:3000"
   148  echo "Run ./stop.sh to shutdown nodes when done"