Skip to content

Commit

Permalink
Move AppInsights output to xui-webapp-appinsights-<env> (#3745)
Browse files Browse the repository at this point in the history
* First attempt at sorting out appinsights

* Bumping chart version/ fixing aliases

* vuln

* vuln

* revert terraform changes - these will be done in a separate PR 3771

* Fix App Insights test (#3773)

* debug logging

* correctly init appInsights

* lint

---------

Co-authored-by: hmcts-jenkins-j-to-z <61242337+hmcts-jenkins-j-to-z[bot]@users.noreply.github.com>
Co-authored-by: Dan Lysiak <[email protected]>
  • Loading branch information
3 people committed Jul 29, 2024
1 parent 672ddce commit f0c5a48
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions Jenkinsfile_CNP
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def secrets = [
secret('test-email', 'TEST_EMAIL'),
secret('test-password', 'TEST_PASSWORD'),
secret('appinsights-instrumentationkey-mc', 'APPINSIGHTS_INSTRUMENTATIONKEY'),
secret('appinsights-connection-string-mc', 'APPINSIGHTS_CONNECTION_STRING'),
secret('system-user-name', 'SYSTEM_USER_NAME'),
secret('system-user-password', 'SYSTEM_USER_PASSWORD')
],
Expand Down
1 change: 1 addition & 0 deletions Jenkinsfile_parameterized
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ List<LinkedHashMap<String, Object>> secrets = [
secret('mc-s2s-client-secret', 'S2S_SECRET'),
secret('mc-idam-client-secret', 'IDAM_SECRET'),
secret('appinsights-instrumentationkey-mc', 'APPINSIGHTS_INSTRUMENTATIONKEY'),
secret('appinsights-connection-string-mc', 'APPINSIGHTS_CONNECTION_STRING'),
secret('launch-darkly-client-id', 'LAUNCH_DARKLY_CLIENT_ID'),
secret('system-user-name', 'SYSTEM_USER_NAME'),
secret('system-user-password', 'SYSTEM_USER_PASSWORD')
Expand Down
1 change: 1 addition & 0 deletions api/.env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ NODE_CONFIG_ENV=development
#IDAM_SECRET=AAA
#S2S_SECRET=AAA
APPINSIGHTS_INSTRUMENTATIONKEY=AAA
APPINSIGHTS_CONNECTION_STRING=BBB
LAUNCH_DARKLY_CLIENT_ID=5de6610b23ce5408280f2268

# PROXY
Expand Down
2 changes: 2 additions & 0 deletions api/configuration/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
export const S2S_SECRET = 'secrets.rpx.mc-s2s-client-secret';
export const REDIS_CLOUD_URL = 'secrets.rpx.webapp-redis-connection-string';
export const APP_INSIGHTS_KEY = 'secrets.rpx.appinsights-instrumentationkey-mc';
export const APP_INSIGHTS_CONNECTION_STRING = 'secrets.rpx.appinsights-connection-string-mc';

export const LAUNCH_DARKLY_CLIENT_ID = 'secrets.rpx.launch-darkly-client-id';

export const COOKIES_TOKEN = 'cookies.token';
Expand Down
1 change: 1 addition & 0 deletions api/interfaces/environment.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface EnvironmentConfig {
appInsightsInstrumentationKey: string;
appInsightsConnectionString: string;
configEnv: string;
cookies: EnvironmentConfigCookies;
exceptionOptions: EnvironmentConfigExceptionOptions;
Expand Down
5 changes: 3 additions & 2 deletions api/lib/appInsights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import * as applicationinsights from 'applicationinsights';
import * as express from 'express';
import { getConfigValue, showFeature } from '../configuration/';
import {
APP_INSIGHTS_KEY, FEATURE_APP_INSIGHTS_ENABLED
APP_INSIGHTS_CONNECTION_STRING,
FEATURE_APP_INSIGHTS_ENABLED
} from '../configuration/references';

export let client: applicationinsights.TelemetryClient;

if (showFeature(FEATURE_APP_INSIGHTS_ENABLED)) {
applicationinsights
.setup(getConfigValue(APP_INSIGHTS_KEY))
.setup(getConfigValue(APP_INSIGHTS_CONNECTION_STRING))
.setAutoDependencyCorrelation(true)
.setAutoCollectRequests(true)
.setAutoCollectPerformance(true)
Expand Down
7 changes: 5 additions & 2 deletions api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import accessManagementRouter from './accessManagement/routes';
import { router as caseShareRoutes } from './caseshare/routes';
import { router as challengedAccessRouter } from './challengedAccess/routes';
import { getConfigValue, showFeature } from './configuration';
import { APP_INSIGHTS_KEY } from './configuration/references';
import { APP_INSIGHTS_CONNECTION_STRING, APP_INSIGHTS_KEY } from './configuration/references';
import { router as globalSearchRoutes } from './globalSearch/routes';
import healthCheck from './healthCheck';
import { router as hearingsRouter } from './hearings/routes';
Expand All @@ -25,7 +25,10 @@ const router = express.Router({ mergeParams: true });
router.use('/healthCheck', healthCheck);

router.get('/monitoring-tools', (req, res) => {
res.send({ key: getConfigValue(APP_INSIGHTS_KEY) });
res.send({
key: getConfigValue(APP_INSIGHTS_KEY),
connectionString: getConfigValue(APP_INSIGHTS_CONNECTION_STRING)
});
});

router.get('/configuration', (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion charts/xui-webapp/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: xui-webapp
home: https://github.com/hmcts/rpx-xui-webapp
version: 1.0.17
version: 1.0.18
description: Expert UI
maintainers:
- name: HMCTS RPX XUI
Expand Down
1 change: 1 addition & 0 deletions charts/xui-webapp/values.preview.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ nodejs:
rpx:
secrets:
- appinsights-instrumentationkey-mc
- appinsights-connection-string-mc
- mc-s2s-client-secret
- mc-idam-client-secret
- system-user-name
Expand Down
1 change: 1 addition & 0 deletions charts/xui-webapp/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ nodejs:
- mc-s2s-client-secret
- mc-idam-client-secret
- appinsights-instrumentationkey-mc
- appinsights-connection-string-mc
- name: webapp-redis6-connection-string
alias: webapp-redis-connection-string
- launch-darkly-client-id
Expand Down
1 change: 1 addition & 0 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"secrets": {
"rpx": {
"appinsights-instrumentationkey-mc": "APPINSIGHTS_INSTRUMENTATIONKEY",
"appinsights-connection-string-mc": "APPINSIGHTS_CONNECTION_STRING",
"mc-s2s-client-secret": "S2S_SECRET",
"mc-idam-client-secret": "IDAM_SECRET",
"webapp-redis-connection-string": "REDISCLOUD_URL",
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ output "appInsightsInstrumentationKey" {
output "appInsightsConnectionString" {
value = azurerm_application_insights.appinsight.connection_string
sensitive = true
}
}
2 changes: 1 addition & 1 deletion src/app/services/logger/monitoring.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { of } from 'rxjs';
import { MonitoringService } from './monitoring.service';

describe('Monitoring service', () => {
const mockedHttpClient = jasmine.createSpyObj('mockedHttpClient', { get: of({ key: 'Some Value' }) });
const mockedHttpClient = jasmine.createSpyObj('mockedHttpClient', { get: of({ connectionString: 'InstrumentationKey=dummy' }) });

it('should be Truthy', () => {
const service = new MonitoringService(mockedHttpClient);
Expand Down
11 changes: 7 additions & 4 deletions src/app/services/logger/monitoring.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface IMonitoringService {

export class MonitorConfig implements IConfig {
public instrumentationKey?: string;
public connectionString?: string;
public endpointUrl?: string;
public emitLineDelimitedJson?: boolean;
public accountId?: string;
Expand Down Expand Up @@ -83,14 +84,16 @@ export class MonitoringService implements IMonitoringService {
}

private send(func: () => any): void {
if (this.config?.instrumentationKey) {
if (this.config?.connectionString) {
func();
} else {
// will only get run once per login
this.http.get('/api/monitoring-tools').subscribe((it) => {
this.http.get('/api/monitoring-tools').subscribe((monitor) => {
// eslint-disable-next-line dot-notation
const connStr = monitor['connectionString'];
console.log('Setting appInsights connection string to ' + connStr);
this.config = {
// eslint-disable-next-line dot-notation
instrumentationKey: it['key']
connectionString: connStr
};
if (!this.areCookiesEnabled) {
this.config = {
Expand Down

0 comments on commit f0c5a48

Please sign in to comment.