Skip to content

Commit ae0e587

Browse files
committed
Remove unused resource field
1 parent 6065c08 commit ae0e587

File tree

15 files changed

+11
-412
lines changed

15 files changed

+11
-412
lines changed

lambdas/collector/__tests__/fingerprint.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,6 @@ describe('generateFingerprint', () => {
4848
expect(modifiedFingerprint).not.toBe(baseFingerprint);
4949
});
5050

51-
it('should change fingerprint when resource changes', () => {
52-
const baseAlert = testAlertEvents.grafanaFiring;
53-
const modifiedAlert = {
54-
...baseAlert,
55-
resource: { ...baseAlert.resource, id: 'different-id' }
56-
};
57-
58-
const baseFingerprint = generateFingerprint(baseAlert);
59-
const modifiedFingerprint = generateFingerprint(modifiedAlert);
60-
61-
expect(modifiedFingerprint).not.toBe(baseFingerprint);
62-
});
6351

6452
it('should be consistent across state changes', () => {
6553
const firingAlert = testAlertEvents.grafanaFiring;

lambdas/collector/__tests__/transformers/base.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class TestTransformer extends BaseTransformer {
1616
priority: this.extractPriority(rawPayload.priority),
1717
occurred_at: this.parseTimestamp(rawPayload.timestamp),
1818
team: this.extractTeam(rawPayload.team),
19-
resource: { type: 'generic' },
2019
identity: { org_id: '', rule_id: '' },
2120
links: {},
2221
raw_provider: rawPayload,

lambdas/collector/__tests__/transformers/cloudwatch.test.ts

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ describe('CloudWatchTransformer', () => {
2727
title: 'High CPU Usage',
2828
priority: 'P2',
2929
team: 'platform',
30-
resource: {
31-
type: 'instance',
32-
id: 'i-1234567890abcdef0',
33-
region: 'us-east-1',
34-
},
3530
identity: {
3631
aws_account: '123456789012',
3732
region: 'us-east-1',
@@ -110,64 +105,8 @@ describe('CloudWatchTransformer', () => {
110105
expect(result.description).toBe('Custom description');
111106
});
112107

113-
it('should extract resource type from namespace', () => {
114-
const testCases = [
115-
{ namespace: 'AWS/AutoScaling', expected: 'instance' },
116-
{ namespace: 'AWS/EC2', expected: 'instance' },
117-
{ namespace: 'AWS/ECS', expected: 'service' },
118-
{ namespace: 'AWS/Lambda', expected: 'service' },
119-
];
120-
121-
testCases.forEach(({ namespace, expected }) => {
122-
const alarmData = JSON.parse(testCloudWatchPayloads.alarm.Message);
123-
const customAlarm = {
124-
...testCloudWatchPayloads.alarm,
125-
Message: JSON.stringify({
126-
...alarmData,
127-
AlarmDescription: 'TEAM=platform | PRIORITY=P2',
128-
Trigger: {
129-
...alarmData.Trigger,
130-
Namespace: namespace,
131-
},
132-
}),
133-
};
134-
135-
const result = transformer.transform(customAlarm, mockEnvelope);
136-
expect(result.resource.type).toBe(expected);
137-
});
138-
});
139108

140-
it('should extract resource ID from dimensions', () => {
141-
const alarmData = JSON.parse(testCloudWatchPayloads.alarm.Message);
142-
const customAlarm = {
143-
...testCloudWatchPayloads.alarm,
144-
Message: JSON.stringify({
145-
...alarmData,
146-
Trigger: {
147-
...alarmData.Trigger,
148-
Dimensions: [
149-
{ name: 'AutoScalingGroupName', value: 'my-asg' },
150-
{ name: 'InstanceId', value: 'i-1234567890abcdef0' },
151-
],
152-
},
153-
}),
154-
};
155109

156-
const result = transformer.transform(customAlarm, mockEnvelope);
157-
expect(result.resource.id).toBe('my-asg'); // Should prefer AutoScalingGroupName
158-
});
159-
160-
it('should build resource extra information', () => {
161-
const result = transformer.transform(testCloudWatchPayloads.alarm, mockEnvelope);
162-
163-
expect(result.resource.extra).toMatchObject({
164-
metric_name: 'CPUUtilization',
165-
namespace: 'AWS/EC2',
166-
statistic: 'AVERAGE',
167-
threshold: 80.0,
168-
comparison_operator: 'GreaterThanThreshold',
169-
});
170-
});
171110

172111
it('should extract region from ARN correctly', () => {
173112
const alarmData = JSON.parse(testCloudWatchPayloads.alarm.Message);
@@ -181,25 +120,9 @@ describe('CloudWatchTransformer', () => {
181120

182121
const result = transformer.transform(customAlarm, mockEnvelope);
183122

184-
expect(result.resource.region).toBe('eu-west-1');
185123
expect(result.identity.region).toBe('eu-west-1');
186124
});
187125

188-
it('should normalize region names to codes', () => {
189-
const alarmData = JSON.parse(testCloudWatchPayloads.alarm.Message);
190-
const customAlarm = {
191-
...testCloudWatchPayloads.alarm,
192-
Message: JSON.stringify({
193-
...alarmData,
194-
Region: 'US West - Oregon',
195-
AlarmArn: undefined, // No ARN, should use region name
196-
}),
197-
};
198-
199-
const result = transformer.transform(customAlarm, mockEnvelope);
200-
201-
expect(result.resource.region).toBe('us-west-2');
202-
});
203126

204127
it('should build console URL correctly', () => {
205128
const result = transformer.transform(testCloudWatchPayloads.alarm, mockEnvelope);

lambdas/collector/__tests__/transformers/grafana.test.ts

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ describe('GrafanaTransformer', () => {
2828
description: 'Test alert description',
2929
priority: 'P1',
3030
team: 'dev-infra',
31-
resource: {
32-
type: 'runner',
33-
id: 'test-runner',
34-
},
3531
identity: {
3632
org_id: '1',
3733
rule_id: 'abc123',
@@ -136,34 +132,6 @@ describe('GrafanaTransformer', () => {
136132
expect(result.occurred_at).toBe('2025-09-16T10:30:00.000Z');
137133
});
138134

139-
it('should build resource information correctly', () => {
140-
const payload = {
141-
...testGrafanaPayloads.firing,
142-
alerts: [{
143-
...testGrafanaPayloads.firing.alerts[0],
144-
labels: {
145-
alertname: 'Test Alert',
146-
resource_type: 'service',
147-
resource_id: 'web-service-1',
148-
region: 'us-west-2',
149-
environment: 'production',
150-
version: '1.2.3',
151-
},
152-
}],
153-
};
154-
155-
const result = transformer.transform(payload, mockEnvelope);
156-
157-
expect(result.resource).toMatchObject({
158-
type: 'service',
159-
id: 'web-service-1',
160-
region: 'us-west-2',
161-
extra: {
162-
environment: 'production',
163-
version: '1.2.3',
164-
},
165-
});
166-
});
167135

168136
it('should build identity information', () => {
169137
const payload = {
@@ -270,31 +238,6 @@ describe('GrafanaTransformer', () => {
270238
// These would be better as integration tests
271239
});
272240

273-
describe('resource type extraction', () => {
274-
it('should map known resource types', () => {
275-
const testCases = [
276-
{ resource_type: 'runner', expected: 'runner' },
277-
{ resource_type: 'instance', expected: 'instance' },
278-
{ resource_type: 'job', expected: 'job' },
279-
{ resource_type: 'service', expected: 'service' },
280-
{ resource_type: 'RUNNER', expected: 'runner' }, // Case insensitive
281-
{ resource_type: 'unknown-type', expected: 'generic' }, // Fallback
282-
];
283-
284-
testCases.forEach(({ resource_type, expected }) => {
285-
const payload = {
286-
...testGrafanaPayloads.firing,
287-
alerts: [{
288-
...testGrafanaPayloads.firing.alerts[0],
289-
labels: { alertname: 'Test', resource_type },
290-
}],
291-
};
292-
293-
const result = transformer.transform(payload, mockEnvelope);
294-
expect(result.resource.type).toBe(expected);
295-
});
296-
});
297-
});
298241

299242
describe('data sanitization', () => {
300243
it('should sanitize description and reason fields', () => {

lambdas/collector/__tests__/transformers/normalized.test.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ describe("NormalizedTransformer", () => {
1616
priority: "P1",
1717
occurred_at: "2024-01-15T10:30:00.000Z",
1818
team: "platform-team",
19-
resource: {
20-
type: "instance",
21-
id: "i-1234567890abcdef0",
22-
region: "us-west-2",
23-
extra: {
24-
instance_type: "m5.large"
25-
}
26-
},
2719
identity: {
2820
aws_account: "123456789012",
2921
region: "us-west-2",
@@ -156,18 +148,6 @@ describe("NormalizedTransformer", () => {
156148
.toThrow(/AlertEvent validation failed/);
157149
});
158150

159-
it("should throw error for invalid resource structure", () => {
160-
const invalidAlerts = [
161-
{ ...validNormalizedAlert, resource: null },
162-
{ ...validNormalizedAlert, resource: "string" },
163-
{ ...validNormalizedAlert, resource: {} } // missing type
164-
];
165-
166-
invalidAlerts.forEach((alert) => {
167-
expect(() => transformer.transform(alert, mockEnvelope))
168-
.toThrow(/AlertEvent validation failed/);
169-
});
170-
});
171151

172152
it("should throw error for invalid identity structure", () => {
173153
const invalidAlerts = [
@@ -256,21 +236,6 @@ describe("NormalizedTransformer", () => {
256236
expect(result.raw_provider).toEqual({});
257237
});
258238

259-
it("should handle missing optional resource fields", () => {
260-
const alert = {
261-
...validNormalizedAlert,
262-
resource: {
263-
type: "generic"
264-
// id, region, extra are optional
265-
}
266-
};
267-
const result = transformer.transform(alert, mockEnvelope);
268-
269-
expect(result.resource.type).toBe("generic");
270-
expect(result.resource.id).toBeUndefined();
271-
expect(result.resource.region).toBeUndefined();
272-
expect(result.resource.extra).toBeUndefined();
273-
});
274239

275240
it("should handle empty identity and links objects", () => {
276241
const alert = {

lambdas/collector/__tests__/transformers/source-detection.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ describe("Source Detection", () => {
4545
priority: "P1",
4646
occurred_at: "2024-01-15T10:30:00.000Z",
4747
team: "platform-team",
48-
resource: { type: "instance" },
4948
identity: {},
5049
links: {}
5150
};
@@ -148,7 +147,6 @@ describe("Source Detection", () => {
148147
priority: "P1",
149148
occurred_at: "2024-01-15T10:30:00.000Z",
150149
team: "platform-team",
151-
resource: { type: "instance" },
152150
identity: {},
153151
links: {}
154152
};

lambdas/collector/__tests__/utils/schema-validator.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,13 @@ describe("Schema Validator", () => {
3232
.toThrow("AlertEvent validation failed");
3333
});
3434

35-
it("should allow missing resource field", () => {
36-
// Resource field should be optional since many alerts don't have meaningful resource info
37-
expect(() => validateNormalizedAlertEvent(validAlertEvent)).not.toThrow();
38-
});
3935

4036
it("should allow valid optional fields", () => {
4137
const alertWithOptionals: AlertEvent = {
4238
...validAlertEvent,
4339
description: "Test description",
4440
summary: "Test summary",
4541
reason: "Test reason",
46-
resource: {
47-
type: "instance",
48-
id: "i-123456",
49-
region: "us-west-2",
50-
extra: {
51-
instance_type: "m5.large",
52-
tags: ["prod", "web"]
53-
}
54-
},
5542
identity: {
5643
aws_account: "123456789012",
5744
region: "us-west-2",

lambdas/collector/__tests__/utils/test-fixtures.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ export const testAlertEvents = {
3636
priority: 'P1' as const,
3737
occurred_at: '2025-09-16T12:00:00.000Z',
3838
team: 'dev-infra',
39-
resource: {
40-
type: 'runner' as const,
41-
id: 'test-runner',
42-
region: 'us-east-1',
43-
},
4439
identity: {
4540
org_id: '1',
4641
rule_id: 'test-rule-123',
@@ -63,11 +58,6 @@ export const testAlertEvents = {
6358
priority: 'P1' as const,
6459
occurred_at: '2025-09-16T12:05:00.000Z',
6560
team: 'dev-infra',
66-
resource: {
67-
type: 'runner' as const,
68-
id: 'test-runner',
69-
region: 'us-east-1',
70-
},
7161
identity: {
7262
org_id: '1',
7363
rule_id: 'test-rule-123',
@@ -90,11 +80,6 @@ export const testAlertEvents = {
9080
priority: 'P2' as const,
9181
occurred_at: '2025-09-16T12:00:00.000Z',
9282
team: 'platform',
93-
resource: {
94-
type: 'instance' as const,
95-
id: 'i-1234567890abcdef0',
96-
region: 'us-east-1',
97-
},
9883
identity: {
9984
org_id: '123456789012',
10085
rule_id: 'arn:aws:cloudwatch:us-east-1:123456789012:alarm:HighCPU',
@@ -117,8 +102,6 @@ export const testGrafanaPayloads = {
117102
status: 'firing',
118103
labels: {
119104
alertname: 'Test Alert',
120-
resource_type: 'runner',
121-
resource_id: 'test-runner',
122105
},
123106
annotations: {
124107
Priority: 'P1',
@@ -154,8 +137,6 @@ export const testGrafanaPayloads = {
154137
status: 'resolved',
155138
labels: {
156139
alertname: 'Test Alert',
157-
resource_type: 'runner',
158-
resource_id: 'test-runner',
159140
},
160141
annotations: {
161142
Priority: 'P1',

0 commit comments

Comments
 (0)