Skip to content

Commit

Permalink
Merge branch 'master' into update-stream-telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
ousmaneo authored Sep 30, 2024
2 parents 2c3a18e + 8e00cd1 commit eee2e67
Show file tree
Hide file tree
Showing 45 changed files with 402 additions and 162 deletions.
9 changes: 9 additions & 0 deletions changelog/unreleased/issue-13822.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type = "fixed"
message = "Fix link target for search query error documentation links."

issues = ["13822"]
pulls = ["20563"]

details.user = """
The documentation link now points to the error types section again, instead of just the search query page.
"""
5 changes: 5 additions & 0 deletions changelog/unreleased/pr-20558.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "c" # One of: a(dded), c(hanged), d(eprecated), r(emoved), f(ixed), s(ecurity)
message = "API endpoint for listing users will not return an error anymore when user is lacking permission, but return current user only instead."

issues = []
pulls = ["20558"]
4 changes: 2 additions & 2 deletions graylog-plugin-archetype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>3.2.1</version>
<version>3.3.0</version>
</extension>
</extensions>

Expand Down Expand Up @@ -84,7 +84,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
2 changes: 1 addition & 1 deletion graylog-project-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@
<plugin>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
<version>7.6.4</version>
<version>7.6.5</version>
</plugin>
</plugins>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.graylog2.plugin.outputs.FilteredMessageOutput;
import org.graylog2.plugin.outputs.MessageOutput;
import org.graylog2.shared.messageq.MessageQueueAcknowledger;
import org.graylog2.system.shutdown.GracefulShutdownHook;
import org.graylog2.system.shutdown.GracefulShutdownService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -54,7 +56,7 @@
* registered {@link FilteredMessageOutput} outputs.
*/
@Singleton
public class BatchedMessageFilterOutput implements MessageOutput {
public class BatchedMessageFilterOutput implements MessageOutput, GracefulShutdownHook {
private static final Logger LOG = LoggerFactory.getLogger(BatchedMessageFilterOutput.class);

private final Map<String, FilteredMessageOutput> outputs;
Expand All @@ -72,8 +74,9 @@ public class BatchedMessageFilterOutput implements MessageOutput {
private final MessageQueueAcknowledger acknowledger;
private final Meter outputWriteFailures;
private final Timer processTime;
private ScheduledFuture<?> flushTask;
private final GracefulShutdownService gracefulShutdownService;
private final IndexSetAwareMessageOutputBuffer buffer;
private ScheduledFuture<?> flushTask;

@Inject
public BatchedMessageFilterOutput(Map<String, FilteredMessageOutput> outputs,
Expand All @@ -82,6 +85,7 @@ public BatchedMessageFilterOutput(Map<String, FilteredMessageOutput> outputs,
Cluster cluster,
MessageQueueAcknowledger acknowledger,
IndexSetAwareMessageOutputBuffer indexSetAwareMessageOutputBuffer,
GracefulShutdownService gracefulShutdownService,
@Named("output_flush_interval") int outputFlushInterval,
@Named("shutdown_timeout") int shutdownTimeoutMs,
@Named("daemonScheduler") ScheduledExecutorService daemonScheduler) {
Expand All @@ -105,6 +109,7 @@ public BatchedMessageFilterOutput(Map<String, FilteredMessageOutput> outputs,
this.bufferFlushesRequested = metricRegistry.meter(name(this.getClass(), "bufferFlushesRequested"));
this.processTime = metricRegistry.timer(name(this.getClass(), "processTime"));
this.outputWriteFailures = metricRegistry.meter(name(this.getClass(), "outputWriteFailures"));
this.gracefulShutdownService = gracefulShutdownService;
}

@Override
Expand All @@ -119,6 +124,7 @@ public void initialize() throws Exception {
LOG.error("Caught exception while trying to flush outputs", e);
}
}, outputFlushInterval.toMillis(), outputFlushInterval.toMillis(), TimeUnit.MILLISECONDS);
gracefulShutdownService.register(this);
}

@VisibleForTesting
Expand Down Expand Up @@ -211,6 +217,16 @@ void cancelFlushTask() {
@Override
public void stop() {
LOG.debug("Stopping output filter");
doGracefulShutdown();
try {
gracefulShutdownService.unregister(this);
} catch (IllegalStateException e) {
LOG.debug("Couldn't unregister from graceful shutdown service: {}", e.getMessage());
}
}

@Override
public void doGracefulShutdown() {
cancelFlushTask();

if (cluster.isConnected() && cluster.isDeflectorHealthy()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.graylog.plugins.views.search.permissions.SearchUser;
import org.graylog.security.UserContext;
import org.graylog.security.authservice.AuthServiceBackendDTO;
import org.graylog.security.authservice.GlobalAuthServiceConfig;
Expand Down Expand Up @@ -233,17 +234,23 @@ private UserSummary returnSummary(UserContext userContext, User user) {
*/
@GET
@Deprecated
@RequiresPermissions(RestPermissions.USERS_LIST)
@ApiOperation(value = "List all users", notes = "Permissions and session data included by default")
public UserList listUsers(
@ApiParam(name = "include_permissions") @QueryParam("include_permissions") @DefaultValue("true") boolean includePermissions,
@ApiParam(name = "include_sessions") @QueryParam("include_sessions") @DefaultValue("true") boolean includeSessions) {
return listUsersSelective(includePermissions, includeSessions);
@ApiParam(name = "include_sessions") @QueryParam("include_sessions") @DefaultValue("true") boolean includeSessions,
@Context SearchUser searchUser) {
final Optional<AllUserSessions> optSessions = includeSessions ? Optional.of(AllUserSessions.create(sessionService)) : Optional.empty();
return searchUser.isPermitted(RestPermissions.USERS_LIST) ?
listUsersSelective(includePermissions, optSessions) :
listForLoggedInUser(searchUser, includePermissions, optSessions);
}

private UserList listUsersSelective(boolean includePermissions, boolean includeSessions) {
private UserList listForLoggedInUser(final SearchUser searchUser, final boolean includePermissions, Optional<AllUserSessions> optSessions) {
return UserList.create(List.of(toUserResponse(searchUser.getUser(), includePermissions, optSessions)));
}

private UserList listUsersSelective(final boolean includePermissions, final Optional<AllUserSessions> optSessions) {
final List<User> users = userManagementService.loadAll();
final Optional<AllUserSessions> optSessions = includeSessions ? Optional.of(AllUserSessions.create(sessionService)) : Optional.empty();

final List<UserSummary> resultUsers = Lists.newArrayListWithCapacity(users.size() + 1);
userManagementService.getRootUser().ifPresent(adminUser ->
Expand Down
1 change: 1 addition & 0 deletions graylog2-server/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<Logger name="org.apache.hadoop" level="warn"/>
<Logger name="org.apache.parquet.hadoop.InternalParquetRecordReader" level="warn"/>
<Logger name="org.apache.avro.Schema" level="error"/>
<Logger name="org.openqa.selenium.devtools.Connection" level="warn"/>
<Root level="info">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="graylog-internal-logs"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.graylog2.shared.SuppressForbidden;
import org.graylog2.shared.bindings.providers.ObjectMapperProvider;
import org.graylog2.shared.messageq.MessageQueueAcknowledger;
import org.graylog2.system.shutdown.GracefulShutdownService;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
Expand Down Expand Up @@ -75,6 +76,8 @@ class BatchedMessageFilterOutputTest {
private IndexSet indexSet;
@Mock(extraInterfaces = MessageOutput.class)
private FilteredMessageOutput targetOutput1;
@Mock
private GracefulShutdownService gracefulShutdownService;

private static final int MESSAGES_PER_BATCH = 3;

Expand Down Expand Up @@ -129,6 +132,7 @@ void setUp() {
cluster,
acknowledger,
buffer,
gracefulShutdownService,
outputFlushInterval,
shutdownTimeoutMs,
Executors.newSingleThreadScheduledExecutor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"dependencies": {
"@babel/eslint-parser": "7.16.5",
"@tanstack/eslint-plugin-query": "4.36.1",
"@typescript-eslint/eslint-plugin": "7.16.1",
"@typescript-eslint/parser": "7.16.1",
"@typescript-eslint/eslint-plugin": "8.7.0",
"@typescript-eslint/parser": "8.7.0",
"eslint": "8.57.0",
"eslint-config-airbnb": "19.0.4",
"eslint-import-resolver-webpack": "0.13.9",
Expand All @@ -27,7 +27,7 @@
"eslint-plugin-jest-dom": "5.4.0",
"eslint-plugin-jest-formatting": "3.1.0",
"eslint-plugin-jsx-a11y": "6.10.0",
"eslint-plugin-react": "7.36.1",
"eslint-plugin-react": "7.37.0",
"eslint-plugin-react-hooks": "4.6.2",
"eslint-plugin-testing-library": "6.3.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@tanstack/react-query": "4.36.1",
"@types/create-react-class": "15.6.8",
"@types/jquery": "3.5.31",
"@types/react": "18.3.8",
"@types/react": "18.3.10",
"babel-preset-graylog": "file:../babel-preset-graylog",
"create-react-class": "15.7.0",
"eslint-config-graylog": "file:../eslint-config-graylog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import commonStyles from '../common/commonStyles.css';
type EventDefinitionConfig = {
group_by: Array<string>,
streams: Array<string>,
stream_categories?: Array<string>,
};

type EventDefinition = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type EventReplayInfo = {
timerange_end: string,
query: string,
streams: string[],
stream_categories?: string[],
};

export type Event = {
Expand Down
2 changes: 0 additions & 2 deletions graylog2-web-interface/src/components/search/MessageShow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class MessageShow extends React.Component {
this.setState(getImmutableProps(nextProps));
}

// eslint-disable-next-line class-methods-use-this

renderForDisplay = (fieldName) => {
// No highlighting for the message details view.
const { message } = this.props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const defaultOptions = {
queries: {
refetchOnWindowFocus: false,
networkMode: 'always' as const,
retry: (failureCount, error) => {
if (error.status >= 400 && error.status < 500) return false;

return failureCount < 4;
},
},
},
};
Expand Down
7 changes: 1 addition & 6 deletions graylog2-web-interface/src/util/DocsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ const docsHelper = {
PIPELINES: 'pipelines',
REPORTING: 'reporting',
ROLLING_ES_UPGRADE: 'rolling-es-upgrade',
SEARCH_QUERY_ERRORS: {
UNKNOWN_FIELD: 'query-language#unknown-field',
QUERY_PARSING_ERROR: 'query-language#parse-exception',
INVALID_OPERATOR: 'query-language#invalid-operator',
UNDECLARED_PARAMETER: 'query-language#undeclared-parameter',
},
SEARCH_QUERY_ERRORS: 'query-language#ErrorTypes',
SEARCH_QUERY_LANGUAGE: 'query-language',
STREAMS: 'streams',
STREAM_PROCESSING_RUNTIME_LIMITS: 'streams#stream-processing-runtime-limits',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import StreamsField from 'views/components/fieldtypes/StreamsField';
import PercentageField from 'views/components/fieldtypes/PercentageField';
import { getPrettifiedValue } from 'views/components/visualizations/utils/unitConverters';
import type FieldUnit from 'views/logic/aggregationbuilder/FieldUnit';
import { DECIMAL_PLACES, UNIT_FEATURE_FLAG } from 'views/components/visualizations/Constants';
import { UNIT_FEATURE_FLAG } from 'views/components/visualizations/Constants';
import useFeature from 'hooks/useFeature';
import { MISSING_BUCKET_NAME } from 'views/Constants';
import formatValueWithUnitLabel from 'views/components/visualizations/utils/formatValueWithUnitLabel';

import EmptyValue from './EmptyValue';
import CustomPropTypes from './CustomPropTypes';
Expand Down Expand Up @@ -60,7 +61,7 @@ type TypeSpecificValueProps = {
const ValueWithUnitRenderer = ({ value, unit }: { value: number, unit: FieldUnit}) => {
const prettified = getPrettifiedValue(value, { abbrev: unit.abbrev, unitType: unit.unitType });

return <span title={value.toString()}>{`${Number(prettified?.value).toFixed(DECIMAL_PLACES)} ${prettified.unit.abbrev}`}</span>;
return <span title={value.toString()}>{formatValueWithUnitLabel(prettified?.value, prettified.unit.abbrev)}</span>;
};

const FormattedValue = ({ field, value, truncate, render, unit, type }: TypeSpecificValueProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { Unit } from 'views/components/visualizations/utils/unitConverters'
import { mappedUnitsFromJSON as units } from 'views/components/visualizations/utils/unitConverters';
import type { FieldUnitsFormValues } from 'views/types';
import type FieldUnit from 'views/logic/aggregationbuilder/FieldUnit';
import getUnitTextLabel from 'views/components/visualizations/utils/getUnitTextLabel';

const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -76,7 +77,7 @@ const FieldUnitPopover = ({ field, predefinedUnit }: { field: string, predefined
const badgeLabel = useMemo(() => {
const curUnit = values?.units?.[field]?.abbrev;

return curUnit || '...';
return getUnitTextLabel(curUnit) || '...';
}, [field, values?.units]);

const predefinedInfo = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ type Props = {
const MessagePreview = ({ onRowClick, colSpanFixup, message, messageFieldType, showMessageRow, config }: Props) => {
const MessageRowOverride = usePluginEntities('views.components.widgets.messageTable.messageRowOverride')?.[0];

return (
return showMessageRow && (
<TableRow onClick={onRowClick}>
<td colSpan={colSpanFixup}>
{showMessageRow && !!MessageRowOverride && (
{!!MessageRowOverride && (
<MessageRowOverride messageFields={message.fields}
config={config}
renderMessageRow={() => renderMessageFieldRow(message, messageFieldType)} />
)}
{(showMessageRow && !MessageRowOverride) && renderMessageFieldRow(message, messageFieldType)}
{(!MessageRowOverride) && renderMessageFieldRow(message, messageFieldType)}
</td>
</TableRow>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('QueryValidation', () => {
await openExplanation();

await screen.findByText('Parse Exception');
await screen.findByTitle('Parse Exception documentation');
await screen.findByTitle('Query error documentation');
});

it('renders pluggable validation explanation', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,6 @@ const useTriggerIfErrorsPersist = (trigger: () => void) => {
return [showExplanation, toggleShow] as const;
};

const getErrorDocumentationLink = (errorType: string) => {
switch (errorType) {
case 'UNKNOWN_FIELD':
return DocsHelper.PAGES.SEARCH_QUERY_ERRORS.UNKNOWN_FIELD;
case 'QUERY_PARSING_ERROR':
return DocsHelper.PAGES.SEARCH_QUERY_ERRORS.QUERY_PARSING_ERROR;
case 'INVALID_OPERATOR':
return DocsHelper.PAGES.SEARCH_QUERY_ERRORS.INVALID_OPERATOR;
case 'UNDECLARED_PARAMETER':
return DocsHelper.PAGES.SEARCH_QUERY_ERRORS.UNDECLARED_PARAMETER;
default:
return DocsHelper.PAGES.SEARCH_QUERY_LANGUAGE;
}
};

type QueryForm = {
queryString: QueryValidationState,
};
Expand Down Expand Up @@ -230,9 +215,9 @@ const QueryValidation = () => {
<Explanation key={id}>
<span><b>{errorTitle}</b>: {errorMessage}</span>
{errorType && (
<DocumentationLink page={getErrorDocumentationLink(errorType)}
title={`${errorTitle} documentation`}
text={<DocumentationIcon name="lightbulb_circle" />} />
<DocumentationLink page={DocsHelper.PAGES.SEARCH_QUERY_ERRORS}
title="Query error documentation"
text={<DocumentationIcon name="lightbulb_circle" />} />
)}
</Explanation>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ const VariableContainer = styled.div<{ $height: number, $width: number }>(({ $he
width: ${$width}px;
grid-template-columns: ${$width}px;
grid-template-rows: ${$height}px auto;
grid-column-gap: 0;
grid-row-gap: 0;
grid-gap: 0;
justify-content: center;
`);

Expand Down
Loading

0 comments on commit eee2e67

Please sign in to comment.