Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into ftr/eslint-in-api-t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
dmlemeshko committed Aug 26, 2024
2 parents b806b14 + d0e4390 commit 2bed553
Show file tree
Hide file tree
Showing 46 changed files with 2,275 additions and 1,275 deletions.
1 change: 1 addition & 0 deletions .buildkite/ftr_platform_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ enabled:
- x-pack/test/functional/config.firefox.js
- x-pack/test/functional/config.upgrade_assistant.ts
- x-pack/test/functional_cloud/config.ts
- x-pack/test/functional_solution_sidenav/config.ts
- x-pack/test/kubernetes_security/basic/config.ts
- x-pack/test/licensing_plugin/config.public.ts
- x-pack/test/licensing_plugin/config.ts
Expand Down
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,8 @@ x-pack/plugins/observability_solution/observability_shared/public/components/pro

# Shared UX
packages/react @elastic/appex-sharedux
test/functional/page_objects/solution_navigation.ts @elastic/appex-sharedux
/x-pack/test_serverless/functional/page_objects/svl_common_navigation.ts @elastic/appex-sharedux

# OpenAPI spec files
/x-pack/plugins/fleet/common/openapi @elastic/platform-docs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
} from '@kbn/core-chrome-browser';
import type { InternalHttpStart } from '@kbn/core-http-browser-internal';
import {
Subject,
BehaviorSubject,
combineLatest,
map,
Expand All @@ -32,6 +33,7 @@ import {
of,
type Observable,
type Subscription,
timer,
} from 'rxjs';
import { type Location, createLocation } from 'history';
import deepEqual from 'react-fast-compare';
Expand Down Expand Up @@ -326,20 +328,50 @@ export class ProjectNavigationService {
}

const { sideNavComponent, homePage = '' } = definition;
const homePageLink = this.navLinksService?.get(homePage);

if (sideNavComponent) {
this.setSideNavComponent(sideNavComponent);
}

if (homePageLink) {
this.setProjectHome(homePageLink.href);
}
this.waitForLink(homePage, (navLink: ChromeNavLink) => {
this.setProjectHome(navLink.href);
});

this.initNavigation(nextId, definition.navigationTree$);
});
}

/**
* This method waits for the chrome nav link to be available and then calls the callback.
* This is necessary to avoid race conditions when we register the solution navigation
* before the deep links are available (plugins can register them later).
*
* @param linkId The chrome nav link id
* @param cb The callback to call when the link is found
* @returns
*/
private waitForLink(linkId: string, cb: (chromeNavLink: ChromeNavLink) => undefined): void {
if (!this.navLinksService) return;

let navLink: ChromeNavLink | undefined = this.navLinksService.get(linkId);
if (navLink) {
cb(navLink);
return;
}

const stop$ = new Subject<void>();
const tenSeconds = timer(10000);

this.deepLinksMap$.pipe(takeUntil(tenSeconds), takeUntil(stop$)).subscribe((navLinks) => {
navLink = navLinks[linkId];

if (navLink) {
cb(navLink);
stop$.next();
}
});
}

private setProjectHome(homeHref: string) {
this.projectHome$.next(homeHref);
}
Expand Down
41 changes: 39 additions & 2 deletions packages/kbn-apm-synthtrace-client/src/lib/infra/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/* eslint-disable max-classes-per-file */
import { Entity, Fields } from '../entity';
import { Serializable } from '../serializable';
import { k8sNode } from './k8s_node';
import { pod } from './pod';

