Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Stream details page #19342

Merged
merged 19 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -49,6 +49,11 @@
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.bson.types.ObjectId;
import org.graylog.grn.GRNTypes;
import org.graylog.plugins.pipelineprocessor.db.PipelineDao;
import org.graylog.plugins.pipelineprocessor.db.PipelineService;
import org.graylog.plugins.pipelineprocessor.db.PipelineStreamConnectionsService;
import org.graylog.plugins.pipelineprocessor.rest.PipelineCompactSource;
import org.graylog.plugins.pipelineprocessor.rest.PipelineConnections;
import org.graylog.plugins.views.startpage.recentActivities.RecentActivityService;
import org.graylog.security.UserContext;
import org.graylog2.audit.AuditEventSender;
Expand Down Expand Up @@ -103,6 +108,7 @@
import org.joda.time.format.ISODateTimeFormat;

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -154,6 +160,8 @@ public class StreamResource extends RestResource {
private final BulkExecutor<Stream, UserContext> bulkStreamDeleteExecutor;
private final BulkExecutor<Stream, UserContext> bulkStreamStartExecutor;
private final BulkExecutor<Stream, UserContext> bulkStreamStopExecutor;
private final PipelineStreamConnectionsService pipelineStreamConnectionsService;
private final PipelineService pipelineService;

private final DbQueryCreator dbQueryCreator;
private final Set<StreamDeletionGuard> streamDeletionGuards;
Expand All @@ -167,13 +175,17 @@ public StreamResource(StreamService streamService,
RecentActivityService recentActivityService,
AuditEventSender auditEventSender,
MessageFactory messageFactory,
Set<StreamDeletionGuard> streamDeletionGuards) {
Set<StreamDeletionGuard> streamDeletionGuards,
PipelineStreamConnectionsService pipelineStreamConnectionsService,
PipelineService pipelineService) {
this.streamService = streamService;
this.streamRuleService = streamRuleService;
this.streamRouterEngineFactory = streamRouterEngineFactory;
this.indexSetRegistry = indexSetRegistry;
this.paginatedStreamService = paginatedStreamService;
this.messageFactory = messageFactory;
this.pipelineStreamConnectionsService = pipelineStreamConnectionsService;
this.pipelineService = pipelineService;
this.dbQueryCreator = new DbQueryCreator(StreamImpl.FIELD_TITLE, attributes);
this.recentActivityService = recentActivityService;
final SuccessContextCreator<Stream> successAuditLogContextCreator = (entity, entityClass) ->
Expand Down Expand Up @@ -596,6 +608,21 @@ public Response cloneStream(@ApiParam(name = "streamId", required = true) @PathP
return Response.created(streamUri).entity(result).build();
}

@GET
@Path("/{streamId}/pipelines")
@ApiOperation(value = "Get pipelines associated with a stream")
@Produces(MediaType.APPLICATION_JSON)
public List<PipelineCompactSource> getConnectedPipelines(@ApiParam(name = "streamId", required = true) @PathParam("streamId") String streamId) throws NotFoundException {
PipelineConnections pipelineConnections = pipelineStreamConnectionsService.load(streamId);
List<PipelineCompactSource> list = new ArrayList<>();

for (String id : pipelineConnections.pipelineIds()) {
PipelineDao pipelineDao = pipelineService.load(id);
list.add(PipelineCompactSource.create(pipelineDao.id(), pipelineDao.title()));
}
return list;
}

@PUT
@Path("/indexSet/{indexSetId}")
@Timed
Expand Down
22 changes: 22 additions & 0 deletions graylog2-web-interface/src/@types/graylog-web-plugin/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ type DataTiering = {
}>,
}

interface PluginDataWarehouse {
DataWarehouseStatus: React.ComponentType<{
stream: {
enabled_status: boolean;
}
}>,
StreamDataWarehouse: React.ComponentType<{}>,
}

type FieldValueProvider = {
type: string,
displayName: string,
Expand All @@ -153,12 +162,25 @@ type FieldValueProvider = {
key_field?: string,
},
}

interface PluginDataWarehouse {
DataWarehouseStatus: React.ComponentType<{
stream: {
enabled_status: boolean;
}
}>,
StreamDataWarehouse: React.ComponentType<{}>,
DataWarehouseJobs: React.ComponentType<{}>,
}

declare module 'graylog-web-plugin/plugin' {
interface PluginExports {
navigation?: Array<PluginNavigation>;
dataWarehouse?: Array<PluginDataWarehouse>
dataTiering?: Array<DataTiering>
defaultNavigation?: Array<PluginNavigation>;
navigationItems?: Array<PluginNavigationItems>;
dataWarehouse?: Array<PluginDataWarehouse>
globalNotifications?: Array<GlobalNotification>;
fieldValueProviders?:Array<FieldValueProvider>;
// Global context providers allow to fetch and process data once
Expand Down
14 changes: 8 additions & 6 deletions graylog2-web-interface/src/components/common/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,27 @@ const Container = styled.div(({ theme }) => css`
padding: 15px;
`);

const Header = styled.div`
const Header = styled.div<{ $alignActionsLeft: boolean; }>(({ theme, $alignActionsLeft }) => css`
display: flex;
justify-content: space-between;
justify-content: ${$alignActionsLeft ? 'flex-start' : 'space-between'};
${$alignActionsLeft ? `gap: ${theme.spacings.sm};` : 'gap: 5px;'};
align-items: center;
margin-bottom: 10px;
flex-wrap: wrap;
gap: 5px;
`;
`);

type Props = React.PropsWithChildren<{
title: React.ReactNode,
actions?: React.ReactNode,
alignActionLeft?: boolean,
}>

/**
* Simple section component. Currently only a "filled" version exists.
*/
const Section = ({ title, actions, children }: Props) => (
const Section = ({ title, actions, children, alignActionLeft }: Props) => (
<Container>
<Header>
<Header $alignActionsLeft={alignActionLeft}>
<h2>{title}</h2>
{actions && <div>{actions}</div>}
</Header>
Expand All @@ -54,6 +55,7 @@ const Section = ({ title, actions, children }: Props) => (

Section.defaultProps = {
actions: undefined,
alignActionLeft: false,
};

export default Section;
29 changes: 29 additions & 0 deletions graylog2-web-interface/src/components/common/Text.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import * as React from 'react';
import type { TextProps } from '@mantine/core';
import { Text as MantineText } from '@mantine/core';

type Props = {
children: string,
} & TextProps;

const Text = ({ ...props }: Props) => (
<MantineText {...props} />
);

export default Text;
1 change: 1 addition & 0 deletions graylog2-web-interface/src/components/common/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export { default as TimeUnit } from './TimeUnit';
export { default as TimeUnitInput } from './TimeUnitInput';
export { default as Timestamp } from './Timestamp';
export { default as TimezoneSelect } from './TimezoneSelect';
export { default as Text } from './Text';
export { default as Tooltip } from './Tooltip';
export { default as TypeAheadDataFilter } from './TypeAheadDataFilter';
export { default as TypeAheadFieldInput } from './TypeAheadFieldInput';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import * as React from 'react';
import { useCallback, useState } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import PropTypes from 'prop-types';

import { Button } from 'components/bootstrap';
import type { BsSize } from 'components/bootstrap/types';
import type { StyleProps } from 'components/bootstrap/Button';
import type { StreamRule } from 'stores/streams/StreamsStore';
import { StreamRulesStore } from 'stores/streams/StreamRulesStore';
import UserNotification from 'util/UserNotification';

import StreamRuleModal from './StreamRuleModal';

type Props = {
bsSize?: BsSize,
bsStyle?: StyleProps,
buttonText?: string,
className?: string,
streamId: string,
}

const CreateStreamRuleButton = ({ bsSize, bsStyle, buttonText, className, streamId }: Props) => {
const [showCreateModal, setShowCreateModal] = useState(false);
const queryClient = useQueryClient();
const toggleCreateModal = useCallback(() => setShowCreateModal((cur) => !cur), []);

const onSaveStreamRule = useCallback((_streamRuleId: string, streamRule: StreamRule) => StreamRulesStore.create(streamId, streamRule, () => {
UserNotification.success('Stream rule was created successfully.', 'Success');
queryClient.invalidateQueries(['stream', streamId]);
}), [streamId, queryClient]);

return (
<>
<Button bsSize={bsSize}
bsStyle={bsStyle}
className={className}
onClick={toggleCreateModal}>
{buttonText}
</Button>
{showCreateModal && (
<StreamRuleModal onClose={toggleCreateModal}
title="New Stream Rule"
submitButtonText="Create Rule"
submitLoadingText="Creating Rule..."
onSubmit={onSaveStreamRule} />

)}
{}
</>
);
};

CreateStreamRuleButton.propTypes = {
buttonText: PropTypes.string,
bsStyle: PropTypes.string,
bsSize: PropTypes.string,
className: PropTypes.string,
streamId: PropTypes.string,
};

CreateStreamRuleButton.defaultProps = {
buttonText: 'Create Rule',
bsSize: undefined,
bsStyle: undefined,
className: undefined,
streamId: undefined,
};

export default CreateStreamRuleButton;
Loading
Loading