Skip to content

Commit

Permalink
[Fleet] Add flag for prerelease to templates/inputs endpoint (elastic…
Browse files Browse the repository at this point in the history
…#174471)

Fixes elastic#172667

## Summary
Some of the integrations show directly the prerelease version of the
package in the overview section, but this wasn't happening in the
"configs" section. Here I'm adding a flag to the
`templates/{pkgName}/{pkgVersion}/inputs` endpoint that allows to select
the prerelease tag as well:
```
  GET kbn:api/fleet/epm/templates/{pkgName}/{pkgVersion}/inputs?format=yaml&prerelease=true
```
One example is the Istio package:
```
  GET kbn:api/fleet/epm/templates/istio/0.5.0/inputs?format=yaml&prerelease=true
```

### Istio overview - before

![Screenshot 2024-01-08 at 17 45
16](https://github.com/elastic/kibana/assets/16084106/bd48faac-5499-4de5-87f0-8addf5ec9961)

### Istio overview - after
![Screenshot 2024-01-09 at 10 15
02](https://github.com/elastic/kibana/assets/16084106/1aac5cfa-911a-498e-bc9b-4422e3c11c02)


### Checklist
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
criamico authored and nreese committed Jan 10, 2024
1 parent a7d80fb commit f357620
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 8 deletions.
8 changes: 8 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,14 @@
"name": "format",
"description": "Format of response - json or yaml",
"in": "query"
},
{
"schema": {
"type": "boolean"
},
"name": "prerelease",
"description": "Specify if version is prerelease",
"in": "query"
}
]
},
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,11 @@ paths:
name: format
description: Format of response - json or yaml
in: query
- schema:
type: boolean
name: prerelease
description: Specify if version is prerelease
in: query
/agents/setup:
get:
summary: Get agent setup info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ parameters:
name: format
description: 'Format of response - json or yaml'
in: query
- schema:
type: boolean
name: prerelease
description: 'Specify if version is prerelease'
in: query
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/rest_spec/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export interface GetInputsTemplatesRequest {
};
query: {
format: 'json' | 'yml' | 'yaml';
prerelease?: boolean;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { FormattedMessage } from '@kbn/i18n-react';
import type { PackageInfo } from '../../../../../types';

import { useGetInputsTemplatesQuery, useStartServices } from '../../../../../hooks';
import { PrereleaseCallout } from '../overview/overview';

import { isPackagePrerelease } from '../../../../../../../../common/services';

interface ConfigsProps {
packageInfo: PackageInfo;
Expand All @@ -33,11 +36,15 @@ export const Configs: React.FC<ConfigsProps> = ({ packageInfo }) => {
const { name: pkgName, version: pkgVersion, title: pkgTitle } = packageInfo;
const notInstalled = packageInfo.status !== 'installing';

const isPrerelease = isPackagePrerelease(packageInfo.version);
const {
data: configs,
error,
isLoading,
} = useGetInputsTemplatesQuery({ pkgName, pkgVersion }, { format: 'yaml' });
} = useGetInputsTemplatesQuery(
{ pkgName, pkgVersion },
{ format: 'yaml', prerelease: isPrerelease }
);

if (error) {
notifications.toasts.addError(error, {
Expand All @@ -55,6 +62,15 @@ export const Configs: React.FC<ConfigsProps> = ({ packageInfo }) => {
<EuiSkeletonText lines={10} />
) : (
<>
{isPrerelease && (
<>
<EuiSpacer size="s" />
<PrereleaseCallout
packageName={packageInfo.name}
packageTitle={packageInfo.title}
/>
</>
)}
<EuiText>
<p>
<FormattedMessage
Expand Down Expand Up @@ -82,7 +98,7 @@ export const Configs: React.FC<ConfigsProps> = ({ packageInfo }) => {
</EuiText>
{notInstalled && (
<>
<EuiSpacer size="m" />
<EuiSpacer size="s" />
<EuiCallOut
title={
<FormattedMessage
Expand All @@ -95,7 +111,7 @@ export const Configs: React.FC<ConfigsProps> = ({ packageInfo }) => {
/>
</>
)}
<EuiSpacer size="m" />
<EuiSpacer size="s" />
<EuiCodeBlock language="yaml" isCopyable={true} paddingSize="s" overflowHeight={1000}>
{configs}
</EuiCodeBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const UnverifiedCallout: React.FC = () => {
);
};

const PrereleaseCallout: React.FC<{
export const PrereleaseCallout: React.FC<{
packageName: string;
latestGAVersion?: string;
packageTitle: string;
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/fleet/server/routes/epm/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,12 +579,12 @@ export const getInputsHandler: FleetRequestHandler<

try {
const { pkgName, pkgVersion } = request.params;
const { format } = request.query;
const { format, prerelease } = request.query;
let body;
if (format === 'json') {
body = await getTemplateInputs(soClient, pkgName, pkgVersion, 'json');
body = await getTemplateInputs(soClient, pkgName, pkgVersion, 'json', prerelease);
} else if (format === 'yml' || format === 'yaml') {
body = await getTemplateInputs(soClient, pkgName, pkgVersion, 'yml');
body = await getTemplateInputs(soClient, pkgName, pkgVersion, 'yml', prerelease);
}
return response.ok({ body });
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export async function getTemplateInputs(
soClient: SavedObjectsClientContract,
pkgName: string,
pkgVersion: string,
format: Format
format: Format,
prerelease?: boolean
) {
const packageInfoMap = new Map<string, PackageInfo>();
let packageInfo: PackageInfo;
Expand All @@ -86,6 +87,7 @@ export async function getTemplateInputs(
savedObjectsClient: soClient,
pkgName,
pkgVersion,
prerelease,
});
}
const emptyPackagePolicy = packageToPackagePolicy(packageInfo, '');
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/types/rest_spec/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,6 @@ export const GetInputsRequestSchema = {
format: schema.oneOf([schema.literal('json'), schema.literal('yml'), schema.literal('yaml')], {
defaultValue: 'json',
}),
prerelease: schema.maybe(schema.boolean()),
}),
};
12 changes: 12 additions & 0 deletions x-pack/test/fleet_api_integration/apis/epm/get_templates_inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export default function (providerContext: FtrProviderContext) {
const testPkgName = 'apache';
const testPkgVersion = '0.1.4';

const prereleasePkgName = 'prerelease';
const prereleasePkgVersion = '0.1.0-dev.0+abc';

const uninstallPackage = async (name: string, version: string) => {
await supertest.delete(`/api/fleet/epm/packages/${name}/${version}`).set('kbn-xsrf', 'xxxx');
};
Expand All @@ -45,6 +48,7 @@ export default function (providerContext: FtrProviderContext) {
});
after(async () => {
await uninstallPackage(testPkgName, testPkgVersion);
await uninstallPackage(testPkgName, testPkgVersion);
});
const expectedYml = `inputs:
- id: logfile-apache.access
Expand Down Expand Up @@ -177,6 +181,14 @@ export default function (providerContext: FtrProviderContext) {
expect(res.text).to.eql(expectedYml);
});

it('returns inputs template for a prerelease package if prerelease=true', async function () {
await supertest
.get(
`/api/fleet/epm/templates/${prereleasePkgName}/${prereleasePkgVersion}/inputs?format=json&prerelease=true`
)
.expect(200);
});

it('returns a 404 for a version that does not exists', async function () {
await supertest
.get(`/api/fleet/epm/templates/${testPkgName}/0.1.0/inputs?format=json`)
Expand Down

0 comments on commit f357620

Please sign in to comment.