-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
kafka.go
63 lines (57 loc) · 1.63 KB
/
kafka.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Hubble
package seven
import (
"fmt"
flowpb "github.com/cilium/cilium/api/v1/flow"
"github.com/cilium/cilium/pkg/hubble/defaults"
"github.com/cilium/cilium/pkg/hubble/parser/options"
"github.com/cilium/cilium/pkg/proxy/accesslog"
)
func decodeKafka(flowType accesslog.FlowType, kafka *accesslog.LogRecordKafka, opts *options.Options) *flowpb.Layer7_Kafka {
// Conditionally exclude the API key from the flow.
var apiKey string
if opts.HubbleRedactSettings.RedactKafkaAPIKey {
apiKey = defaults.SensitiveValueRedacted
} else {
apiKey = kafka.APIKey
}
if flowType == accesslog.TypeRequest {
// Set only fields that are relevant for requests.
return &flowpb.Layer7_Kafka{
Kafka: &flowpb.Kafka{
ApiVersion: int32(kafka.APIVersion),
ApiKey: apiKey,
CorrelationId: kafka.CorrelationID,
Topic: kafka.Topic.Topic,
},
}
}
return &flowpb.Layer7_Kafka{
Kafka: &flowpb.Kafka{
ErrorCode: int32(kafka.ErrorCode),
ApiVersion: int32(kafka.APIVersion),
ApiKey: apiKey,
CorrelationId: kafka.CorrelationID,
Topic: kafka.Topic.Topic,
},
}
}
func kafkaSummary(flow *flowpb.Flow) string {
kafka := flow.GetL7().GetKafka()
if kafka == nil {
return ""
}
if flow.GetL7().Type == flowpb.L7FlowType_REQUEST {
return fmt.Sprintf("Kafka request %s correlation id %d topic '%s'",
kafka.ApiKey,
kafka.CorrelationId,
kafka.Topic)
}
// response
return fmt.Sprintf("Kafka response %s correlation id %d topic '%s' return code %d",
kafka.ApiKey,
kafka.CorrelationId,
kafka.Topic,
kafka.ErrorCode)
}