@spinnaker/titus 0.4.8 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ import { IAmazonServerGroup, IScalingPolicy, IStepPolicyDescription, ITargetTrackingPolicy, IUpsertAlarmDescription, IUpsertScalingPolicyCommand } from '@spinnaker/amazon';
2
+ declare type PolicyType = 'Step' | 'TargetTracking';
3
+ export declare const TitusScalingPolicyCommandBuilder: {
4
+ buildAlarm: (policy: IScalingPolicy, region: string) => IUpsertAlarmDescription;
5
+ buildStepPolicy: (policy: IScalingPolicy, threshold: number, cooldown: number) => IStepPolicyDescription;
6
+ buildNewCommand: (type: PolicyType, serverGroup: IAmazonServerGroup, policy: ITargetTrackingPolicy) => IUpsertScalingPolicyCommand;
7
+ prepareCommandForUpsert: (command: IUpsertScalingPolicyCommand, isRemove: boolean) => IUpsertScalingPolicyCommand;
8
+ };
9
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@spinnaker/titus",
3
3
  "license": "Apache-2.0",
4
- "version": "0.4.8",
4
+ "version": "0.5.3",
5
5
  "module": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "scripts": {
@@ -13,9 +13,9 @@
13
13
  "lib": "npm run build"
14
14
  },
15
15
  "dependencies": {
16
- "@spinnaker/amazon": "^0.8.5",
17
- "@spinnaker/core": "^0.9.1",
18
- "@spinnaker/docker": "^0.0.105",
16
+ "@spinnaker/amazon": "^0.8.9",
17
+ "@spinnaker/core": "^0.11.2",
18
+ "@spinnaker/docker": "^0.0.109",
19
19
  "@spinnaker/mocks": "1.0.7",
20
20
  "@uirouter/angularjs": "1.0.26",
21
21
  "@uirouter/react": "1.0.7",
@@ -44,5 +44,5 @@
44
44
  "shx": "0.3.3",
45
45
  "typescript": "4.3.5"
46
46
  },
47
- "gitHead": "7a3e89eee4e351ae7177bc77de642c9fd54788ff"
47
+ "gitHead": "de4f3f2b9379e8e4ec9ab20bfe69a4e566a48cf3"
48
48
  }
