Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export async function checkForEmailValue(
}
}

export function getEmailValueStructure(email) {
return {
xpack: {
default_admin_email: email
}
};
}
Copy link
Member

Choose a reason for hiding this comment

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

Since the collector constructor spreads in any property given to it, we can make this function a part of the settings collector instance.

something like:

collectorSet.makeStatsCollector({	
  type: ...,
  async fetch: ...,
  getEmailValueStructure: email => ({
    xpack: { default_admin_email: email }
  })
})

In the line below where getEmailValueStructure is used in the fetch, it can use this.getEmailValueStructure(defaultAdminEmail)


export function getSettingsCollector(server) {
const config = server.config();
const { collectorSet } = server.usage;
Expand All @@ -65,11 +73,7 @@ export function getSettingsCollector(server) {

// skip everything if defaultAdminEmail === undefined
if (defaultAdminEmail || (defaultAdminEmail === null && shouldUseNull)) {
kibanaSettingsData = {
xpack: {
default_admin_email: defaultAdminEmail
}
};
kibanaSettingsData = getEmailValueStructure(defaultAdminEmail);
this.log.debug(`[${defaultAdminEmail}] default admin email setting found, sending [${KIBANA_SETTINGS_TYPE}] monitoring document.`);
} else {
this.log.debug(`not sending [${KIBANA_SETTINGS_TYPE}] monitoring document because [${defaultAdminEmail}] is null or invalid.`);
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/xpack_main/server/routes/api/v1/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { wrap as wrapError } from 'boom';
import { KIBANA_SETTINGS_TYPE } from '../../../../../monitoring/common/constants';
import { getKibanaInfoForStats } from '../../../../../monitoring/server/kibana_monitoring/lib';
import { getEmailValueStructure } from '../../../../../monitoring/server/kibana_monitoring/collectors/get_settings_collector';
Copy link
Member

Choose a reason for hiding this comment

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

we should be able to not have this import when getEmailValueStructure is a method of settingsCollector


const getClusterUuid = async callCluster => {
const { cluster_uuid: uuid } = await callCluster('info', { filterPath: 'cluster_uuid', });
Expand All @@ -26,7 +27,10 @@ export function settingsRoute(server, kbnServer) {
const { collectorSet } = server.usage;
const settingsCollector = collectorSet.getCollectorByType(KIBANA_SETTINGS_TYPE);

const settings = await settingsCollector.fetch(callCluster);
let settings = await settingsCollector.fetch(callCluster);
if (!settings) {
settings = getEmailValueStructure(null);
}
const uuid = await getClusterUuid(callCluster);

const kibana = getKibanaInfoForStats(server, kbnServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function ({ getService }) {
expect(body.settings.kibana.transport_address.length > 0).to.eql(true);
expect(body.settings.kibana.version.length > 0).to.eql(true);
expect(body.settings.kibana.status.length > 0).to.eql(true);
expect(body.settings.xpack.default_admin_email).to.eql(null);
});
});
});
Expand Down