Skip to content

Commit 2089ded

Browse files
authored
Fix: terraform export fixes (#1070)
* fix: terraform check capabilities * fix: add frequency and timeout to terraform export * fix: conditionally add validate fields for terraform dns checks * fix: tests and props syntax
1 parent efb5d42 commit 2089ded

File tree

4 files changed

+45
-19
lines changed

4 files changed

+45
-19
lines changed

‎src/components/TerraformConfig/terraformConfigUtils.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,27 @@ const settingsToTF = (check: Check): TFCheckSettings => {
8888
record_type: check.settings.dns.recordType,
8989
protocol: check.settings.dns.protocol,
9090
valid_r_codes: check.settings.dns.validRCodes,
91-
validate_answer_rrs: {
92-
fail_if_matches_regexp: check.settings.dns.validateAnswerRRS?.failIfMatchesRegexp,
93-
fail_if_not_matches_regexp: check.settings.dns.validateAnswerRRS?.failIfNotMatchesRegexp,
94-
},
95-
validate_authority_rrs: {
96-
fail_if_matches_regexp: check.settings.dns.validateAuthorityRRS?.failIfMatchesRegexp,
97-
fail_if_not_matches_regexp: check.settings.dns.validateAuthorityRRS?.failIfNotMatchesRegexp,
98-
},
99-
validate_additional_rrs: {
100-
fail_if_matches_regexp: check.settings.dns.validateAdditionalRRS?.failIfMatchesRegexp,
101-
fail_if_not_matches_regexp: check.settings.dns.validateAdditionalRRS?.failIfNotMatchesRegexp,
102-
},
91+
...((check.settings.dns.validateAnswerRRS?.failIfMatchesRegexp ||
92+
check.settings.dns.validateAnswerRRS?.failIfNotMatchesRegexp) && {
93+
validate_answer_rrs: {
94+
fail_if_matches_regexp: check.settings.dns.validateAnswerRRS.failIfMatchesRegexp,
95+
fail_if_not_matches_regexp: check.settings.dns.validateAnswerRRS.failIfNotMatchesRegexp,
96+
},
97+
}),
98+
...((check.settings.dns.validateAuthorityRRS?.failIfMatchesRegexp ||
99+
check.settings.dns.validateAuthorityRRS?.failIfNotMatchesRegexp) && {
100+
validate_authority_rrs: {
101+
fail_if_matches_regexp: check.settings.dns.validateAuthorityRRS.failIfMatchesRegexp,
102+
fail_if_not_matches_regexp: check.settings.dns.validateAuthorityRRS.failIfNotMatchesRegexp,
103+
},
104+
}),
105+
...((check.settings.dns.validateAdditionalRRS?.failIfMatchesRegexp ||
106+
check.settings.dns.validateAdditionalRRS?.failIfNotMatchesRegexp) && {
107+
validate_additional_rrs: {
108+
fail_if_matches_regexp: check.settings.dns.validateAdditionalRRS.failIfMatchesRegexp,
109+
fail_if_not_matches_regexp: check.settings.dns.validateAdditionalRRS.failIfNotMatchesRegexp,
110+
},
111+
}),
103112
},
104113
};
105114
}
@@ -181,6 +190,8 @@ export const checkToTF = (check: Check): TFCheck => {
181190
probes: check.probes,
182191
labels: labelsToTFLabels(check.labels),
183192
settings: settingsToTF(check),
193+
frequency: check.frequency,
194+
timeout: check.timeout,
184195
};
185196

186197
return tfCheck;
@@ -204,5 +215,6 @@ export const probeToTF = (probe: Probe): TFProbe => ({
204215
region: probe.region,
205216
public: false,
206217
labels: labelsToTFLabels(probe.labels),
207-
capabilities: probe.capabilities,
218+
disable_browser_checks: probe.capabilities.disableBrowserChecks,
219+
disable_scripted_checks: probe.capabilities.disableScriptedChecks,
208220
});

‎src/components/TerraformConfig/terraformTypes.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export interface TFCheck {
3838
probes: number[];
3939
labels: TFLabels;
4040
settings: TFCheckSettings;
41+
frequency: number;
42+
timeout: number;
4143
}
4244

4345
export type TFLabels = { [key: string]: string };
@@ -102,9 +104,9 @@ interface TFDnsSettings
102104
ip_version?: string;
103105
record_type?: string;
104106
valid_r_codes?: string[];
105-
validate_answer_rrs: TFFailIfMatchesNotMatches;
106-
validate_authority_rrs: TFFailIfMatchesNotMatches;
107-
validate_additional_rrs: TFFailIfMatchesNotMatches;
107+
validate_answer_rrs?: TFFailIfMatchesNotMatches;
108+
validate_authority_rrs?: TFFailIfMatchesNotMatches;
109+
validate_additional_rrs?: TFFailIfMatchesNotMatches;
108110
}
109111

