Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Update _key generation #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eXtremeX
Copy link

Summary

Added

  • Made user, group and incident keys more detailed by including the
    name/email property.

Updated

  • Updated SDK dependencies to 8.29.2.
  • Changed ENV USERNAME property name to USERID.
  • According to the documentation, it is possible that the Unique record identifier (sys_id), the parameter used to generate the key, can have duplicate values under certain circumstances.
  • Another possible cause is that the sys_id may be unique only to the table it is on, meaning different tables can have entries with the same sys_id.
  • As a fix for these, the key generation was updated in such a way that it takes the entity type, the sys_id and the name of the entity to generate the key.
  • An issue was also found in the .env file, wherein the USERNAME parameter was not being properly detected. To fix this, the parameter was renamed to USERID instead.

Type of change

Please leave any irrelevant options unchecked.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    not work as expected)
  • This change requires a documentation update

Checklist

General Development Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@eXtremeX eXtremeX requested a review from a team as a code owner November 23, 2022 14:11
@@ -41,7 +53,7 @@ export function createUserEntity(user: any): Entity {
...convertCommonServiceNowProperties(user),
_class: Entities.USER._class,
_type: Entities.USER._type,
_key: user.sys_id,
_key: getUserKey(user.sys_id, user.user_name),

Choose a reason for hiding this comment

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

Do you have examples of where this fixed the duplicate key issue? I'm surprised the id wasn't unique.

Choose a reason for hiding this comment

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

I just want to confirm that this fixes the issue, because changing the _key value will cause a large amount of churn in users' graphs. If we can avoid that it's better, but does fix the issue I'm good to go with it.

Copy link
Author

Choose a reason for hiding this comment

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

Hey @zemberdotnet, we aren't 100% sure if this will fix the issue but we thought it was worth a try - weren't aware changing _key has negative impact as a whole on the other hand.

The code surrounding user ingestion is very simple:

Client method part:

return this.iterateTableResources({
      table: ServiceNowTable.USER,
      callback,
});

Step function part:

await client.iterateUsers(async (user) => {
    const userEntity = await jobState.addEntity(createUserEntity(user));

    await jobState.addRelationship(
      createDirectRelationship({
        _class: RelationshipClass.HAS,
        from: accountEntity,
        to: userEntity,
      }),
    );
});

Some ideas that came to mind were either to increase the _key complexity or to maybe skip (truly) duplicate users but it's not like we're expecting them by default and that alone might hide some other bug that's causing this.

Do you have some ideas what you might try doing here?

Copy link

@zemberdotnet zemberdotnet Jan 4, 2023

Choose a reason for hiding this comment

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

Hey @eXtremeX 👋 Thank you for the detailed explanation.

weren't aware changing _key has negative impact as a whole on the other hand.

In this case, it's probably okay. It will cause all entities to be fully deleted and recreated, but this probably doesn't produce enough data for that to be a huge concern.

I'm good to try this approach if we can address the other comment I have below.

@zemberdotnet zemberdotnet self-assigned this Dec 2, 2022
@@ -4,7 +4,7 @@ const instanceConfigFields: IntegrationInstanceConfigFieldMap = {
hostname: {
type: 'string',
},
username: {
userid: {

Choose a reason for hiding this comment

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

Hey, last problem before this can be approved. Do we have to change this field name? It will cause breaking changes and require migration for all integrations that use this field.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants