Skip to content

Commit 329fa6d

Browse files
authored
Merge pull request #159 from microservices-suite/repo-engineering/deletion_automation
feat: add suite signature to ELK
2 parents c66bc0d + c480f93 commit 329fa6d

8 files changed

+325
-385
lines changed

.suite-cli/cli/scripts/assets/grafanaKrakendDashboardJsonContent.asset.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = () =>`
1+
module.exports = ({ app_name }) => `
22
{
33
"annotations": {
44
"list": [
@@ -6970,7 +6970,7 @@ module.exports = () =>`
69706970
]
69716971
},
69726972
"timezone": "",
6973-
"title": "KrakenD",
6973+
"title": "🦧${app_name}",
69746974
"uid": "I9FkyxWik",
69756975
"version": 1
69766976
}`

.suite-cli/cli/scripts/assets/krakenJsonContent.asset.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module.exports = ({
44
api_version,
55
gateway_cache_period,
66
gateway_timeout,
7-
gateway_port
7+
gateway_port,
8+
app_name
89
}) => {
910
// Health check for all services
1011
const suiteStatusCheckBackends = services.map((service) => `
@@ -79,7 +80,7 @@ module.exports = ({
7980
},
8081
"telemetry/logging": {
8182
"level": "DEBUG",
82-
"prefix": "[KRAKEND]",
83+
"prefix": "[SUITE]",
8384
"syslog": false,
8485
"stdout": true
8586
},
@@ -97,7 +98,7 @@ module.exports = ({
9798
"exporters": {
9899
"jaeger": {
99100
"endpoint": "http://jaeger:14268/api/traces",
100-
"service_name": "krakend"
101+
"service_name": "🦧${app_name}"
101102
}
102103
}
103104
}

.suite-cli/cli/scripts/assets/krakendConfigContent.asset.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module.exports = ({
44
api_version,
55
gateway_cache_period,
66
gateway_timeout,
7-
gateway_port
7+
gateway_port,
8+
app_name
89
}) => {
910
// Health check for all services
1011
const suiteStatusCheckBackends = services.map((service) => `
@@ -79,7 +80,7 @@ module.exports = ({
7980
},
8081
"telemetry/logging": {
8182
"level": "DEBUG",
82-
"prefix": "[KRAKEND]",
83+
"prefix": "[SUITE]",
8384
"syslog": false,
8485
"stdout": true
8586
},
@@ -97,7 +98,7 @@ module.exports = ({
9798
"exporters": {
9899
"jaeger": {
99100
"endpoint": "http://jaeger:14268/api/traces",
100-
"service_name": "krakend"
101+
"service_name": "🦧${app_name}"
101102
}
102103
}
103104
}

.suite-cli/cli/scripts/assets/krakendPartialsExtraConfContent.asset.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = () =>`
1+
module.exports = ({ app_name }) => `
22
{
33
"security/cors": {
44
"allow_origins": [
@@ -23,7 +23,7 @@ module.exports = () =>`
2323
},
2424
"telemetry/logging": {
2525
"level": "DEBUG",
26-
"prefix": "[KRAKEND]",
26+
"prefix": "[SUITE]",
2727
"syslog": false,
2828
"stdout": true
2929
},
@@ -48,7 +48,7 @@ module.exports = () =>`
4848
"exporters": {
4949
"jaeger": {
5050
"endpoint": "http://jaeger:14268/api/traces",
51-
"serviceName": "krakend"
51+
"serviceName": "🦧${app_name}"
5252
}
5353
}
5454
}

.suite-cli/cli/scripts/assets/logstashConfContent.asset.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ input {
88
filter {
99
# Grok expression matches several formats (EE and CE):
1010
#[GIN] 2022/09/09 - 08:33:51 | 200 | 732.753µs | 172.20.0.1 | GET "/sequential"
11-
#[KRAKEND] 2022/09/09 - 08:35:25.813 [AccessLog] | 200 | 92.944122ms | 172.20.0.1 | GET /market/simple
12-
#[KRAKEND][SERVICE: AsyncAgent][AMQP][async-agent-demo] Starting the consumer
11+
#[SUITE] 2022/09/09 - 08:35:25.813 [AccessLog] | 200 | 92.944122ms | 172.20.0.1 | GET /market/simple
12+
#[SUITE][SERVICE: AsyncAgent][AMQP][async-agent-demo] Starting the consumer
1313
grok {
14-
match => { "message" => '(\[%{WORD}\] %{DATA}%{SPACE}-%{SPACE}%{DATA}%{SPACE}(\[AccessLog\]%{SPACE})?\| %{NUMBER:statusCode} \|%{SPACE}%{NUMBER:duration}(m|µ|n|u)?s%{SPACE}\|%{SPACE}%{DATA:ip}%{SPACE}\|%{SPACE}%{WORD:verb}%{SPACE}"?(?<url>[^"]+)"?)?((\[KRAKEND\])?\[%{WORD:scope}(: (?<context>[^\]]+)(\]\[%{DATA:sublevel1})?(\]\[%{DATA:sublevel2})?)?\] %{GREEDYDATA:msg})?'}
14+
match => { "message" => '(\[%{WORD}\] %{DATA}%{SPACE}-%{SPACE}%{DATA}%{SPACE}(\[AccessLog\]%{SPACE})?\| %{NUMBER:statusCode} \|%{SPACE}%{NUMBER:duration}(m|µ|n|u)?s%{SPACE}\|%{SPACE}%{DATA:ip}%{SPACE}\|%{SPACE}%{WORD:verb}%{SPACE}"?(?<url>[^"]+)"?)?((\[SUITE\])?\[%{WORD:scope}(: (?<context>[^\]]+)(\]\[%{DATA:sublevel1})?(\]\[%{DATA:sublevel2})?)?\] %{GREEDYDATA:msg})?'}
1515
}
1616
1717
if [host] and ![host][name] {

.suite-cli/cli/scripts/krakend.ndjson

+4
Large diffs are not rendered by default.

.suite-cli/cli/scripts/scripts.module.js

+14-24
Original file line numberDiff line numberDiff line change
@@ -1550,11 +1550,11 @@ const injectSREConfigs = async ({ app_directory, answers, relativeKrakendDir, kr
15501550
break;
15511551

15521552
case 'grafana/krakend':
1553-
writeFile(join(current_dir, 'dashboard.json'), assets.grafanaKrakendDashboardJsonContent());
1553+
writeFile(join(current_dir, 'dashboard.json'), assets.grafanaKrakendDashboardJsonContent({ app_name: answers.app_name }));
15541554
break;
15551555

15561556
case 'krakend/partials':
1557-
writeFile(join(current_dir, 'extra_config.tmpl'), assets.krakendPartialsExtraConfContent());
1557+
writeFile(join(current_dir, 'extra_config.tmpl'), assets.krakendPartialsExtraConfContent({app_name: answers.app_name}));
15581558
writeFile(join(current_dir, 'input_headers.tmpl'), assets.krakendPartialsInputHeadersContent());
15591559
writeFile(join(current_dir, 'rate_limit_backend.tmpl'), assets.krakendPartialsRateLimitBackendContent());
15601560
break;
@@ -1588,10 +1588,11 @@ const injectSREConfigs = async ({ app_directory, answers, relativeKrakendDir, kr
15881588
api_version: answers.api_version,
15891589
gateway_cache_period: answers.gateway_cache_period,
15901590
gateway_timeout: answers.gateway_timeout,
1591-
relativeKrakendDir
1591+
relativeKrakendDir,
1592+
app_name: answers.app_name
15921593
}));
15931594
writeFile(join(`${app_directory}`, '.env'), assets.dockerComposeEnvContent());
1594-
await downloadAndWriteDashboardFile(app_directory);
1595+
await readAndWriteDashboardFile(app_directory, answers);
15951596

15961597
}
15971598
const scaffoldApp = ({ answers }) => {
@@ -2146,30 +2147,19 @@ const removeGateway = async ({ gateway, project_root }) => {
21462147
}
21472148
};
21482149

2149-
const downloadAndWriteDashboardFile = (app_directory) => {
2150-
const fileUrl = 'https://raw.githubusercontent.com/krakend/playground-community/master/config/elastic/dashboard.ndjson';
2150+
const readAndWriteDashboardFile = (app_directory, answers) => {
21512151
const outputDirectory = path.join(app_directory, 'telemetry', 'elastic');
21522152
const filename = 'dashboard.ndjson';
21532153
const outputPath = path.join(outputDirectory, filename);
2154+
// Read the NDJSON file content as a string
2155+
console.log({__dirname:__dirname})
2156+
const krakendNdjson = readFileSync(`${__dirname}/krakend.ndjson`, 'utf8');
21542157

2155-
return new Promise((resolve, reject) => {
2156-
const file = fs.createWriteStream(outputPath);
2157-
2158-
https.get(fileUrl, (response) => {
2159-
if (response.statusCode === 200) {
2160-
response.pipe(file);
2161-
file.on('finish', () => {
2162-
file.close(() => {
2163-
resolve();
2164-
});
2165-
});
2166-
} else {
2167-
reject(new Error(`Failed to download file: ${response.statusCode} ${response.statusMessage}`));
2168-
}
2169-
}).on('error', (err) => {
2170-
fs.unlink(outputPath, () => reject(err));
2171-
});
2172-
});
2158+
// Replace all occurrences of 'KrakenD' with 'SuiteCLI/<appname>'
2159+
const updatedContent = krakendNdjson.replace(/KrakenD/g, `🦧${answers.app_name}`);
2160+
2161+
// Write the updated content to the new file
2162+
writeFileSync(outputPath, updatedContent);
21732163
};
21742164

21752165
module.exports = {

0 commit comments

Comments
 (0)