interface HostDocument extends Fields {
Expand All @@ -20,17 +21,20 @@ interface HostDocument extends Fields {
'host.ip'?: string;
'host.os.name'?: string;
'host.os.version'?: string;
'host.os.platform'?: string;
'cloud.provider'?: string;
}

class Host extends Entity<HostDocument> {
cpu() {
cpu({ cpuTotalValue }: { cpuTotalValue?: number } = {}) {
return new HostMetrics({
...this.fields,
'system.cpu.total.norm.pct': 0.094,
'system.cpu.total.norm.pct': cpuTotalValue ?? 0.98,
'system.cpu.user.pct': 0.805,
'system.cpu.system.pct': 0.704,
'system.cpu.cores': 16,
'process.cpu.pct': 0.1,
'system.cpu.nice.pct': 0.1,
'metricset.period': 10000,
'metricset.name': 'cpu',
});
Expand All @@ -45,6 +49,7 @@ class Host extends Entity<HostDocument> {
'system.memory.total': 68719476736,
'system.memory.used.bytes': 39964708864,
'system.memory.used.pct': 0.582,
'process.memory.pct': 0.1,
'metricset.period': 10000,
'metricset.name': 'memory',
});
Expand Down Expand Up @@ -72,6 +77,22 @@ class Host extends Entity<HostDocument> {
});
}

core() {
return new HostMetrics({
...this.fields,
'system.core.total.pct': 0.98,
'system.core.user.pct': 0.805,
'system.core.nice.pct': 0.704,
'system.core.idle.pct': 0.1,
'system.core.iowait.pct': 0.1,
'system.core.irq.pct': 0.1,
'system.core.softirq.pct': 0.1,
'system.core.steal.pct': 0.1,
'metricset.period': 10000,
'metricset.name': 'core',
});
}

filesystem() {
return new HostMetrics({
...this.fields,
Expand All @@ -96,6 +117,10 @@ class Host extends Entity<HostDocument> {
pod(uid: string) {
return pod(uid, this.fields['host.hostname']);
}

node(podUid: string) {
return k8sNode(this.fields['host.hostname'], podUid);
}
}

export interface HostMetricsDocument extends HostDocument {
Expand All @@ -120,6 +145,17 @@ export interface HostMetricsDocument extends HostDocument {
'system.load'?: { 1: number; cores: number };
'host.network.ingress.bytes'?: number;
'host.network.egress.bytes'?: number;
'process.cpu.pct'?: number;
'process.memory.pct'?: number;
'system.core.total.pct'?: number;
'system.core.user.pct'?: number;
'system.core.nice.pct'?: number;
'system.core.idle.pct'?: number;
'system.core.iowait.pct'?: number;
'system.core.irq.pct'?: number;
'system.core.softirq.pct'?: number;
'system.core.steal.pct'?: number;
'system.cpu.nice.pct'?: number;
}

class HostMetrics extends Serializable<HostMetricsDocument> {}
Expand All @@ -132,6 +168,7 @@ export function host(name: string): Host {
'host.name': name,
'host.ip': '10.128.0.2',
'host.os.name': 'Linux',
'host.os.platform': 'ubuntu',
'host.os.version': '4.19.76-linuxkit',
'cloud.provider': 'gcp',
});
Expand Down
5 changes: 4 additions & 1 deletion packages/kbn-apm-synthtrace-client/src/lib/infra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ import { host, HostMetricsDocument } from './host';
import { k8sContainer, K8sContainerMetricsDocument } from './k8s_container';
import { pod, PodMetricsDocument } from './pod';
import { awsRds, AWSRdsMetricsDocument } from './aws/rds';
import { k8sNode, K8sNodeMetricsDocument } from './k8s_node';

export type InfraDocument =
| HostMetricsDocument
| PodMetricsDocument
| DockerContainerMetricsDocument
| K8sContainerMetricsDocument
| AWSRdsMetricsDocument;
| AWSRdsMetricsDocument
| K8sNodeMetricsDocument;

export const infra = {
host,
pod,
dockerContainer,
k8sContainer,
awsRds,
k8sNode,
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ interface K8sContainerDocument extends Fields {
'container.name'?: string;
'container.image.name'?: string;
'container.runtime'?: string;
'host.name'?: string;
'host.name': string;
'host.hostname': string;
'cloud.provider'?: string;
'cloud.instance.id'?: string;
'cloud.image.id'?: string;
'event.dataset'?: string;
'agent.id': string;
}

export class K8sContainer extends Entity<K8sContainerDocument> {
Expand All @@ -31,13 +33,15 @@ export class K8sContainer extends Entity<K8sContainerDocument> {
...this.fields,
'kubernetes.container.cpu.usage.limit.pct': 46,
'kubernetes.container.memory.usage.limit.pct': 30,
'kubernetes.pod.cpu.usage.limit.pct': 46,
});
}
}

export interface K8sContainerMetricsDocument extends K8sContainerDocument {
'kubernetes.container.cpu.usage.limit.pct': number;
'kubernetes.container.memory.usage.limit.pct': number;
'kubernetes.pod.cpu.usage.limit.pct': number;
}

class K8sContainerMetrics extends Serializable<K8sContainerMetricsDocument> {}
Expand All @@ -51,6 +55,8 @@ export function k8sContainer(id: string, uid: string, nodeName: string): K8sCont
'container.runtime': 'containerd',
'container.image.name': 'image-1',
'host.name': 'host-1',
'host.hostname': 'host-1',
'agent.id': 'synthtrace',
'cloud.instance.id': 'instance-1',
'cloud.image.id': 'image-1',
'cloud.provider': 'aws',
Expand Down
58 changes: 58 additions & 0 deletions packages/kbn-apm-synthtrace-client/src/lib/infra/k8s_node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
/* eslint-disable max-classes-per-file */
import { Entity, Fields } from '../entity';
import { Serializable } from '../serializable';

interface K8sNodeDocument extends Fields {
'kubernetes.node.name': string;
'kubernetes.pod.uid'?: string;
'agent.id': string;
'host.hostname': string;
'host.name': string;
'metricset.name'?: string;
'event.dataset'?: string;
}

export class K8sNode extends Entity<K8sNodeDocument> {
metrics() {
return new K8sNodeMetrics({
...this.fields,
'kubernetes.node.cpu.allocatable.cores': 0.53,
'kubernetes.node.cpu.usage.nanocores': 0.32,
'kubernetes.node.memory.allocatable.bytes': 0.46,
'kubernetes.node.memory.usage.bytes': 0.86,
'kubernetes.node.fs.capacity.bytes': 100,
'kubernetes.node.fs.used.bytes': 100,
'kubernetes.node.pod.allocatable.total': 10,
});
}
}

export interface K8sNodeMetricsDocument extends K8sNodeDocument {
'kubernetes.node.cpu.allocatable.cores': number;
'kubernetes.node.cpu.usage.nanocores': number;
'kubernetes.node.memory.allocatable.bytes': number;
'kubernetes.node.memory.usage.bytes': number;
'kubernetes.node.fs.capacity.bytes': number;
'kubernetes.node.fs.used.bytes': number;
'kubernetes.node.pod.allocatable.total': number;
}

class K8sNodeMetrics extends Serializable<K8sNodeMetricsDocument> {}

export function k8sNode(name: string, podUid: string) {
return new K8sNode({
'kubernetes.node.name': name,
'kubernetes.pod.uid': podUid,
'agent.id': 'synthtrace',
'host.hostname': name,
'host.name': name,
'event.dataset': 'kubernetes.node',
});
}
6 changes: 6 additions & 0 deletions packages/kbn-apm-synthtrace-client/src/lib/infra/pod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { Serializable } from '../serializable';
import { k8sContainer } from './k8s_container';

interface PodDocument extends Fields {
'agent.id': string;
'host.hostname': string;
'host.name': string;
'kubernetes.pod.uid': string;
'kubernetes.node.name': string;
'metricset.name'?: string;
Expand Down Expand Up @@ -40,5 +43,8 @@ export function pod(uid: string, nodeName: string) {
return new Pod({
'kubernetes.pod.uid': uid,
'kubernetes.node.name': nodeName,
'agent.id': 'synthtrace',
'host.hostname': nodeName,
'host.name': nodeName,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ export class InfraSynthtraceEsClient extends SynthtraceEsClient<InfraDocument> {
...options,
pipeline: infraPipeline(),
});
this.dataStreams = ['metrics-*', 'logs-*'];
this.dataStreams = [
'metrics-system*',
'metrics-kubernetes*',
'metrics-docker*',
'metrics-aws*',
'metricbeat-*',
'logs-*',
];
}
}

Expand Down Expand Up @@ -60,7 +67,10 @@ function getRoutingTransform() {
document._index = 'metrics-system.filesystem-default';
} else if (metricset === 'diskio') {
document._index = 'metrics-system.diskio-default';
} else if (metricset === 'core') {
document._index = 'metrics-system.core-default';
} else if ('container.id' in document) {
document._index = 'metrics-docker.container-default';
document._index = 'metrics-kubernetes.container-default';
} else if ('kubernetes.pod.uid' in document) {
document._index = 'metrics-kubernetes.pod-default';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,27 @@ export class InfraSynthtraceKibanaClient {

this.logger.info(`Installed System package ${packageVersion}`);
}

async uninstallSystemPackage(packageVersion: string) {
this.logger.debug(`Uninstalling System package ${packageVersion}`);

const url = join(this.target, `/api/fleet/epm/packages/system/${packageVersion}`);
const response = await pRetry(() => {
return fetch(url, {
method: 'DELETE',
headers: kibanaHeaders(),
body: '{"force":true}',
});
});

const responseJson = await response.json();

if (!responseJson.items) {
throw new Error(
`Failed to uninstall System package version ${packageVersion}, received HTTP ${response.status} and message: ${responseJson.message} for url ${url}`
);
}

this.logger.info(`System package ${packageVersion} uninstalled`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const NavigationItemOpenPanel: FC<Props> = ({ item, navigateToUrl, active
[`nav-item-isActive`]: isActive,
});
const buttonDataTestSubj = classNames(`panelOpener`, `panelOpener-${path}`, {
[`panelOpener-id-${id}`]: id,
[`panelOpener-deepLinkId-${deepLink?.id}`]: !!deepLink,
});

Expand Down
Loading

0 comments on commit 2bed553

Please sign in to comment.