Skip to content

Commit 219da28

Browse files
Valery Petrovclaude
andcommitted
fix: accept protocol names in the NetFlow protocol filter
Charts, records and the Sankey show protocols by name, but the Protocol filter only matched the raw number, so typing "TCP" returned no flows. Known names now map to their protocol number before filtering. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3b86faf commit 219da28

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎packages/app/src/__tests__/netflow.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ describe('NetFlow queries', () => {
164164
expect(where).toContain("toString(Proto) = '6'");
165165
});
166166

167+
it.each([
168+
['tcp', '6'],
169+
[' ICMPv6 ', '58'],
170+
['99', '99'],
171+
['SCTP', 'SCTP'],
172+
])('filters protocol %p as %p', (protocol, expected) => {
173+
expect(buildNetflowWhere(source, { protocol })).toBe(
174+
`(toString(Proto) = '${expected}')`,
175+
);
176+
});
177+
167178
it('keeps the source, connection, time range and filters on every query', () => {
168179
const configs = buildNetflowQueryConfigs({
169180
source,

‎packages/app/src/netflow.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FIXED_TIME_BUCKET_EXPR_ALIAS } from '@hyperdx/common-utils/dist/core/renderChartConfig';
22
import {
33
getSourceImplicitColumnExpression,
4+
NETFLOW_PROTOCOL_NAMES,
45
netflowProtocolNameExpression,
56
} from '@hyperdx/common-utils/dist/core/searchChartConfig';
67
import {
@@ -85,14 +86,20 @@ export function getNetflowDimensions(source: TNetflowSource) {
8586
};
8687
}
8788

89+
// The protocol filter also accepts the names the charts show, e.g. TCP.
90+
const protocolNumber = (value?: string) =>
91+
Object.entries(NETFLOW_PROTOCOL_NAMES).find(
92+
([, name]) => name.toLowerCase() === value?.trim().toLowerCase(),
93+
)?.[0] ?? value;
94+
8895
export function buildNetflowWhere(
8996
source: TNetflowSource,
9097
filters: NetflowFilters,
9198
) {
9299
const predicates: string[] = [];
93100
for (const [value, expression, address] of [
94101
[filters.exporter, source.exporterExpression, false],
95-
[filters.protocol, source.protocolExpression, false],
102+
[protocolNumber(filters.protocol), source.protocolExpression, false],
96103
[filters.srcAddr, source.srcAddrExpression, true],
97104
[filters.dstAddr, source.dstAddrExpression, true],
98105
] as const) {

‎packages/common-utils/src/core/searchChartConfig.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
*/
3131
export type SearchChartConfig = BuilderChartConfig & Partial<DateRange>;
3232

33-
const NETFLOW_PROTOCOL_NAMES = {
33+
export const NETFLOW_PROTOCOL_NAMES = {
3434
1: 'ICMP',
3535
6: 'TCP',
3636
17: 'UDP',

0 commit comments

Comments
 (0)