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