Search in sources :

Example 1 with AlarmConfiguration

use of com.netflix.titus.api.appscale.model.AlarmConfiguration in project titus-control-plane by Netflix.

the class CloudWatchClient method createOrUpdateAlarm.

@Override
public Observable<String> createOrUpdateAlarm(String policyRefId, String jobId, AlarmConfiguration alarmConfiguration, String autoScalingGroup, List<String> actions) {
    List<Dimension> metricDimensions = buildMetricDimensions(alarmConfiguration, autoScalingGroup);
    String cloudWatchName = buildCloudWatchName(policyRefId, jobId);
    PutMetricAlarmRequest putMetricAlarmRequest = new PutMetricAlarmRequest();
    if (alarmConfiguration.getActionsEnabled().isPresent()) {
        putMetricAlarmRequest.setActionsEnabled(alarmConfiguration.getActionsEnabled().get());
    }
    putMetricAlarmRequest.setAlarmActions(actions);
    putMetricAlarmRequest.setAlarmName(cloudWatchName);
    putMetricAlarmRequest.setDimensions(metricDimensions);
    putMetricAlarmRequest.setNamespace(alarmConfiguration.getMetricNamespace());
    putMetricAlarmRequest.setComparisonOperator(alarmConfiguration.getComparisonOperator().name());
    putMetricAlarmRequest.setStatistic(alarmConfiguration.getStatistic().name());
    putMetricAlarmRequest.setEvaluationPeriods(alarmConfiguration.getEvaluationPeriods());
    putMetricAlarmRequest.setPeriod(alarmConfiguration.getPeriodSec());
    putMetricAlarmRequest.setThreshold(alarmConfiguration.getThreshold());
    putMetricAlarmRequest.setMetricName(alarmConfiguration.getMetricName());
    return wrapWithExponentialRetry(String.format("createOrUpdateAlarm in policy %s for job %s", policyRefId, jobId), Observable.create(emitter -> awsCloudWatch.putMetricAlarmAsync(putMetricAlarmRequest, new AsyncHandler<PutMetricAlarmRequest, PutMetricAlarmResult>() {

        @Override
        public void onError(Exception exception) {
            createErrorCounter.increment();
            emitter.onError(AutoScalePolicyException.errorCreatingAlarm(policyRefId, exception.getMessage()));
        }

        @Override
        public void onSuccess(PutMetricAlarmRequest request, PutMetricAlarmResult putMetricAlarmResult) {
            int httpStatusCode = putMetricAlarmResult.getSdkHttpMetadata().getHttpStatusCode();
            log.info("Created Cloud Watch Alarm {} for {} - status {}", request, jobId, httpStatusCode);
            // TODO : how to get ARN created by AWS for this resource ? returning cloudWatchName for now
            createAlarmCounter.increment();
            emitter.onNext(cloudWatchName);
            emitter.onCompleted();
        }
    }), Emitter.BackpressureMode.NONE));
}
Also used : AmazonCloudWatchAsyncClientBuilder(com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClientBuilder) AutoScalePolicyException(com.netflix.titus.api.appscale.service.AutoScalePolicyException) Completable(rx.Completable) Arrays(java.util.Arrays) DeleteAlarmsResult(com.amazonaws.services.cloudwatch.model.DeleteAlarmsResult) ResourceNotFoundException(com.amazonaws.services.cloudwatch.model.ResourceNotFoundException) Counter(com.netflix.spectator.api.Counter) LoggerFactory(org.slf4j.LoggerFactory) PutMetricAlarmResult(com.amazonaws.services.cloudwatch.model.PutMetricAlarmResult) CloudAlarmClient(com.netflix.titus.api.connector.cloud.CloudAlarmClient) Singleton(javax.inject.Singleton) AmazonCloudWatchAsync(com.amazonaws.services.cloudwatch.AmazonCloudWatchAsync) ArrayList(java.util.ArrayList) Observable(rx.Observable) Inject(javax.inject.Inject) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) MetricDimension(com.netflix.titus.api.appscale.model.MetricDimension) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) DeleteAlarmsRequest(com.amazonaws.services.cloudwatch.model.DeleteAlarmsRequest) AlarmConfiguration(com.netflix.titus.api.appscale.model.AlarmConfiguration) Logger(org.slf4j.Logger) Emitter(rx.Emitter) List(java.util.List) PutMetricAlarmRequest(com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest) AwsConfiguration(com.netflix.titus.ext.aws.AwsConfiguration) AsyncHandler(com.amazonaws.handlers.AsyncHandler) Registry(com.netflix.spectator.api.Registry) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RetryWrapper.wrapWithExponentialRetry(com.netflix.titus.ext.aws.RetryWrapper.wrapWithExponentialRetry) PutMetricAlarmResult(com.amazonaws.services.cloudwatch.model.PutMetricAlarmResult) PutMetricAlarmRequest(com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) MetricDimension(com.netflix.titus.api.appscale.model.MetricDimension) AutoScalePolicyException(com.netflix.titus.api.appscale.service.AutoScalePolicyException) ResourceNotFoundException(com.amazonaws.services.cloudwatch.model.ResourceNotFoundException)

