Skip to content

Commit

Permalink
Generalize TCPDrop to include more protocols
Browse files Browse the repository at this point in the history
Signed-off-by: msherif1234 <mmahmoud@redhat.com>
  • Loading branch information
msherif1234 committed Jul 17, 2023
1 parent 2003ce5 commit 950c317
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion config/sample-frontend-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ alertNamespaces:
- netobserv
sampling: 50
features:
- tcpDrop
- pktDrop
- dnsTracking
12 changes: 6 additions & 6 deletions pkg/handler/lokiclientmock/loki_client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ func (o *LokiClientMock) Get(url string) ([]byte, int, error) {
if strings.Contains(url, "query=topk") {
path = "mocks/loki/topology"

if strings.Contains(url, "|unwrap%20TcpDrop") {
if strings.Contains(url, "|unwrap%20PktDrop") {
path += "_dropped"
}

if strings.Contains(url, "by(app)") {
path += "_app.json"
} else if strings.Contains(url, "by(TcpDropLatestState)") {
} else if strings.Contains(url, "by(PktDropLatestState)") {
path += "_state.json"
} else if strings.Contains(url, "by(TcpDropLatestDropCause)") {
} else if strings.Contains(url, "by(PktDropLatestDropCause)") {
path += "_cause.json"
} else if strings.Contains(url, "by(SrcK8S_HostName,DstK8S_HostName)") {
path += "_host.json"
Expand All @@ -44,11 +44,11 @@ func (o *LokiClientMock) Get(url string) ([]byte, int, error) {
}
} else {
path = "mocks/loki/flows"
if strings.Contains(url, "|~`\"Packets\":0[,}]|~`\"TcpDropPackets\":[1-9][0-9]*[,}]") {
if strings.Contains(url, "|~`\"Packets\":0[,}]|~`\"PktDropPackets\":[1-9][0-9]*[,}]") {
path += "_dropped.json"
} else if strings.Contains(url, "|~`\"TcpDropPackets\":[1-9][0-9]*[,}]") {
} else if strings.Contains(url, "|~`\"PktDropPackets\":[1-9][0-9]*[,}]") {
path += "_has_dropped.json"
} else if strings.Contains(url, "|~`\"TcpDropPackets\":0[,}]") {
} else if strings.Contains(url, "|~`\"PktDropPackets\":0[,}]") {
path += "_sent.json"
} else {
path += ".json"
Expand Down
20 changes: 10 additions & 10 deletions pkg/loki/flow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ func NewFlowQueryBuilder(cfg *Config, start, end, limit string, reporter constan
// match 0 packet sent and 1+ packets dropped
lineFilters = append(lineFilters,
numberMatchLineFilter(fields.Packets, true, "0"),
regexMatchLineFilter(fields.TCPDropPackets, true, "[1-9][0-9]*"),
regexMatchLineFilter(fields.PktDropPackets, true, "[1-9][0-9]*"),
)
} else if packetLoss == constants.PacketLossHasDrop {
// match 1+ packets dropped
lineFilters = append(lineFilters,
regexMatchLineFilter(fields.TCPDropPackets, true, "[1-9][0-9]*"),
regexMatchLineFilter(fields.PktDropPackets, true, "[1-9][0-9]*"),
)
} else if packetLoss == constants.PacketLossSent {
// match records that doesn't contains "TCPDropPackets" field
// match records that doesn't contains "PktDropPackets" field
// as FLP will ensure the filtering
lineFilters = append(lineFilters,
notContainsKeyLineFilter(fields.TCPDropPackets),
notContainsKeyLineFilter(fields.PktDropPackets),
)
}

Expand Down Expand Up @@ -251,17 +251,17 @@ func (q *FlowQueryBuilder) appendDeduplicateFilter(sb *strings.Builder) {
sb.WriteString("`")
}

func (q *FlowQueryBuilder) appendTCPDropStateFilter(sb *strings.Builder) {
// !~`TcpDropLatestState":0`
func (q *FlowQueryBuilder) appendPktDropStateFilter(sb *strings.Builder) {
// !~`PktDropLatestState":0`
sb.WriteString("!~`")
sb.WriteString(`TcpDropLatestState":0`)
sb.WriteString(`PktDropLatestState":0`)
sb.WriteString("`")
}

func (q *FlowQueryBuilder) appendTCPDropCauseFilter(sb *strings.Builder) {
// !~`TcpDropLatestDropCause":0`
func (q *FlowQueryBuilder) appendPktDropCauseFilter(sb *strings.Builder) {
// !~`PktDropLatestDropCause":0`
sb.WriteString("!~`")
sb.WriteString(`TcpDropLatestDropCause":0`)
sb.WriteString(`PktDropLatestDropCause":0`)
sb.WriteString("`")
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/loki/topology_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func NewTopologyQuery(cfg *Config, start, end, limit, rateInterval, step, metric
f = "count_over_time"
case "droppedPackets":
f = "rate"
t = "TcpDropPackets"
t = "PktDropPackets"
case "packets":
f = "rate"
t = "Packets"
case "droppedBytes":
f = "rate"
t = "TcpDropBytes"
t = "PktDropBytes"
default:
f = "rate"
t = "Bytes"
Expand Down Expand Up @@ -87,9 +87,9 @@ func getFields(aggregate, groups string) string {
case "app":
fields = []string{"app"}
case "droppedState":
fields = []string{"TcpDropLatestState"}
fields = []string{"PktDropLatestState"}
case "droppedCause":
fields = []string{"TcpDropLatestDropCause"}
fields = []string{"PktDropLatestDropCause"}
case "host":
fields = []string{"SrcK8S_HostName", "DstK8S_HostName"}
case "namespace":
Expand Down Expand Up @@ -150,9 +150,9 @@ func (q *TopologyQueryBuilder) Build() string {
q.appendDeduplicateFilter(sb)
}
if q.topology.skipEmptyDropState {
q.appendTCPDropStateFilter(sb)
q.appendPktDropStateFilter(sb)
} else if q.topology.skipEmptyDropCause {
q.appendTCPDropCauseFilter(sb)
q.appendPktDropCauseFilter(sb)
}
q.appendJSON(sb, true)
if len(q.topology.dataField) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/fields/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const (
SrcHostName = Src + HostName
DstHostName = Dst + HostName
Packets = "Packets"
TCPDropPackets = "TcpDropPackets"
PktDropPackets = "PktDropPackets"
Proto = "Proto"
Bytes = "Bytes"
TCPDropBytes = "TcpDropBytes"
PktDropBytes = "PktDropBytes"
FlowDirection = "FlowDirection"
DNSID = "DnsId"
)
Expand Down
26 changes: 13 additions & 13 deletions web/src/api/ipfix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,27 @@ export interface Fields {
IcmpType?: number;
/** ICMP code */
IcmpCode?: number;
/** TCP state for drops */
TcpDropLatestState?: string;
/** TCP cause for drops */
TcpDropLatestDropCause?: string;
/** TCP flags for drops */
TcpDropLatestFlags?: number;
/** Pkt TCP state for drops */
PktDropLatestState?: string;
/** Pkt cause for drops */
PktDropLatestDropCause?: string;
/** Pkt TCP flags for drops */
PktDropLatestFlags?: number;
/** Number of packets dropped in this flow */
TcpDropPackets?: number;
PktDropPackets?: number;
/** In conversation tracking, A to B packets dropped counter per conversation */
TcpDropPackets_AB?: number;
PktDropPackets_AB?: number;
/** In conversation tracking, B to A packets dropped counter per conversation */
TcpDropPackets_BA?: number;
PktDropPackets_BA?: number;
/** Number of bytes dropped in this flow */
TcpDropBytes?: number;
PktDropBytes?: number;
/** In conversation tracking, A to B bytes dropped counter per conversation */
TcpDropBytes_AB?: number;
PktDropBytes_AB?: number;
/** In conversation tracking, B to A bytes dropped counter per conversation */
TcpDropBytes_BA?: number;
PktDropBytes_BA?: number;
/** DNS record id */
DnsId?: number;
/** TCP flags for DNS record */
/** DNS flags for DNS record */
DnsFlags?: number;
/** Parsed DNS header RCODEs name */
DnsFlagsResponseCode?: string;
Expand Down
4 changes: 2 additions & 2 deletions web/src/api/loki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export interface RawTopologyMetric {
SrcK8S_OwnerType?: string;
SrcK8S_Type?: string;
SrcK8S_HostName?: string;
TcpDropLatestState?: string;
TcpDropLatestDropCause?: string;
PktDropLatestState?: string;
PktDropLatestDropCause?: string;
}

export interface RawTopologyMetrics {
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/__tests-data__/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export const ConfigResultSample = {
},
quickFilters: [],
sampling: 1,
features: ['tcpDrop', 'dnsTracking']
features: ['pktDrop', 'dnsTracking']
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('<QueryOptionsDropdown />', () => {
allowFlow: true,
allowConnection: true,
allowReporterBoth: true,
allowTcpDrops: true,
allowPktDrops: true,
useTopK: false,
limit: 100,
match: 'all',
Expand All @@ -36,7 +36,7 @@ describe('<QueryOptionsPanel />', () => {
allowFlow: true,
allowConnection: true,
allowReporterBoth: true,
allowTcpDrops: true,
allowPktDrops: true,
useTopK: false,
limit: 100,
match: 'all',
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/dropdowns/query-options-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface QueryOptionsDropdownProps {
allowFlow: boolean;
allowConnection: boolean;
allowReporterBoth: boolean;
allowTcpDrops: boolean;
allowPktDrops: boolean;
useTopK: boolean;
limit: number;
setLimit: (limit: number) => void;
Expand All @@ -41,7 +41,7 @@ export const QueryOptionsPanel: React.FC<QueryOptionsDropdownProps> = ({
allowFlow,
allowConnection,
allowReporterBoth,
allowTcpDrops,
allowPktDrops,
useTopK,
limit,
setLimit,
Expand Down Expand Up @@ -251,7 +251,7 @@ export const QueryOptionsPanel: React.FC<QueryOptionsDropdownProps> = ({
</div>
</Tooltip>
{packetLossOptions.map(opt => {
const disabled = !allowTcpDrops && opt.value !== 'all';
const disabled = !allowPktDrops && opt.value !== 'all';
return (
<div key={`packet-loss-${opt.value}`}>
<label className="pf-c-select__menu-item">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('<FiltersToolbar />', () => {
allowFlow: true,
allowConnection: true,
allowReporterBoth: true,
allowTcpDrops: true,
allowPktDrops: true,
useTopK: false,
match: 'all',
packetLoss: 'all',
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/netflow-record/record-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ export const RecordField: React.FC<{
//show both sent / dropped counts
if (Array.isArray(value) && value.length) {
let droppedText = t('dropped');
if (c.id === ColumnsId.bytes && flow.fields.TcpDropLatestDropCause) {
droppedText = t('dropped by {{reason}}', { reason: flow.fields.TcpDropLatestDropCause });
if (c.id === ColumnsId.bytes && flow.fields.PktDropLatestDropCause) {
droppedText = t('dropped by {{reason}}', { reason: flow.fields.PktDropLatestDropCause });
}
return doubleContainer(
simpleTextWithTooltip(
Expand Down
12 changes: 6 additions & 6 deletions web/src/components/netflow-traffic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export const NetflowTraffic: React.FC<{
setLoading(true);
setError(undefined);
const fq = buildFlowQuery();
const droppedType = config.features.includes('tcpDrop')
const droppedType = config.features.includes('pktDrop')
? fq.type === 'bytes'
? 'droppedBytes'
: 'droppedPackets'
Expand Down Expand Up @@ -605,8 +605,8 @@ export const NetflowTraffic: React.FC<{
return config.features.includes('dnsTracking');
}, [config.features]);

const isTCPDrop = React.useCallback(() => {
return config.features.includes('tcpDrop');
const isPktDrop = React.useCallback(() => {
return config.features.includes('pktDrop');
}, [config.features]);

React.useEffect(() => {
Expand Down Expand Up @@ -1081,7 +1081,7 @@ export const NetflowTraffic: React.FC<{
content = (
<NetflowOverview
limit={limit}
panels={panels.filter(panel => panel.isSelected && (isTCPDrop() || !panel.id.includes('dropped')))}
panels={panels.filter(panel => panel.isSelected && (isPktDrop() || !panel.id.includes('dropped')))}
recordType={recordType}
metricType={metricType}
metrics={metrics}
Expand Down Expand Up @@ -1321,7 +1321,7 @@ export const NetflowTraffic: React.FC<{
allowFlow: isFlow(),
allowConnection: isConnectionTracking(),
allowReporterBoth: selectedViewId === 'table',
allowTcpDrops: isTCPDrop(),
allowPktDrops: isPktDrop(),
useTopK: selectedViewId === 'overview'
}}
forcedFilters={forcedFilters}
Expand Down Expand Up @@ -1462,7 +1462,7 @@ export const NetflowTraffic: React.FC<{
isModalOpen={isOverviewModalOpen}
setModalOpen={setOverviewModalOpen}
recordType={recordType}
panels={panels.filter(panel => isTCPDrop() || !panel.id.includes('dropped'))}
panels={panels.filter(panel => isPktDrop() || !panel.id.includes('dropped'))}
setPanels={setSelectedPanels}
/>
<ColumnsModal
Expand Down
2 changes: 1 addition & 1 deletion web/src/model/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RecordType } from './flow-query';
import { RawQuickFilter } from './quick-filters';

export type Feature = 'tcpDrop' | 'dnsTracking';
export type Feature = 'pktDrop' | 'dnsTracking';

export type Config = {
recordTypes: RecordType[];
Expand Down
4 changes: 2 additions & 2 deletions web/src/utils/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ export const getExtraColumns = (t: TFunction): Column[] => {
tooltip: t('The total aggregated number of bytes.'),
fieldName: 'Bytes',
isSelected: true,
value: f => (f.fields.TcpDropBytes ? [f.fields.Bytes, f.fields.TcpDropBytes] : f.fields.Bytes),
value: f => (f.fields.PktDropBytes ? [f.fields.Bytes, f.fields.PktDropBytes] : f.fields.Bytes),
sort: (a, b, col) => compareNumbers(col.value(a) as number, col.value(b) as number),
width: 5
},
Expand All @@ -751,7 +751,7 @@ export const getExtraColumns = (t: TFunction): Column[] => {
tooltip: t('The total aggregated number of packets.'),
fieldName: 'Packets',
isSelected: true,
value: f => (f.fields.TcpDropPackets ? [f.fields.Packets, f.fields.TcpDropPackets] : f.fields.Packets),
value: f => (f.fields.PktDropPackets ? [f.fields.Packets, f.fields.PktDropPackets] : f.fields.Packets),
sort: (a, b, col) => compareNumbers(col.value(a) as number, col.value(b) as number),
width: 5
},
Expand Down
4 changes: 2 additions & 2 deletions web/src/utils/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ const parseMetric = (
const stats = computeStats(normalized);
if (aggregateBy === 'droppedState') {
return {
name: raw.metric.TcpDropLatestState,
name: raw.metric.PktDropLatestState,
values: normalized,
stats: stats,
aggregateBy
} as DroppedTopologyMetrics;
} else if (aggregateBy === 'droppedCause') {
return {
name: raw.metric.TcpDropLatestDropCause,
name: raw.metric.PktDropLatestDropCause,
values: normalized,
stats: stats,
aggregateBy
Expand Down

0 comments on commit 950c317

Please sign in to comment.