Skip to content

Commit

Permalink
Make perf optional (#435)
Browse files Browse the repository at this point in the history
* create new subscription to get device load from currently only mockup of perfMon server

* add new subscription to get load of multiple devices at once

* handle null or empty values for model and version

* shorten null value handler

* implement connection to the perf monitoring service

* add stream mutation changes (#434)

* add new env variable to make perf monit optional

* add missing env variables to pr check

---------

Co-authored-by: Martin Sottnik <[email protected]>
Co-authored-by: plehocky <[email protected]>
  • Loading branch information
3 people authored May 27, 2024
1 parent 6ffc65c commit 3078758
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ PERFORMANCE_MONITORING_GRAPHQL_API_URL=http://localhost:8082/api/graphql

KAFKA_BROKER="10.19.0.25:9094"
KAFKA_TOPIC=frinx
KAFKA_ENABLED=false
KAFKA_ENABLED=false

PERFORMANCE_MONITORING_ENABLED=true
1 change: 1 addition & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
KAFKA_BROKER: 10.19.0.25:30006
KAFKA_TOPIC: uniconfig
KAFKA_ENABLED: false
PERFORMANCE_MONITORING_ENABLED: true
- name: Check code formatting
run: npm run formatter:check
- name: Run eslint check
Expand Down
33 changes: 33 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ type TopologyConfigDisabled = {

type TopologyConfig = TopologyConfigDisabled | TopologyConfigEnabled;

type PerformanceMonitoringConfigEnabled = {
performanceMonitoringEnabled: true;
performanceMonitoringGraphqlURL: string;
};

type PerfomanceMonitoringConfigDisabled = {
performanceMonitoringEnabled: false;
};

type PerformanceMonitoringConfig = PerfomanceMonitoringConfigDisabled | PerformanceMonitoringConfigEnabled;

// all arango params must be present or none
function getTopologyConfig(): TopologyConfig {
const topologyEnabled = stringToBoolean(envString('TOPOLOGY_ENABLED'));
Expand Down Expand Up @@ -69,6 +80,27 @@ function getTopologyConfig(): TopologyConfig {
};
}

function getPerformanceMonitoringConfig(): PerformanceMonitoringConfig {
const performanceMonitoringEnabled = stringToBoolean(envString('PERFORMANCE_MONITORING_ENABLED'));
const topologyEnabled = stringToBoolean(envString('TOPOLOGY_ENABLED'));
const performanceMonitoringGraphqlURL = optionalEnvString('PERFORMANCE_MONITORING_GRAPHQL_API_URL');

if (!performanceMonitoringEnabled || !topologyEnabled) {
return {
performanceMonitoringEnabled: false,
};
}

if (!performanceMonitoringGraphqlURL) {
throw new Error('Not all mandatory topology discovery url (PERFORMANCE_MONITORING_GRAPHQL_API_URL) were found.');
}

return {
performanceMonitoringEnabled: true,
performanceMonitoringGraphqlURL,
};
}

const config = {
host: envString('HOST'),
port: envString('PORT'),
Expand All @@ -82,6 +114,7 @@ const config = {
kafkaTopic: envString('KAFKA_TOPIC'),
kafkaEnabled: stringToBoolean(envString('KAFKA_ENABLED')),
...getTopologyConfig(),
...getPerformanceMonitoringConfig(),
};

export default config;
1 change: 1 addition & 0 deletions src/external-api/performance-monitoring-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const DEVICE_CPU_USAGE = gql`
`;

function getPerformanceMonitoringAPI() {
if (config.performanceMonitoringEnabled === false) {
if (config.topologyEnabled === false) {
return undefined;
}
Expand Down
1 change: 1 addition & 0 deletions src/schema/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type AddSnapshotPayload {
input AddStreamInput {
deviceName: String!
streamName: String!
streamParameters: String
}

type AddStreamPayload {
Expand Down
1 change: 1 addition & 0 deletions src/schema/nexus-typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface NexusGenInputs {
// input type
deviceName: string; // String!
streamName: string; // String!
streamParameters?: string | null; // String
};
AddZoneInput: {
// input type
Expand Down
6 changes: 4 additions & 2 deletions src/schema/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const AddStreamInput = inputObjectType({
definition: (t) => {
t.nonNull.string('streamName');
t.nonNull.string('deviceName');
t.string('streamParameters');
},
});

Expand All @@ -139,6 +140,7 @@ export const AddStreamMutation = extendType({
data: {
deviceName: input.deviceName,
streamName: input.streamName,
streamParameters: input.streamParameters != null ? JSON.parse(input.streamParameters) : undefined,
tenantId,
},
});
Expand Down Expand Up @@ -180,13 +182,13 @@ export const ActivateStreamMutation = extendType({
const { streamName, deviceName, streamParameters, device } = stream;
const uniconfigStreamName = getUniconfigStreamName(streamName, deviceName);
// TODO: create column stream params
const installDeviceParams = prepareInstallParameters(
const installStreamParams = prepareInstallParameters(
uniconfigStreamName,
getMountParamsForStream(device.mountParameters, streamParameters),
);

const uniconfigURL = await getUniconfigURL(prisma, device.uniconfigZoneId);
await installDeviceCache({ uniconfigURL, deviceName: uniconfigStreamName, params: installDeviceParams });
await installDeviceCache({ uniconfigURL, deviceName: uniconfigStreamName, params: installStreamParams });

return { stream };
},
Expand Down

0 comments on commit 3078758

Please sign in to comment.