Skip to content

Commit 4be3dd2

Browse files
committed
Solved naming comments and added empty field check while setting resource labels
1 parent 603a32d commit 4be3dd2

File tree

6 files changed

+149
-176
lines changed

6 files changed

+149
-176
lines changed

extension/encoding/googlecloudlogentryencodingextension/README.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Examples:
130130

131131
- Audit Logs: `encoding.format: "gcp.auditlog"`
132132
- VPC Flow Logs: `encoding.format: "gcp.vpcflow"`
133-
- Application Load Balancer Logs: `encoding.format: "gcp.load_balancing"`
133+
- Application Load Balancer Logs: `encoding.format: "gcp.load-balacer"`
134134
- Proxy Network Load Balancer Logs: `encoding.format: "gcp.proxy-nlb"`
135135
- Cloud DNS Logs: `encoding.format: "gcp.dns"`
136136

@@ -146,7 +146,7 @@ For example, `projects/my-project/logs/cloudaudit.googleapis.com%2Fsystem_event`
146146
2. **Map log type to format**: The extension maps specific log types to their corresponding encoding formats (`encoding.format`):
147147
- Audit logs (activity, data access, system event, policy): `gcp.auditlog`
148148
- VPC flow logs (network management-sourced and compute-sourced VPC flow logs): `gcp.vpcflow`
149-
- Application Load Balancer logs (Global External and Regional External): `gcp.load_balancing`
149+
- Application Load Balancer logs (Global External and Regional External): `gcp.load-balancer`
150150
- Cloud Armor logs (embedded within load balancer logs): `gcp.armorlog`
151151
- Proxy Network Load Balancer logs: `gcp.proxy-nlb`
152152
- Cloud DNS logs: `gcp.dns`
@@ -163,7 +163,7 @@ The following format values are supported in the `googlecloudlogentryencodingext
163163
|------------------|------------------|-----------------|
164164
| Audit Logs | `auditlog` | Google Cloud audit logs (activity, data access, system event, policy) |
165165
| VPC Flow Logs | `vpcflow` | Virtual Private Cloud flow log records |
166-
| Application Load Balancer Logs | `load_balancing` | Global and Regional External Application Load Balancer logs |
166+
| Application Load Balancer Logs | `load-balancer` | Global and Regional External Application Load Balancer logs |
167167
| Armor Logs | `armorlog` | Google Cloud armor logs (security policies applied) |
168168
| Proxy Network Load Balancer Logs | `proxy-nlb` | Proxy Network Load Balancer connection logs |
169169
| Cloud DNS Logs | `dns` | Cloud DNS query and response logs |
@@ -448,30 +448,29 @@ Application Load Balancer logs (both [Global External](https://docs.cloud.google
448448

449449
| Original field | Log record attribute |
450450
|---|---|
451-
| `queryName` | `gcp.dns.query.name` |
452-
| `queryType` | `gcp.dns.query.type` |
453-
| `responseCode` | `gcp.dns.response.code` |
451+
| `queryName` | `dns.question.name` |
452+
| `queryType` | `dns.question.type` |
453+
| `responseCode` | `dns.response_code` |
454454
| `alias_query_response_code` | `gcp.dns.alias_query.response.code` |
455455
| `authAnswer` | `gcp.dns.auth_answer` |
456-
| `rdata` | `gcp.dns.rdata` |
457-
| `destinationIP` | `gcp.dns.destination_ip` |
458-
| `sourceNetwork` | `gcp.dns.source.network` |
459-
| `source_type` | `gcp.dns.source.type` |
456+
| `rdata` | `dns.answer.data` |
457+
| `destinationIP` | `server.address` |
458+
| `sourceNetwork` | `gcp.dns.client.vpc.name` |
459+
| `source_type` | `gcp.dns.client.type` |
460460
| `sourceIP` | `client.address` |
461461
| `protocol` | `network.transport` |
462462
| `location` | `cloud.region` |
463-
| `target_name` | `gcp.dns.target.name` |
464-
| `target_type` | `gcp.dns.target.type` |
463+
| `target_name` | `gcp.dns.server.name` |
464+
| `target_type` | `gcp.dns.server.type` |
465465
| `serverLatency` | `gcp.dns.server_latency` |
466466
| `egressError` | `gcp.dns.egress_error` |
467467
| `healthyIps` | `gcp.dns.healthy_ips` |
468468
| `unhealthyIps` | `gcp.dns.unhealthy_ips` |
469469
| `dns64Translated` | `gcp.dns.dns64_translated` |
470-
| `vmInstanceId` | `gcp.dns.vm.instance.id` |
471-
| `vmInstanceIdString` | `gcp.dns.vm.instance.id_string` |
472-
| `vmInstanceName` | `gcp.dns.vm.instance.name` |
470+
| `vmInstanceId` | `host.id` |
471+
| `vmInstanceName` | `host.name` |
473472
| `vmProjectId` | `gcp.dns.vm.project_id` |
474-
| `vmZoneName` | `gcp.dns.vm.zone` |
473+
| `vmZoneName` | `cloud.availability_zone` |
475474

476475
**Protocol translation**: The numeric protocol field from GCP is automatically translated to human-readable protocol names using the [IANA Protocol Numbers](https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml) standard. Common values include:
477476

extension/encoding/googlecloudlogentryencodingextension/internal/dnslog/parser.go

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
package dnslog // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/googlecloudlogentryencodingextension/internal/dnslog"
77

88
import (
9+
"errors"
910
"fmt"
11+
"strings"
1012

1113
gojson "github.com/goccy/go-json"
1214
"go.opentelemetry.io/collector/pdata/pcommon"
13-
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
15+
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
1416

1517
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/googlecloudlogentryencodingextension/internal/shared"
1618
)
@@ -19,34 +21,30 @@ const (
1921
CloudDNSQueryLogSuffix = "dns.googleapis.com%2Fdns_queries"
2022

2123
// Query related attributes. Ref: https://datatracker.ietf.org/doc/html/rfc1035#section-4.1.2
22-
// gcpDNSQueryName holds the DNS query name
23-
gcpDNSQueryName = "gcp.dns.query.name"
2424
// gcpDNSQueryType holds the DNS query type
25-
gcpDNSQueryType = "gcp.dns.query.type"
25+
gcpDNSQueryType = "dns.question.type" // TBD in SemConv
2626

2727
// Response related attributes
2828
// gcpDNSResponseCode holds the DNS response code
29-
gcpDNSResponseCode = "gcp.dns.response.code"
29+
gcpDNSResponseCode = "dns.response_code" // TBD in SemConv
3030
// gcpDNSAliasQueryResponseCode holds the response code for alias queries
3131
gcpDNSAliasQueryResponseCode = "gcp.dns.alias_query.response.code"
3232
// gcpDNSAuthAnswer indicates whether the response is authoritative
3333
gcpDNSAuthAnswer = "gcp.dns.auth_answer" // Ref: https://datatracker.ietf.org/doc/html/rfc1035
34-
// gcpDNSRdata holds DNS answer in presentation format
35-
gcpDNSRdata = "gcp.dns.rdata"
34+
// gcpDNSAnswerData holds DNS answer in presentation format
35+
gcpDNSAnswerData = "dns.answer.data" // TBD in SemConv
3636

3737
// Network related attributes
38-
// gcpDNSDestinationIP holds target IP address
39-
gcpDNSDestinationIP = "gcp.dns.destination_ip"
40-
// gcpDNSSourceNetwork holds the source network name
41-
gcpDNSSourceNetwork = "gcp.dns.source.network"
42-
// gcpDNSSourceType holds the source type of the DNS query
43-
gcpDNSSourceType = "gcp.dns.source.type"
44-
45-
// Target related attributes
46-
// gcpDNSTargetName holds the target name
47-
gcpDNSTargetName = "gcp.dns.target.name"
48-
// gcpDNSTargetType holds the type of target resolving the DNS query
49-
gcpDNSTargetType = "gcp.dns.target.type"
38+
// gcpDNSClientVPCNetwork holds the client network name where the DNS query originated
39+
gcpDNSClientVPCNetwork = "gcp.dns.client.vpc.name"
40+
// gcpDNSClientType holds the client type of the DNS query
41+
gcpDNSClientType = "gcp.dns.client.type"
42+
43+
// Server related attributes
44+
// gcpDNSServerName holds the name name of Google Cloud instance that is responsible of resolving the query
45+
gcpDNSServerName = "gcp.dns.server.name"
46+
// gcpDNServerType holds the type of target resolving the DNS query
47+
gcpDNServerType = "gcp.dns.server.type"
5048

5149
// Performance and error related attributes
5250
// gcpDNSServerLatency holds the server-side latency in seconds
@@ -63,16 +61,8 @@ const (
6361
gcpDNSDNS64Translated = "gcp.dns.dns64_translated"
6462

6563
// VM instance related attributes
66-
// gcpDNSVMInstanceID holds the Compute Engine VM instance ID as an integer
67-
gcpDNSVMInstanceID = "gcp.dns.vm.instance.id"
68-
// gcpDNSVMInstanceIDString holds the Compute Engine VM instance ID as a string
69-
gcpDNSVMInstanceIDString = "gcp.dns.vm.instance.id_string"
70-
// gcpDNSVMInstanceName holds the VM instance name
71-
gcpDNSVMInstanceName = "gcp.dns.vm.instance.name"
7264
// gcpDNSVMProjectID holds the Google Cloud project ID of the network from which the query was sent
7365
gcpDNSVMProjectID = "gcp.dns.vm.project_id"
74-
// gcpDNSVMZoneName holds the name of the VM zone from which the query was sent
75-
gcpDNSVMZoneName = "gcp.dns.vm.zone"
7666
)
7767

7868
type dnslog struct {
@@ -97,36 +87,35 @@ type dnslog struct {
9787
TargetType string `json:"target_type"`
9888
UnhealthyIps string `json:"unhealthyIps"`
9989
VMInstanceID *int64 `json:"vmInstanceId"`
100-
VMInstanceIDStr string `json:"vmInstanceIdString"`
10190
VMInstanceName string `json:"vmInstanceName"`
10291
VMProjectID string `json:"vmProjectId"`
10392
VMZoneName string `json:"vmZoneName"`
10493
}
10594

10695
func handleQueryAttributes(log *dnslog, attr pcommon.Map) {
107-
shared.PutStr(gcpDNSQueryName, log.QueryName, attr)
108-
shared.PutStr(gcpDNSQueryType, log.QueryType, attr)
96+
shared.PutStr(string(semconv.DNSQuestionNameKey), log.QueryName, attr)
97+
shared.PutStr(gcpDNSQueryType, log.QueryType, attr) // TBD in SemConv
10998
}
11099

111100
func handleResponseAttributes(log *dnslog, attr pcommon.Map) {
112-
shared.PutStr(gcpDNSResponseCode, log.ResponseCode, attr)
101+
shared.PutStr(gcpDNSResponseCode, log.ResponseCode, attr) // TBD in SemConv
113102
shared.PutStr(gcpDNSAliasQueryResponseCode, log.AliasQueryResponseCode, attr)
114103
shared.PutBool(gcpDNSAuthAnswer, log.AuthAnswer, attr)
115-
shared.PutStr(gcpDNSRdata, log.Rdata, attr)
104+
shared.PutStr(gcpDNSAnswerData, log.Rdata, attr) // TBD in SemConv
116105
}
117106

118107
func handleNetworkAttributes(log *dnslog, attr pcommon.Map) {
119-
shared.PutStr(gcpDNSDestinationIP, log.DestinationIP, attr)
120-
shared.PutStr(gcpDNSSourceNetwork, log.SourceNetwork, attr)
121-
shared.PutStr(gcpDNSSourceType, log.SourceType, attr)
108+
shared.PutStr(string(semconv.ServerAddressKey), log.DestinationIP, attr)
109+
shared.PutStr(gcpDNSClientVPCNetwork, log.SourceNetwork, attr)
110+
shared.PutStr(gcpDNSClientType, log.SourceType, attr)
122111
shared.PutStr(string(semconv.ClientAddressKey), log.SourceIP, attr)
123-
shared.PutStr(string(semconv.NetworkTransportKey), log.Protocol, attr)
112+
shared.PutStr(string(semconv.NetworkTransportKey), strings.ToLower(log.Protocol), attr)
124113
shared.PutStr(string(semconv.CloudRegionKey), log.Location, attr)
125114
}
126115

127116
func handleTargetAttributes(log *dnslog, attr pcommon.Map) {
128-
shared.PutStr(gcpDNSTargetName, log.TargetName, attr)
129-
shared.PutStr(gcpDNSTargetType, log.TargetType, attr)
117+
shared.PutStr(gcpDNSServerName, log.TargetName, attr)
118+
shared.PutStr(gcpDNServerType, log.TargetType, attr)
130119
}
131120

132121
func handlePerformanceAndErrorAttributes(log *dnslog, attr pcommon.Map) {
@@ -141,26 +130,29 @@ func handleDNSFeatureAttributes(log *dnslog, attr pcommon.Map) {
141130
}
142131

143132
func handleVMInstanceAttributes(log *dnslog, attr pcommon.Map) {
144-
shared.PutInt(gcpDNSVMInstanceID, log.VMInstanceID, attr)
145-
shared.PutStr(gcpDNSVMInstanceIDString, log.VMInstanceIDStr, attr)
146-
shared.PutStr(gcpDNSVMInstanceName, log.VMInstanceName, attr)
133+
shared.PutInt(string(semconv.HostIDKey), log.VMInstanceID, attr)
134+
shared.PutStr(string(semconv.HostNameKey), log.VMInstanceName, attr)
147135
shared.PutStr(gcpDNSVMProjectID, log.VMProjectID, attr)
148-
shared.PutStr(gcpDNSVMZoneName, log.VMZoneName, attr)
136+
shared.PutStr(string(semconv.CloudAvailabilityZoneKey), log.VMZoneName, attr)
149137
}
150138

151139
func ParsePayloadIntoAttributes(payload []byte, attr pcommon.Map) error {
152-
var log dnslog
140+
var log *dnslog
153141
if err := gojson.Unmarshal(payload, &log); err != nil {
154142
return fmt.Errorf("failed to unmarshal DNS log: %w", err)
155143
}
156144

157-
handleQueryAttributes(&log, attr)
158-
handleResponseAttributes(&log, attr)
159-
handleNetworkAttributes(&log, attr)
160-
handleTargetAttributes(&log, attr)
161-
handlePerformanceAndErrorAttributes(&log, attr)
162-
handleDNSFeatureAttributes(&log, attr)
163-
handleVMInstanceAttributes(&log, attr)
145+
if log == nil {
146+
return errors.New("DNS cannot be nil after detecting payload as DNS log")
147+
}
148+
149+
handleQueryAttributes(log, attr)
150+
handleResponseAttributes(log, attr)
151+
handleNetworkAttributes(log, attr)
152+
handleTargetAttributes(log, attr)
153+
handlePerformanceAndErrorAttributes(log, attr)
154+
handleDNSFeatureAttributes(log, attr)
155+
handleVMInstanceAttributes(log, attr)
164156

165157
return nil
166158
}

0 commit comments

Comments
 (0)