@@ -0,0 +1,119 @@
1
+ import { cloneDeep } from 'lodash';
2
+
3
+ import {
4
+ IAmazonServerGroup,
5
+ IScalingPolicy,
6
+ IScalingPolicyAlarmView,
7
+ IStepAdjustment,
8
+ IStepPolicyDescription,
9
+ ITargetTrackingPolicy,
10
+ IUpsertAlarmDescription,
11
+ IUpsertScalingPolicyCommand,
12
+ } from '@spinnaker/amazon';
13
+
14
+ type PolicyType = 'Step' | 'TargetTracking';
15
+
16
+ export const TitusScalingPolicyCommandBuilder = {
17
+ buildAlarm: (policy: IScalingPolicy, region: string): IUpsertAlarmDescription => {
18
+ const alarm = policy?.alarms[0] as IScalingPolicyAlarmView;
19
+ return {
20
+ comparisonOperator: alarm.comparisonOperator,
21
+ region,
22
+ dimensions: alarm.dimensions,
23
+ disableEditingDimensions: alarm.disableEditingDimensions,
24
+ evaluationPeriods: alarm.evaluationPeriods,
25
+ metricName: alarm.metricName,
26
+ namespace: alarm.namespace,
27
+ period: alarm.period,
28
+ statistic: alarm.statistic,
29
+ threshold: alarm.threshold,
30
+ unit: alarm.unit,
31
+ } as IUpsertAlarmDescription;
32
+ },
33
+
34
+ buildStepPolicy: (policy: IScalingPolicy, threshold: number, cooldown: number): IStepPolicyDescription => {
35
+ const stepAdjustments = policy.stepAdjustments.map((adjustment) => {
36
+ const step = {
37
+ scalingAdjustment: Math.abs(adjustment.scalingAdjustment),
38
+ } as IStepAdjustment;
39
+
40
+ if (adjustment.metricIntervalUpperBound !== undefined) {
41
+ step.metricIntervalUpperBound = adjustment.metricIntervalUpperBound + threshold;
42
+ }
43
+ if (adjustment.metricIntervalLowerBound !== undefined) {
44
+ step.metricIntervalLowerBound = adjustment.metricIntervalLowerBound + threshold;
45
+ }
46
+
47
+ return step;
48
+ });
49
+
50
+ return {
51
+ cooldown: cooldown || 600,
52
+ estimatedInstanceWarmup: cooldown || 600,
53
+ metricAggregationType: 'Average',
54
+ stepAdjustments,
55
+ };
56
+ },
57
+
58
+ buildNewCommand: (
59
+ type: PolicyType,
60
+ serverGroup: IAmazonServerGroup,
61
+ policy: ITargetTrackingPolicy,
62
+ ): IUpsertScalingPolicyCommand => {
63
+ const command = {
64
+ adjustmentType: type === 'Step' ? policy.adjustmentType : null,
65
+ cloudProvider: serverGroup.cloudProvider,
66
+ credentials: serverGroup.account,
67
+ jobId: serverGroup.disabledDate,
68
+ name: policy.id,
69
+ region: serverGroup.region,
70
+ scalingPolicyID: policy.id,
71
+ serverGroupName: serverGroup.name,
72
+ } as IUpsertScalingPolicyCommand;
73
+
74
+ if (type === 'Step') {
75
+ command.alarm = TitusScalingPolicyCommandBuilder.buildAlarm(policy, serverGroup.region);
76
+ command.minAdjustmentMagnitude = policy.minAdjustmentMagnitude || 1;
77
+ command.step = TitusScalingPolicyCommandBuilder.buildStepPolicy(
78
+ policy,
79
+ command.alarm.threshold,
80
+ command.cooldown,
81
+ );
82
+ }
83
+
84
+ if (type === 'TargetTracking') {
85
+ command.targetTrackingConfiguration = { ...policy.targetTrackingConfiguration };
86
+ }
87
+
88
+ return command;
89
+ },
90
+
91
+ prepareCommandForUpsert: (command: IUpsertScalingPolicyCommand, isRemove: boolean): IUpsertScalingPolicyCommand => {
92
+ const commandToSubmit = cloneDeep(command);
93
+
94
+ if (commandToSubmit.adjustmentType !== 'PercentChangeInCapacity') {
95
+ delete commandToSubmit.minAdjustmentMagnitude;
96
+ }
97
+
98
+ if (commandToSubmit.step) {
99
+ // adjust metricIntervalLowerBound/UpperBound for each step based on alarm threshold
100
+ commandToSubmit.step.stepAdjustments.forEach((step) => {
101
+ if (isRemove) {
102
+ step.scalingAdjustment = 0 - step.scalingAdjustment;
103
+ delete commandToSubmit.step.estimatedInstanceWarmup;
104
+ }
105
+ if (step.metricIntervalLowerBound !== undefined) {
106
+ step.metricIntervalLowerBound -= commandToSubmit.alarm.threshold;
107
+ }
108
+ if (step.metricIntervalUpperBound !== undefined) {
109
+ step.metricIntervalUpperBound -= commandToSubmit.alarm.threshold;
110
+ }
111
+ });
112
+ } else {
113
+ if (isRemove) {
114
+ command.simple.scalingAdjustment = 0 - command.simple.scalingAdjustment;
115
+ }
116
+ }
117
+ return commandToSubmit;
118
+ },
119
+ };
@@ -107,6 +107,10 @@ module(TITUS_SERVERGROUP_DETAILS_SCALINGPOLICY_UPSERT_UPSERTSCALINGPOLICY_CONTRO
107
107
  this.boundsChanged();
108
108
  };
109
109
 
110
+ this.alarmChanged = (newAlarm) => {
111
+ this.command.alarm = newAlarm;
112
+ };
113
+
110
114
  this.adjustmentTypeChanged = (action, type) => {
111
115
  this.viewState.operator = action;
112
116
  this.viewState.adjustmentType = type;
@@ -13,16 +13,18 @@
13
13
  see a metric below, click "Configure available metrics" in the server group details to set up forwarding from
14
14
  Atlas to CloudWatch.
15
15
  </p>
16
- <aws-alarm-configurer
17
- command="ctrl.command"
18
- modal-view-state="ctrl.viewState"
16
+ <alarm-configurer
17
+ alarm="ctrl.command.alarm"
18
+ multiple-alarms="ctrl.viewState.multipleAlarms"
19
19
  server-group="ctrl.alarmServerGroup"
20
- bounds-changed="ctrl.boundsChanged()"
21
- ></aws-alarm-configurer>
20
+ step-adjustments="ctrl.command.step.stepAdjustments"
21
+ steps-changed="ctrl.stepsChanged"
22
+ update-alarm="ctrl.alarmChanged"
23
+ ></alarm-configurer>
22
24
  </div>
23
25
 
24
26
  <h4 class="section-heading">Actions</h4>
25
- <div class="section-body" ng-if="!ctrl.command.alarm.metricName">
27
+ <div class="section-body" ng-if="!ctrl.command.alarm.metricName && !ctrl.command.alarm.name">
26
28
  <h4 class="text-center">Select a metric</h4>
27
29
  </div>
28
30
  <div class="section-body" ng-if="ctrl.command.alarm.metricName">