Example 2 with AlarmConfiguration

use of com.netflix.titus.api.appscale.model.AlarmConfiguration in project titus-control-plane by Netflix.

the class CloudWatchClientTest method buildDefaultMetricDimensions.

@Test
public void buildDefaultMetricDimensions() {
    AlarmConfiguration alarmConfiguration = getAlarmConfigBuilder().build();
    List<Dimension> dimensions = CloudWatchClient.buildMetricDimensions(alarmConfiguration, "foo-bar");
    assertThat(dimensions).isNotNull();
    assertThat(dimensions.size()).isEqualTo(1);
    assertThat(dimensions.get(0).getName()).isEqualTo("AutoScalingGroupName");
    assertThat(dimensions.get(0).getValue()).isEqualTo("foo-bar");
}
Also used : AlarmConfiguration(com.netflix.titus.api.appscale.model.AlarmConfiguration) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) MetricDimension(com.netflix.titus.api.appscale.model.MetricDimension) Test(org.junit.Test)

Example 3 with AlarmConfiguration

use of com.netflix.titus.api.appscale.model.AlarmConfiguration in project titus-control-plane by Netflix.

the class CassAppScalePolicyStoreTest method buildAutoScalingPolicy.

private AutoScalingPolicy buildAutoScalingPolicy(String jobId) {
    AlarmConfiguration alarmConfiguration = AlarmConfiguration.newBuilder().withActionsEnabled(true).withComparisonOperator(ComparisonOperator.GreaterThanThreshold).withEvaluationPeriods(1).withPeriodSec(60).withMetricName("CPUUtilization").withMetricNamespace("AWS/EC2").withName(jobId).withStatistic(Statistic.Average).build();
    StepAdjustment stepAdjustment = StepAdjustment.newBuilder().withMetricIntervalLowerBound(0).withScalingAdjustment(1).build();
    StepScalingPolicyConfiguration stepScalingPolicyConfiguration = StepScalingPolicyConfiguration.newBuilder().withAdjustmentType(StepAdjustmentType.ChangeInCapacity).withCoolDownSec(60).withMetricAggregatorType(MetricAggregationType.Average).withMinAdjustmentMagnitude(1).withSteps(Arrays.asList(stepAdjustment)).build();
    PolicyConfiguration policyConfiguration = PolicyConfiguration.newBuilder().withAlarmConfiguration(alarmConfiguration).withStepScalingPolicyConfiguration(stepScalingPolicyConfiguration).withPolicyType(PolicyType.StepScaling).withName(jobId).build();
    AutoScalingPolicy autoScalingPolicy = AutoScalingPolicy.newBuilder().withPolicyConfiguration(policyConfiguration).withStatus(PolicyStatus.Pending).withStatusMessage("ICE-ed by AWS").withJobId(jobId).build();
    return autoScalingPolicy;
}
Also used : AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) AlarmConfiguration(com.netflix.titus.api.appscale.model.AlarmConfiguration) StepScalingPolicyConfiguration(com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration) PolicyConfiguration(com.netflix.titus.api.appscale.model.PolicyConfiguration) StepAdjustment(com.netflix.titus.api.appscale.model.StepAdjustment) StepScalingPolicyConfiguration(com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration)

Example 4 with AlarmConfiguration

