Skip to content

Commit

Permalink
[docs] fix direct branch injection into docs links
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Oct 29, 2021
1 parent efd043e commit 945c87d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 15 deletions.
16 changes: 12 additions & 4 deletions x-pack/plugins/apm/server/deprecations/deprecations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

import { kibanaPackageJson } from '@kbn/dev-utils';

import { GetDeprecationsContext } from '../../../../../src/core/server';
import { CloudSetup } from '../../../cloud/server';
import { getDeprecations } from './';
Expand All @@ -19,7 +21,7 @@ const deprecationContext = {
describe('getDeprecations', () => {
describe('when fleet is disabled', () => {
it('returns no deprecations', async () => {
const deprecationsCallback = getDeprecations({ branch: 'master' });
const deprecationsCallback = getDeprecations({ branch: 'main' });
const deprecations = await deprecationsCallback(deprecationContext);
expect(deprecations).toEqual([]);
});
Expand All @@ -28,7 +30,7 @@ describe('getDeprecations', () => {
describe('when running on cloud with legacy apm-server', () => {
it('returns deprecations', async () => {
const deprecationsCallback = getDeprecations({
branch: 'master',
branch: 'main',
cloudSetup: { isCloudEnabled: true } as unknown as CloudSetup,
fleet: {
start: () => ({
Expand All @@ -38,13 +40,19 @@ describe('getDeprecations', () => {
});
const deprecations = await deprecationsCallback(deprecationContext);
expect(deprecations).not.toEqual([]);
if (kibanaPackageJson.branch === 'main') {
for (const { documentationUrl } of deprecations) {
expect(documentationUrl).toMatch(/\/master\//);
expect(documentationUrl).not.toMatch(/\/main\//);
}
}
});
});

describe('when running on cloud with fleet', () => {
it('returns no deprecations', async () => {
const deprecationsCallback = getDeprecations({
branch: 'master',
branch: 'main',
cloudSetup: { isCloudEnabled: true } as unknown as CloudSetup,
fleet: {
start: () => ({
Expand All @@ -60,7 +68,7 @@ describe('getDeprecations', () => {
describe('when running on prem', () => {
it('returns no deprecations', async () => {
const deprecationsCallback = getDeprecations({
branch: 'master',
branch: 'main',
cloudSetup: { isCloudEnabled: false } as unknown as CloudSetup,
fleet: {
start: () => ({ agentPolicyService: { get: () => undefined } }),
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/apm/server/deprecations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export function getDeprecations({
const isCloudEnabled = !!cloudSetup?.isCloudEnabled;

const hasCloudAgentPolicy = !isEmpty(cloudAgentPolicy);
// TODO: remove when docs support "main"
const docBranch = branch === 'main' ? 'master' : branch;

if (isCloudEnabled && !hasCloudAgentPolicy) {
deprecations.push({
Expand All @@ -48,7 +50,7 @@ export function getDeprecations({
defaultMessage:
'Running the APM Server binary directly is considered a legacy option and is deprecated since 7.16. Switch to APM Server managed by an Elastic Agent instead. Read our documentation to learn more.',
}),
documentationUrl: `https://www.elastic.co/guide/en/apm/server/${branch}/apm-integration.html`,
documentationUrl: `https://www.elastic.co/guide/en/apm/server/${docBranch}/apm-integration.html`,
level: 'warning',
correctiveActions: {
manualSteps: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import { ReportingCore } from '../';
import { deprecations } from '../lib/deprecations';

const REPORTING_USER_ROLE_NAME = 'reporting_user';
const getDocumentationUrl = (branch: string) =>
`https://www.elastic.co/guide/en/kibana/${branch}/kibana-privileges.html`;
const getDocumentationUrl = (branch: string) => {
// TODO: remove when docs support "main"
const docBranch = branch === 'main' ? 'master' : branch;
return `https://www.elastic.co/guide/en/kibana/${docBranch}/kibana-privileges.html`;
};

interface ExtraDependencies {
reportingCore: ReportingCore;
Expand Down
17 changes: 13 additions & 4 deletions x-pack/plugins/security/server/config_deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const securityConfigDeprecationProvider: ConfigDeprecationProvider = ({
(settings, fromPath, addDeprecation, { branch }) => {
const auditLoggingEnabled = settings?.xpack?.security?.audit?.enabled ?? false;
const legacyAuditLoggerEnabled = !settings?.xpack?.security?.audit?.appender;
// TODO: remove when docs support "main"
const docsBranch = branch === 'main' ? 'master' : 'main';
if (auditLoggingEnabled && legacyAuditLoggerEnabled) {
addDeprecation({
configPath: 'xpack.security.audit.appender',
Expand All @@ -44,7 +46,7 @@ export const securityConfigDeprecationProvider: ConfigDeprecationProvider = ({
defaultMessage:
'The legacy audit logger is deprecated in favor of the new ECS-compliant audit logger.',
}),
documentationUrl: `https://www.elastic.co/guide/en/kibana/${branch}/security-settings-kb.html#audit-logging-settings`,
documentationUrl: `https://www.elastic.co/guide/en/kibana/${docsBranch}/security-settings-kb.html#audit-logging-settings`,
correctiveActions: {
manualSteps: [
i18n.translate('xpack.security.deprecations.auditLogger.manualStepOneMessage', {
Expand All @@ -60,6 +62,8 @@ export const securityConfigDeprecationProvider: ConfigDeprecationProvider = ({
// Deprecation warning for the old array-based format of `xpack.security.authc.providers`.
(settings, _fromPath, addDeprecation, { branch }) => {
if (Array.isArray(settings?.xpack?.security?.authc?.providers)) {
// TODO: remove when docs support "main"
const docsBranch = branch === 'main' ? 'master' : 'main';
addDeprecation({
configPath: 'xpack.security.authc.providers',
title: i18n.translate('xpack.security.deprecations.authcProvidersTitle', {
Expand All @@ -69,7 +73,7 @@ export const securityConfigDeprecationProvider: ConfigDeprecationProvider = ({
defaultMessage: 'Use the new object format instead of an array of provider types.',
}),
level: 'warning',
documentationUrl: `https://www.elastic.co/guide/en/kibana/${branch}/security-settings-kb.html#authentication-security-settings`,
documentationUrl: `https://www.elastic.co/guide/en/kibana/${docsBranch}/security-settings-kb.html#authentication-security-settings`,
correctiveActions: {
manualSteps: [
i18n.translate('xpack.security.deprecations.authcProviders.manualSteps1', {
Expand All @@ -85,6 +89,9 @@ export const securityConfigDeprecationProvider: ConfigDeprecationProvider = ({
}
},
(settings, _fromPath, addDeprecation, { branch }) => {
// TODO: remove when docs support "main"
const docsBranch = branch === 'main' ? 'master' : 'main';

const hasProviderType = (providerType: string) => {
const providers = settings?.xpack?.security?.authc?.providers;
if (Array.isArray(providers)) {
Expand Down Expand Up @@ -112,7 +119,7 @@ export const securityConfigDeprecationProvider: ConfigDeprecationProvider = ({
values: { tokenProvider },
}),
level: 'warning',
documentationUrl: `https://www.elastic.co/guide/en/kibana/${branch}/security-settings-kb.html#authentication-security-settings`,
documentationUrl: `https://www.elastic.co/guide/en/kibana/${docsBranch}/security-settings-kb.html#authentication-security-settings`,
correctiveActions: {
manualSteps: [
i18n.translate('xpack.security.deprecations.basicAndTokenProviders.manualSteps1', {
Expand All @@ -126,6 +133,8 @@ export const securityConfigDeprecationProvider: ConfigDeprecationProvider = ({
}
},
(settings, _fromPath, addDeprecation, { branch }) => {
// TODO: remove when docs support "main"
const docsBranch = branch === 'main' ? 'master' : 'main';
const samlProviders = (settings?.xpack?.security?.authc?.providers?.saml ?? {}) as Record<
string,
any
Expand All @@ -145,7 +154,7 @@ export const securityConfigDeprecationProvider: ConfigDeprecationProvider = ({
defaultMessage: 'This setting is no longer used.',
}),
level: 'warning',
documentationUrl: `https://www.elastic.co/guide/en/kibana/${branch}/security-settings-kb.html#authentication-security-settings`,
documentationUrl: `https://www.elastic.co/guide/en/kibana/${docsBranch}/security-settings-kb.html#authentication-security-settings`,
correctiveActions: {
manualSteps: [
i18n.translate('xpack.security.deprecations.maxRedirectURLSize.manualSteps1', {
Expand Down
15 changes: 12 additions & 3 deletions x-pack/plugins/security/server/deprecations/kibana_user_role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ async function getUsersDeprecations(
return [];
}

// TODO: remove when docs support "main"
const docsBranch = packageInfo.branch === 'main' ? 'master' : 'main';

return [
{
title: getDeprecationTitle(),
message: getDeprecationMessage(),
level: 'warning',
deprecationType: 'feature',
documentationUrl: `https://www.elastic.co/guide/en/elasticsearch/reference/${packageInfo.branch}/built-in-roles.html`,
documentationUrl: `https://www.elastic.co/guide/en/elasticsearch/reference/${docsBranch}/built-in-roles.html`,
correctiveActions: {
api: {
method: 'POST',
Expand Down Expand Up @@ -159,13 +162,16 @@ async function getRoleMappingsDeprecations(
return [];
}

// TODO: remove when docs support "main"
const docsBranch = packageInfo.branch === 'main' ? 'master' : 'main';

return [
{
title: getDeprecationTitle(),
message: getDeprecationMessage(),
level: 'warning',
deprecationType: 'feature',
documentationUrl: `https://www.elastic.co/guide/en/elasticsearch/reference/${packageInfo.branch}/built-in-roles.html`,
documentationUrl: `https://www.elastic.co/guide/en/elasticsearch/reference/${docsBranch}/built-in-roles.html`,
correctiveActions: {
api: {
method: 'POST',
Expand Down Expand Up @@ -193,6 +199,9 @@ async function getRoleMappingsDeprecations(
function deprecationError(packageInfo: PackageInfo, error: Error): DeprecationsDetails[] {
const title = getDeprecationTitle();

// TODO: remove when docs support "main"
const docsBranch = packageInfo.branch === 'main' ? 'master' : 'main';

if (getErrorStatusCode(error) === 403) {
return [
{
Expand All @@ -202,7 +211,7 @@ function deprecationError(packageInfo: PackageInfo, error: Error): DeprecationsD
message: i18n.translate('xpack.security.deprecations.kibanaUser.forbiddenErrorMessage', {
defaultMessage: 'You do not have enough permissions to fix this deprecation.',
}),
documentationUrl: `https://www.elastic.co/guide/en/kibana/${packageInfo.branch}/xpack-security.html#_required_permissions_7`,
documentationUrl: `https://www.elastic.co/guide/en/kibana/${docsBranch}/xpack-security.html#_required_permissions_7`,
correctiveActions: {
manualSteps: [
i18n.translate(
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/task_manager/server/lib/log_health_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export function logHealthMetrics(
}

const message = `Latest Monitored Stats: ${JSON.stringify(monitoredHealth)}`;
const docLink = `https://www.elastic.co/guide/en/kibana/${kibanaPackageJson.branch}/task-manager-health-monitoring.html`;
// TODO: remove when docs support "main"
const docsBranch = kibanaPackageJson.branch === 'main' ? 'master' : 'main';

const docLink = `https://www.elastic.co/guide/en/kibana/${docsBranch}/task-manager-health-monitoring.html`;
const detectedProblemMessage = `Task Manager detected a degradation in performance. This is usually temporary, and Kibana can recover automatically. If the problem persists, check the docs for troubleshooting information: ${docLink} .`;
if (enabled) {
const driftInSeconds = (monitoredHealth.stats.runtime?.value.drift.p99 ?? 0) / 1000;
Expand Down

0 comments on commit 945c87d

Please sign in to comment.