Skip to content

Commit

Permalink
#9257: fix heartbeat telemetry regression (#9258)
Browse files Browse the repository at this point in the history
  • Loading branch information
twschiller authored Oct 9, 2024
1 parent 4d6d207 commit e95e85b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/types/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,5 @@ export type ActivatedDeployment = {
deployment: UUID;
// Use legacy names - these are passed to the server
blueprint: RegistryId;
blueprintVersion: string;
blueprintVersion: SemVerString;
};
6 changes: 6 additions & 0 deletions src/types/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ describe("types/helpers.ts", () => {
coerce: true,
expected: "v1.2.3",
},
{
value: "0.0.0",
allowLeadingV: false,
coerce: false,
expected: "0.0.0",
},
])(
"$value with allowLeadingV: $allowLeadingV and coerce: $coerce returns $expected",
({ value, allowLeadingV, coerce, expected }) => {
Expand Down
8 changes: 0 additions & 8 deletions src/types/registryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,11 @@ export type Metadata = {
*/
readonly name: string;

/**
* An optional human-readable description.
*/
/**
* An optional human-readable description.
*/
readonly description?: string;

/**
* The semantic version of the package.
*
* Currently optional because it defaults to the browser extension version for bricks defined in JS.
*/
/**
* The semantic version of the package.
*
Expand Down
25 changes: 24 additions & 1 deletion src/utils/deploymentUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
isDeploymentActive,
makeUpdatedFilter,
mergeDeploymentIntegrationDependencies,
selectActivatedDeployments,
} from "./deploymentUtils";
import {
uuidv4,
Expand All @@ -46,7 +47,10 @@ import {
import getModDefinitionIntegrationIds from "@/integrations/util/getModDefinitionIntegrationIds";
import { getExtensionVersion } from "@/utils/extensionUtils";
import { validateTimestamp } from "@/utils/timeUtils";
import { modInstanceFactory } from "@/testUtils/factories/modInstanceFactories";
import {
modInstanceFactory,
teamDeploymentMetadataFactory,
} from "@/testUtils/factories/modInstanceFactories";
import { mapActivatedModComponentsToModInstance } from "@/store/modComponents/modInstanceUtils";

describe("makeUpdatedFilter", () => {
Expand Down Expand Up @@ -495,3 +499,22 @@ describe("mergeDeploymentIntegrationDependencies", () => {
]);
});
});

describe("selectActivatedDeployments", () => {
it("selects deployment", () => {
const manualMod = modInstanceFactory();
const deploymentMod = modInstanceFactory({
deploymentMetadata: teamDeploymentMetadataFactory(),
});

const result = selectActivatedDeployments([manualMod, deploymentMod]);

expect(result).toStrictEqual([
{
deployment: deploymentMod.deploymentMetadata!.id,
blueprint: deploymentMod.definition.metadata.id,
blueprintVersion: deploymentMod.definition.metadata.version,
},
]);
});
});
18 changes: 13 additions & 5 deletions src/utils/deploymentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
type IntegrationDependency,
type SanitizedIntegrationConfig,
} from "@/integrations/integrationTypes";
import { validateUUID } from "@/types/helpers";
import { normalizeSemVerString, validateUUID } from "@/types/helpers";
import { type Except } from "type-fest";
import { PIXIEBRIX_INTEGRATION_ID } from "@/integrations/constants";
import getUnconfiguredComponentIntegrations from "@/integrations/util/getUnconfiguredComponentIntegrations";
Expand Down Expand Up @@ -144,17 +144,25 @@ export function checkExtensionUpdateRequired(
);
}

/**
* Return activated deployment telemetry for heartbeat. Includes deployments that are activated, but paused.
*/
export function selectActivatedDeployments(
modInstances: ModInstance[],
): ActivatedDeployment[] {
return uniqBy(
modInstances
.filter((x) => x.deploymentMetadata != null)
.map((x) => ({
.map((modInstance) => ({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Typescript not picking up filter
deployment: x.deploymentMetadata!.id,
blueprint: x.definition.metadata.id,
blueprintVersion: x.definition.metadata.id,
deployment: modInstance.deploymentMetadata!.id,
blueprint: modInstance.definition.metadata.id,
// In practice, all activated mods must have a version. But be defensive given that Metadata type used by
// ModDefinition does not currently require version.
blueprintVersion:
modInstance.definition.metadata.version ??
// 0.0.0 so it's easier to see the defaulting in the backend
normalizeSemVerString("0.0.0"),
})),
(x) => x.deployment,
);
Expand Down

0 comments on commit e95e85b

Please sign in to comment.