diff --git a/nerdlets/service-containers/service-containers.js b/nerdlets/service-containers/service-containers.js index d5fef82..17b62d8 100644 --- a/nerdlets/service-containers/service-containers.js +++ b/nerdlets/service-containers/service-containers.js @@ -52,56 +52,63 @@ export default class ServiceContainers extends React.Component { let result = await EntityByGuidQuery.query({ entityGuid }); const entity = result.data.entities[0]; - const nrql = `SELECT uniques(containerId) FROM Transaction - WHERE entityGuid = '${entityGuid}' ${timeRange}`; - // get the container id's that this app runs in - result = await nrdbQuery(entity.accountId, nrql); - const containerIds = result.map((r) => r.member); - this.setState({ containerIds }); - - // look up the infrastucture account(s) that are associated with this entity. - // cache for performance. - const storageQuery = { - collection: 'GLOBAL', - entityGuid, - documentId: 'infraAccountsData', - }; - const storageResult = await EntityStorageQuery.query(storageQuery); - - let infraAccounts = storageResult.data && storageResult.data.infraAccounts; - - // find the account(s) that are monitoring these containers. Hopefully there's exactly - // one, but not, take the account with the most matches. - if (!infraAccounts && containerIds && containerIds.length > 0) { - const where = `containerId IN (${containerIds - .map((cid) => `'${cid}'`) - .join(',')})`; - const find = { eventType: 'ProcessSample', where }; - - infraAccounts = await findRelatedAccountsWith(find); - - // cache in entity storage - storageQuery.document = { infraAccounts }; - storageQuery.actionType = - EntityStorageMutation.ACTION_TYPE.WRITE_DOCUMENT; - - await EntityStorageMutation.mutate(storageQuery); - } + if (entity) { + const nrql = `SELECT uniques(containerId) FROM Transaction + WHERE entityGuid = '${entityGuid}' ${timeRange}`; - if (!infraAccounts || infraAccounts.length === 0) { - const searchedAccounts = await accountsWithData('ProcessSample'); - this.setState({ accountDataNotFound: true, searchedAccounts, entity }); + // get the container id's that this app runs in + result = await nrdbQuery(entity.accountId, nrql); + const containerIds = result.map((r) => r.member); + this.setState({ containerIds }); + + // look up the infrastucture account(s) that are associated with this entity. + // cache for performance. + const storageQuery = { + collection: 'GLOBAL', + entityGuid, + documentId: 'infraAccountsData', + }; + const storageResult = await EntityStorageQuery.query(storageQuery); + + let infraAccounts = + storageResult.data && storageResult.data.infraAccounts; + + // find the account(s) that are monitoring these containers. Hopefully there's exactly + // one, but not, take the account with the most matches. + if (!infraAccounts && containerIds && containerIds.length > 0) { + const where = `containerId IN (${containerIds + .map((cid) => `'${cid}'`) + .join(',')})`; + const find = { eventType: 'ProcessSample', where }; + + infraAccounts = await findRelatedAccountsWith(find); + + // cache in entity storage + storageQuery.document = { infraAccounts }; + storageQuery.actionType = + EntityStorageMutation.ACTION_TYPE.WRITE_DOCUMENT; + + await EntityStorageMutation.mutate(storageQuery); + } + + if (!infraAccounts || infraAccounts.length === 0) { + const searchedAccounts = await accountsWithData('ProcessSample'); + this.setState({ accountDataNotFound: true, searchedAccounts, entity }); + } else { + // use the infra account with the most hits as the primary for this entity, and then + // store the others otherInfraAccounts so we can show an info box. + this.setState({ + infraAccount: infraAccounts[0], + allInfraAccounts: infraAccounts, + containerIds, + entity, + timeRange, + }); + } } else { - // use the infra account with the most hits as the primary for this entity, and then - // store the others otherInfraAccounts so we can show an info box. - this.setState({ - infraAccount: infraAccounts[0], - allInfraAccounts: infraAccounts, - containerIds, - entity, - timeRange, - }); + console.log('entity data not found => ', result); + this.setState({ accountDataNotFound: true, entity }); } } diff --git a/nr1.json b/nr1.json index 99d192a..de3af94 100644 --- a/nr1.json +++ b/nr1.json @@ -1,6 +1,6 @@ { "schemaType": "NERDPACK", - "id": "5d870b85-07a5-4213-9bec-f9351fb9c08c", + "id": "3c4445bb-9ea4-4c72-b22f-6769c1c6cf87", "displayName": "Container Explorer", "description": "Global visibility of the containers across your infrastructure, easily segmented by tags." }