110112
interface TFGRPCSettings extends Omit<GRPCSettings, 'ipVersion' | 'tlsConfig'> {
@@ -205,6 +207,8 @@ export interface TFProbeConfig {
205207
[key: string]: TFProbe;
206208
}
207209

208-
export interface TFProbe extends Omit<Probe, 'online' | 'onlineChange' | 'version' | 'deprecated' | 'labels'> {
210+
export interface TFProbe extends Omit<Probe, 'online' | 'onlineChange' | 'version' | 'deprecated' | 'labels' | 'capabilities'> {
209211
labels: TFLabels;
212+
disable_scripted_checks: boolean;
213+
disable_browser_checks: boolean;
210214
}

‎src/hooks/useTerraformConfig.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ describe('terraform config generation', () => {
109109
a_really_really_really_really_really_really_really_really_really_long_jobname_areallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongexample_com:
110110
{
111111
enabled: true,
112+
frequency: BASIC_PING_CHECK.frequency,
112113
job: 'a really really really really really really really really really long jobname',
113114
labels: {
114115
[BASIC_PING_CHECK.labels[0].name]: BASIC_PING_CHECK.labels[0].value,
@@ -121,10 +122,12 @@ describe('terraform config generation', () => {
121122
},
122123
},
123124
target: 'areallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongexample.com',
125+
timeout: BASIC_PING_CHECK.timeout
124126
},
125127
a_really_really_really_really_really_really_really_really_really_long_jobname_areallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongexample_com_stuff:
126128
{
127129
enabled: true,
130+
frequency: BASIC_PING_CHECK.frequency,
128131
job: 'a really really really really really really really really really long jobname',
129132
labels: {
130133
[BASIC_PING_CHECK.labels[0].name]: BASIC_PING_CHECK.labels[0].value,
@@ -137,6 +140,7 @@ describe('terraform config generation', () => {
137140
},
138141
},
139142
target: 'areallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongexample.com/stuff',
143+
timeout: BASIC_PING_CHECK.timeout
140144
},
141145
},
142146
grafana_synthetic_monitoring_probe: TERRAFORM_PRIVATE_PROBES,
@@ -204,6 +208,7 @@ describe('terraform config generation', () => {
204208
grafana_synthetic_monitoring_check: {
205209
'stuff_https___www_grafana-dev_com': {
206210
enabled: true,
211+
frequency: 120000,
207212
job: 'stuff',
208213
labels: {},
209214
probes: [1, 2],
@@ -267,6 +272,7 @@ describe('terraform config generation', () => {
267272
},
268273
},
269274
target: 'https://www.grafana-dev.com',
275+
timeout: 17000,
270276
},
271277
},
272278
grafana_synthetic_monitoring_probe: TERRAFORM_PRIVATE_PROBES,

‎src/test/fixtures/terraform.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const TERRAFORM_PRIVATE_PROBES = {
1616
name: PRIVATE_PROBE.name,
1717
public: PRIVATE_PROBE.public,
1818
region: PRIVATE_PROBE.region,
19-
capabilities: PRIVATE_PROBE.capabilities,
19+
disable_browser_checks: PRIVATE_PROBE.capabilities.disableBrowserChecks,
20+
disable_scripted_checks: PRIVATE_PROBE.capabilities.disableScriptedChecks,
2021
},
2122
[UNSELECTED_PRIVATE_PROBE.name]: {
2223
labels: {
@@ -27,7 +28,8 @@ export const TERRAFORM_PRIVATE_PROBES = {
2728
name: UNSELECTED_PRIVATE_PROBE.name,
2829
public: UNSELECTED_PRIVATE_PROBE.public,
2930
region: UNSELECTED_PRIVATE_PROBE.region,
30-
capabilities: UNSELECTED_PRIVATE_PROBE.capabilities,
31+
disable_browser_checks: UNSELECTED_PRIVATE_PROBE.capabilities.disableBrowserChecks,
32+
disable_scripted_checks: UNSELECTED_PRIVATE_PROBE.capabilities.disableScriptedChecks,
3133
},
3234
};
3335

@@ -46,6 +48,7 @@ export const TERRAFORM_BASIC_PING_CHECK = {
4648
grafana_synthetic_monitoring_check: {
4749
[nameKey]: {
4850
enabled: true,
51+
frequency: BASIC_PING_CHECK.frequency,
4952
job: BASIC_PING_CHECK.job,
5053
labels: {
5154
[BASIC_PING_CHECK.labels[0].name]: BASIC_PING_CHECK.labels[0].value,
@@ -58,6 +61,7 @@ export const TERRAFORM_BASIC_PING_CHECK = {
5861
},
5962
},
6063
target: BASIC_PING_CHECK.target,
64+
timeout: BASIC_PING_CHECK.timeout,
6165
},
6266
},
6367
grafana_synthetic_monitoring_probe: TERRAFORM_PRIVATE_PROBES,

0 commit comments

Comments
 (0)