Skip to content

Commit

Permalink
Cloud logs (#1999)
Browse files Browse the repository at this point in the history
* begin cloud logs

* auth

* feat: config to files

* feat: logmon & atracker

* feat: state

* front-end

* front-end

* front-end

* rm logs

* fix: auth

* fix: auth

* fix: snakecase

* fix: package updates

* fix: packages

* feat: overrides

* feat: overrides

* feat: overrides

* feat: overrides
  • Loading branch information
jvallexm authored and GitHub Enterprise committed Aug 20, 2024
1 parent 54ccb1f commit 1864f67
Show file tree
Hide file tree
Showing 29 changed files with 1,768 additions and 4,305 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- Users can now create Secrets Groups from the Secrets Manager page
- Users can now add authorizations for Kubernetes and CIS to Secrets Manager from the Secrets Manager Page
- Users can now attach Power VS Volumes to FalconStor VTL instances
- Users can now enable Cloud Logs from the Cloud Logs page /forms/logs. Please note that enabling this feature will prevent Activity Tracker and LogDNA code from being generated. Cloud Logs will replace these services

### Fixes

Expand Down
4,952 changes: 662 additions & 4,290 deletions client/package-lock.json

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"json-to-tf": "^0.3.1",
"jszip": "^3.10.1",
"lazy-z": "1.12.1",
"react": "^18.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.23.1",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.0.0",
"react-router-dom": "^6.3.0",
"regex-but-with-words": "^1.5.0",
"sass": "1.51.0",
"stream-browserify": "^3.0.0"
Expand All @@ -45,10 +45,21 @@
"@testing-library/user-event": "^14.4.3",
"husky": "1.3.1",
"lint-staged": "^13.0.3",
"postcss": "^8.4.38",
"prettier": "^1.17.0",
"react-scripts": "^5.0.1",
"wait-for-expect": "3.0.2"
},
"overrides": {
"react-scripts": {
"@svgr/webpack": "8.1.0",
"typescript": "5.0.2",
"postcss": "8.4.38"
}
},
"peerDependencies": {
"postcss": "^8.4.38"
},
"browserslist": [
">0.2%",
"not dead",
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/page-template/PageTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
IbmCloudBareMetalServer,
GroupObjects,
ScreenMapSet,
IbmCloudLogging,
} from "@carbon/icons-react";
import f5 from "../../images/f5.png";
import {
Expand All @@ -73,6 +74,7 @@ function F5Icon() {
const releaseNotes = require("../../lib/docs/release-notes.json");
const navCategories = require("../../lib/nav-catagories");
const navIcons = {
IbmCloudLogging: IbmCloudLogging,
ScreenMapSet: ScreenMapSet,
GroupObjects: GroupObjects,
IbmCloudKeyProtect: IbmCloudKeyProtect,
Expand Down
18 changes: 18 additions & 0 deletions client/src/components/pages/CraigForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,24 @@ function craigForms(craig) {
},
],
},
cloud_logs: {
groups: [
{
enabled: craig.cloud_logs.enabled,
},
{
name: craig.cloud_logs.name,
resource_group: craig.cloud_logs.resource_group,
},
{
cos: craig.cloud_logs.cos,
},
{
logs_bucket: craig.cloud_logs.logs_bucket,
metrics_bucket: craig.cloud_logs.metrics_bucket,
},
],
},
logdna: {
groups: [
{
Expand Down
47 changes: 47 additions & 0 deletions client/src/components/pages/FormPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,51 @@ const CloudDatabasePage = (craig) => {
});
};

const CloudLogs = (craig) => {
console.log(craig.store.json);
return (
<CraigToggleForm
craig={craig}
about={RenderDocs("cloud_logs", craig.store.json._options.template)()}
name="Cloud Logs"
hideName
noDeleteButton={true}
useAddButton={false}
tabPanel={{
name: "Cloud Logs",
}}
onShowToggle={() => {}}
submissionFieldName="cloud_logs"
onSave={craig.cloud_logs.save}
innerFormProps={{
craig: craig,
data: craig.store.json.cloud_logs,
disableSave: disableSave,
form: {
jsonField: "cloud_logs",
disableSave: disableSave,
groups: [
{
enabled: craig.cloud_logs.enabled,
},
{
name: craig.cloud_logs.name,
resource_group: craig.cloud_logs.resource_group,
},
{
cos: craig.cloud_logs.cos,
},
{
logs_bucket: craig.cloud_logs.logs_bucket,
metrics_bucket: craig.cloud_logs.metrics_bucket,
},
],
},
}}
/>
);
};

const ClusterPage = (craig) => {
return formPageTemplate(craig, {
name: "Clusters",
Expand Down Expand Up @@ -1412,6 +1457,8 @@ export const NewFormPage = (props) => {
return ClassicVlanPage(craig);
} else if (form === "icd") {
return CloudDatabasePage(craig);
} else if (form === "logs") {
return CloudLogs(craig);
} else if (form === "clusters") {
return ClusterPage(craig);
} else if (form === "dns") {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/pages/diagrams/ScrollForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ScrollForm extends React.Component {
hide={false}
name={
contains(
["logdna", "sysdig", "atracker", "scc_v2"],
["logdna", "sysdig", "atracker", "scc_v2", "cloud_logs"],
this.props.selectedItem
)
? this.props.craig.store.json[this.props.selectedItem].name
Expand Down
8 changes: 8 additions & 0 deletions client/src/lib/docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2609,5 +2609,13 @@
]
],
"last_updated": "05/31/2024"
},
"cloud_logs": {
"content": [
{
"text": "NYI"
}
],
"relatedLinks": []
}
}
3 changes: 2 additions & 1 deletion client/src/lib/docs/release-notes.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"Power VS Workspace connections are no longer removed from Transit Gateways when updating the Workspace's region",
"Users can now create Secrets Groups from the Secrets Manager page",
"Users can now add authorizations for Kubernetes and CIS to Secrets Manager from the Secrets Manager Page",
"Users can now attach Power VS Volumes to FalconStor VTL instances"
"Users can now attach Power VS Volumes to FalconStor VTL instances",
"Users can now enable Cloud Logs from the Cloud Logs page /forms/logs. Please note that enabling this feature will prevent Activity Tracker and LogDNA code from being generated. Cloud Logs will replace these services"
],
"fixes": [
"Fixed an issue causing generate-env.sh to incorrectly set values for Power VS regions"
Expand Down
3 changes: 2 additions & 1 deletion client/src/lib/forms/disable-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function disableSave(field, stateData, componentProps, craig) {
"power_placement_groups",
"power_shared_processor_pools",
"secrets_groups",
"cloud_logs",
];
let isPowerSshKey = field === "ssh_keys" && componentProps.arrayParentName;
if (contains(stateDisableSaveComponents, field) || isPowerSshKey) {
Expand Down Expand Up @@ -190,7 +191,7 @@ function invalidCidrBlock(value) {
*/
function forceShowForm(stateData, componentProps) {
let openForm = false;
if (componentProps.innerFormProps?.data.enable === false) {
if (componentProps.innerFormProps?.data?.enable === false) {
return openForm;
}

Expand Down
6 changes: 6 additions & 0 deletions client/src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ const {
classicSecurityGroupTf,
classicVsiTf,
classicBareMetalTf,
formatCloudLogs,
formatCosToCloudLogsAuth,
cloudLogsTf,
} = require("./json-to-iac");
const releaseNotes = require("./docs/release-notes.json");
const docs = require("./docs/docs.json");
Expand All @@ -154,6 +157,9 @@ const {
} = require("./components");

module.exports = {
cloudLogsTf,
formatCosToCloudLogsAuth,
formatCloudLogs,
dynamicPasswordInputProps,
dynamicToolTipWrapperProps,
dynamicCraigFormGroupsProps,
Expand Down
4 changes: 3 additions & 1 deletion client/src/lib/json-to-iac/atracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ function atrackerTf(config) {
if (config.atracker.add_route) {
str += formatAtrackerRoute(config);
}
return config.atracker.enabled ? tfBlock("Atracker Resources", str) : "";
return config.atracker.enabled && !config?.cloud_logs?.enabled
? tfBlock("Atracker Resources", str)
: "";
}

module.exports = {
Expand Down
127 changes: 127 additions & 0 deletions client/src/lib/json-to-iac/cloud-logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
const {
contains,
isEmpty,
keys,
titleCase,
getObjectFromArray,
snakeCase,
} = require("lazy-z");
const {
jsonToTfPrint,
bucketRef,
cosRef,
tfBlock,
rgIdRef,
} = require("./utils");

/**
* format cloud logs
* @param {*} config
* @returns {string} terraform
*/
function formatCloudLogs(config) {
let logsData = {
name: "${var.prefix}-cloud-logs",
service: "logs",
plan: "standard",
location: "${var.region}",
resource_group_id: rgIdRef(config.cloud_logs.resource_group, config),
parameters: {},
};

if (!contains([null, "(Disabled)"], config.cloud_logs.logs_bucket)) {
logsData.parameters.logs_bucket_crn = bucketRef(
config.cloud_logs.cos,
config.cloud_logs.logs_bucket,
"crn"
);
logsData.parameters.logs_bucket_endpoint = bucketRef(
config.cloud_logs.cos,
config.cloud_logs.logs_bucket,
`s3_endpoint_${config._options.endpoints}`
);
}

if (!contains([null, "(Disabled)"], config.cloud_logs.metrics_bucket)) {
logsData.parameters.metrics_bucket_crn = bucketRef(
config.cloud_logs.cos,
config.cloud_logs.metrics_bucket,
"crn"
);
logsData.parameters.metrics_bucket_endpoint = bucketRef(
config.cloud_logs.cos,
config.cloud_logs.metrics_bucket,
`s3_endpoint_${config._options.endpoints}`
);
}

if (isEmpty(keys(logsData.parameters))) {
delete logsData.parameters;
} else {
logsData.depends_on = [
`\${ibm_iam_authorization_policy.${snakeCase(
config.cloud_logs.cos
)}_object_storage_to_cloud_logs}`,
];
}

return jsonToTfPrint(
"resource",
"ibm_resource_instance",
"cloud_logs",
logsData
);
}

/**
* format authorization from cos to cloud logs
* @param {*} config
* @returns {string} terraform
*/
function formatCosToCloudLogsAuth(config) {
return jsonToTfPrint(
"resource",
"ibm_iam_authorization_policy",
`${config.cloud_logs.cos}_object_storage_to_cloud_logs`,
{
source_service_name: "logs",
description: `Allow Cloud Logs to access ${titleCase(
config.cloud_logs.cos
)} Object Storage`,
target_service_name: "cloud-object-storage",
target_resource_instance_id: cosRef(
config.cloud_logs.cos,
"guid",
getObjectFromArray(config.object_storage, "name", config.cloud_logs.cos)
.use_data
),
roles: ["Writer"],
}
);
}

/**
* format cloud logs terraform
* @param {*} config craig json
* @returns {string} terraform code
*/
function cloudLogsTf(config) {
let tf = "";
if (
config?.cloud_logs?.enabled &&
(!contains([null, "(Disabled)"], config?.cloud_logs?.logs_bucket) ||
!contains([null, "(Disabled)"], config?.cloud_logs?.metrics_bucket))
) {
tf += formatCosToCloudLogsAuth(config);
}
if (config?.cloud_logs?.enabled) {
tf += formatCloudLogs(config);
}
return tf === "" ? null : tfBlock("Cloud Logs Resources", tf);
}

module.exports = {
formatCloudLogs,
formatCosToCloudLogsAuth,
cloudLogsTf,
};
2 changes: 2 additions & 0 deletions client/src/lib/json-to-iac/config-to-files-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const { outputsTf } = require("./outputs");
const { classicSecurityGroupTf } = require("./classic-security-group");
const { classicVsiTf } = require("./classic-vsi");
const { classicBareMetalTf } = require("./classic-bare-metal");
const { cloudLogsTf } = require("./cloud-logs");
const apacheLicense = ` Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -323,6 +324,7 @@ function configToFilesJson(config, apiMode, templateTarMode) {
"classic_security_groups.tf": classicSecurityGroupTf(config),
"classic_vsi.tf": classicVsiTf(config),
"classic_bare_metal.tf": classicBareMetalTf(config),
"cloud_logs.tf": cloudLogsTf(config),
};
vpcModuleTf(files, config);
return files;
Expand Down
9 changes: 9 additions & 0 deletions client/src/lib/json-to-iac/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,16 @@ const {
} = require("./classic-security-group");
const { classicVsiTf } = require("./classic-vsi");
const { classicBareMetalTf } = require("./classic-bare-metal");
const {
formatCloudLogs,
formatCosToCloudLogsAuth,
cloudLogsTf,
} = require("./cloud-logs");

module.exports = {
cloudLogsTf,
formatCosToCloudLogsAuth,
formatCloudLogs,
classicVsiTf,
classicBareMetalTf,
classicSecurityGroupTf,
Expand Down
Loading

0 comments on commit 1864f67

Please sign in to comment.