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));
}
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");
}
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;
}
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");
}
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");
}
Aggregations