use of com.netflix.titus.api.appscale.model.AlarmConfiguration in project titus-control-plane by Netflix.

the class CassAppScalePolicyStoreTest method checkSerialization.

@Test
public void checkSerialization() throws Exception {
    AlarmConfiguration alarmConfiguration = AlarmConfiguration.newBuilder().withActionsEnabled(true).withComparisonOperator(ComparisonOperator.GreaterThanThreshold).withEvaluationPeriods(1).withPeriodSec(60).withThreshold(2.5).withMetricName("CPUUtilization").withMetricNamespace("AWS/EC2").withName("job-1").withStatistic(Statistic.Average).build();
    String serializedValue = ObjectMappers.appScalePolicyMapper().writeValueAsString(alarmConfiguration);
    alarmConfiguration = ObjectMappers.appScalePolicyMapper().readValue(serializedValue.getBytes(), AlarmConfiguration.class);
    Assertions.assertThat(alarmConfiguration.getName()).isEqualTo("job-1");
}
Also used : AlarmConfiguration(com.netflix.titus.api.appscale.model.AlarmConfiguration) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Example 5 with AlarmConfiguration

use of com.netflix.titus.api.appscale.model.AlarmConfiguration in project titus-control-plane by Netflix.

the class CloudWatchClientTest method buildCustomMetricDimensions.

@Test
public void buildCustomMetricDimensions() {
    MetricDimension md1 = MetricDimension.newBuilder().withName("foo").withValue("bar").build();
    MetricDimension md2 = MetricDimension.newBuilder().withName("service-tier").withValue("1").build();
    List<MetricDimension> customMetricDimensions = Arrays.asList(md1, md2);
    AlarmConfiguration alarmConfiguration = getAlarmConfigBuilder().withDimensions(customMetricDimensions).build();
    List<Dimension> dimensions = CloudWatchClient.buildMetricDimensions(alarmConfiguration, "foo-bar");
    assertThat(dimensions).isNotNull();
    assertThat(dimensions.size()).isEqualTo(2);
    assertThat(dimensions.get(0).getName()).isEqualTo("foo");
    assertThat(dimensions.get(0).getValue()).isEqualTo("bar");
    assertThat(dimensions.get(1).getName()).isEqualTo("service-tier");
    assertThat(dimensions.get(1).getValue()).isEqualTo("1");
}
Also used : AlarmConfiguration(com.netflix.titus.api.appscale.model.AlarmConfiguration) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) MetricDimension(com.netflix.titus.api.appscale.model.MetricDimension) MetricDimension(com.netflix.titus.api.appscale.model.MetricDimension) Test(org.junit.Test)

Aggregations

AlarmConfiguration (com.netflix.titus.api.appscale.model.AlarmConfiguration)7 Test (org.junit.Test)4 Dimension (com.amazonaws.services.cloudwatch.model.Dimension)3 AutoScalingPolicy (com.netflix.titus.api.appscale.model.AutoScalingPolicy)3 MetricDimension (com.netflix.titus.api.appscale.model.MetricDimension)3 PolicyConfiguration (com.netflix.titus.api.appscale.model.PolicyConfiguration)3 StepScalingPolicyConfiguration (com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration)3 StepAdjustment (com.netflix.titus.api.appscale.model.StepAdjustment)2 IntegrationNotParallelizableTest (com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 AsyncHandler (com.amazonaws.handlers.AsyncHandler)1 AmazonCloudWatchAsync (com.amazonaws.services.cloudwatch.AmazonCloudWatchAsync)1 AmazonCloudWatchAsyncClientBuilder (com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClientBuilder)1 DeleteAlarmsRequest (com.amazonaws.services.cloudwatch.model.DeleteAlarmsRequest)1 DeleteAlarmsResult (com.amazonaws.services.cloudwatch.model.DeleteAlarmsResult)1 PutMetricAlarmRequest (com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest)1 PutMetricAlarmResult (com.amazonaws.services.cloudwatch.model.PutMetricAlarmResult)1 ResourceNotFoundException (com.amazonaws.services.cloudwatch.model.ResourceNotFoundException)1 BoundStatement (com.datastax.driver.core.BoundStatement)1 ResultSet (com.datastax.driver.core.ResultSet)1