Skip to content

Custom event implementation #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jun 4, 2025
Merged

Custom event implementation #51

merged 24 commits into from
Jun 4, 2025

Conversation

disha-148
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@morningspace morningspace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of more comments:

  • To confirm, does this PR cover the support of custom event for export, lint, init, and it does not cover import, right?
  • I don't see the command line help info is updated to reflect the latest changes introduced by the support of custom event.
  • Next time, we can split the code change into multiple PRs, and each one includes one functional modification, e.g.: one PR for export, one PR for init, and so on, which is easier for code review.

}

readmeContent += `
## Installation and Usage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing packages may need to be updated, e.g.: the Installation and Usage section seems to be the 3 level title, now has been moved up to 2 level.

const url = `https://${server}/api/custom-dashboard`
logger.info(`Start to get the dashboard list from ${url}`);
// Event export
const eventId = getValueByKeyFromArray(eventIncludes, "eventId");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we consistently use id instead of eventId as what we do with dashboards, since the type event has been specified by type=event

try {
const filename = `${title}.json`;
const filepath = path.join(dir, filename);
logger.info(`Saving dashboard (id=${id}) to ${filepath}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When log a message, usually when it says doing something, in this case, saving, we will append ... at the end of the log line. The same applies to all the other log messages through out this file.

const filepath = path.join(dir, filename);
logger.info(`Saving event (id=${id}) to ${filepath}`);
fs.writeFileSync(filepath, JSON.stringify(event, null, 2));
logger.info(`Event (id=${id}) saved successfully`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be sure that we use the term consistently w/o ambiguity when it comes to the event manipulation. For example, here we say some event is saved successfully. This may be confusing to the end user, because it's actually a custom event definition, not an event instance. We probably should use event definition through out this file.

Dashboard might have the same problem.

@disha-148 disha-148 marked this pull request as ready for review May 21, 2025 18:20
Comment on lines +120 to +121
${execName} export --server example.com --include 'type=dashboard title="Runtime.*"' --location ./my-package
${execName} export --server example.com --include 'type=event id=exampleid' --location ./my-package
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the single quotes required? I'd expect this is not needed. If it's not true, we can solve it in a follow-up PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The single quotes aren't strictly necessary. We'll address this in a follow-up PR.

logger.info(`Applying the dashboard to ${url} ...`);
const url = `https://${server}/${apiPath}`;

function getTypeLabel(apiPath: String): String {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to dynamically determine the type by apiPath, because every time when you call importIntegration, you know the type, you can pass it into importIntegration as a param.

Comment on lines +849 to +859
if (matches.length && inc.explicitlyTyped) {
filtered = matches.map(idCond => {
const id = idCond.split("=")[1]?.replace(/^"|"$/g, '');
return { id };
});
} else if (matches.length) {
filtered = matches.map(idCond => {
const id = idCond.split("=")[1]?.replace(/^"|"$/g, '');
return allDashboards.find(d => d.id === id);
}).filter(Boolean);
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the difference between the two blocks? Why it doesn't have to check the existence of the id in allDashboards in the first if block?

Comment on lines +939 to +945
const isOnlyDashboard = parsedIncludes.every(inc => inc.type === "dashboard");
const isOnlyEvent = parsedIncludes.every(inc => inc.type === "event");
const isMixedOrUnspecified = parsedIncludes.some(inc => inc.type === "all") || (!isOnlyDashboard && !isOnlyEvent);

if (!wasDashboardFound && !wasEventFound && isMixedOrUnspecified) {
logger.error("No custom elements were found or exported.");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code logic here is tricky. Shall we just simply count the processed dashboards and events, and if there's nothing processed, we output no custom elements exported. We should not rely on the presence of type param in the --include clause, because it could be possible that no element is processed even the type is specified, e.g.: no match found for this type.

@morningspace morningspace merged commit beda782 into instana:main Jun 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants