Skip to content

Commit

Permalink
bazel: bazelfy logging documentation
Browse files Browse the repository at this point in the history
In doing so, I also noticed a couple generated `.go` files that weren't
yet bazelfied, so I took care of them too.

Closes #65812.

Release note: None
  • Loading branch information
rickystewart committed Jul 26, 2021
1 parent 3fd1428 commit 45e72b7
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 7 deletions.
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:exclude pkg/sql/schemachanger/scop/mutation_visitor_generated.go
# gazelle:exclude pkg/sql/schemachanger/scop/validation_visitor_generated.go
# gazelle:exclude pkg/util/log/channel/channel_generated.go
# gazelle:exclude pkg/util/log/eventpb/eventlog_channels_generated.go
# gazelle:exclude pkg/util/log/eventpb/json_encode_generated.go
# gazelle:exclude pkg/util/log/log_channels_generated.go
# gazelle:exclude pkg/util/log/severity/severity_generated.go
# gazelle:exclude pkg/util/timeutil/lowercase_timezones_generated.go
Expand Down
49 changes: 49 additions & 0 deletions docs/generated/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("//pkg/util/log/eventpb:PROTOS.bzl", _EVENTPB_PROTO_LOCATIONS = "EVENTPB_PROTO_LOCATIONS")

genrule(
name = "gen-logging-md",
srcs = [
Expand All @@ -12,3 +14,50 @@ genrule(
"//pkg/util/log/gen",
],
)

genrule(
name = "gen-logsinks-md",
srcs = [
"//pkg/util/log/logconfig:config.go",
],
outs = ["logsinks.md"],
cmd = """
$(location //pkg/util/log/logconfig:gen) < $(location //pkg/util/log/logconfig:config.go) > $(location logsinks.md)
""",
exec_tools = [
"//pkg/util/log/logconfig:gen",
],
)

genrule(
name = "gen-eventlog-md",
srcs = [
"//pkg/util/log/eventpb:cluster_events.proto",
"//pkg/util/log/eventpb:ddl_events.proto",
"//pkg/util/log/eventpb:events.proto",
"//pkg/util/log/eventpb:health_events.proto",
"//pkg/util/log/eventpb:job_events.proto",
"//pkg/util/log/eventpb:misc_sql_events.proto",
"//pkg/util/log/eventpb:privilege_events.proto",
"//pkg/util/log/eventpb:role_events.proto",
"//pkg/util/log/eventpb:session_events.proto",
"//pkg/util/log/eventpb:sql_audit_events.proto",
"//pkg/util/log/eventpb:zone_events.proto",
],
outs = ["eventlog.md"],
cmd = """
$(location //pkg/util/log/eventpb:gen) eventlog.md \
{} \
>$(location eventlog.md)
""".format(_EVENTPB_PROTO_LOCATIONS),
exec_tools = [
"//pkg/util/log/eventpb:gen",
],
)

genrule(
name = "gen-logformats-md",
outs = ["logformats.md"],
cmd = "$(location //pkg/cmd/docgen) logformats $(location logformats.md)",
exec_tools = ["//pkg/cmd/docgen"],
)
88 changes: 84 additions & 4 deletions pkg/util/log/eventpb/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
load("//pkg/util/log/eventpb:PROTOS.bzl", _EVENTPB_PROTO_LOCATIONS = "EVENTPB_PROTO_LOCATIONS")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

exports_files([
"cluster_events.proto",
"ddl_events.proto",
"events.proto",
"health_events.proto",
"job_events.proto",
"misc_sql_events.proto",
"privilege_events.proto",
"role_events.proto",
"session_events.proto",
"sql_audit_events.proto",
"zone_events.proto",
])

go_binary(
name = "gen",
srcs = ["gen.go"],
importpath = "github.com/cockroachdb/cockroach/pkg/util/log/eventpb",
visibility = ["//visibility:public"],
deps = [
"//pkg/cli/exit",
"//pkg/util/log/logpb",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_gostdlib//go/format",
],
)

go_library(
name = "eventpb",
srcs = [
"doc.go",
"eventlog_channels_generated.go",
"events.go",
"json_encode_generated.go",
":gen-eventlog-channels-generated-go", # keep
":gen-json-encode-generated-go", # keep
],
embed = [":eventpb_go_proto"],
importpath = "github.com/cockroachdb/cockroach/pkg/util/log/eventpb",
visibility = ["//visibility:public"],
deps = [
"//pkg/util/jsonbytes",
"//pkg/util/jsonbytes", # keep
"//pkg/util/log/logpb",
"@com_github_cockroachdb_redact//:redact",
],
Expand Down Expand Up @@ -62,3 +90,55 @@ go_proto_library(
visibility = ["//visibility:public"],
deps = ["@com_github_gogo_protobuf//gogoproto"],
)

genrule(
name = "gen-eventlog-channels-generated-go",
srcs = [
"//pkg/util/log/eventpb:cluster_events.proto",
"//pkg/util/log/eventpb:ddl_events.proto",
"//pkg/util/log/eventpb:events.proto",
"//pkg/util/log/eventpb:health_events.proto",
"//pkg/util/log/eventpb:job_events.proto",
"//pkg/util/log/eventpb:misc_sql_events.proto",
"//pkg/util/log/eventpb:privilege_events.proto",
"//pkg/util/log/eventpb:role_events.proto",
"//pkg/util/log/eventpb:session_events.proto",
"//pkg/util/log/eventpb:sql_audit_events.proto",
"//pkg/util/log/eventpb:zone_events.proto",
],
outs = ["eventlog_channels_generated.go"],
cmd = """
$(location //pkg/util/log/eventpb:gen) eventlog_channels_go \
{} \
>$(location eventlog_channels_generated.go)
""".format(_EVENTPB_PROTO_LOCATIONS),
exec_tools = [
"//pkg/util/log/eventpb:gen",
],
)

genrule(
name = "gen-json-encode-generated-go",
srcs = [
"//pkg/util/log/eventpb:cluster_events.proto",
"//pkg/util/log/eventpb:ddl_events.proto",
"//pkg/util/log/eventpb:events.proto",
"//pkg/util/log/eventpb:health_events.proto",
"//pkg/util/log/eventpb:job_events.proto",
"//pkg/util/log/eventpb:misc_sql_events.proto",
"//pkg/util/log/eventpb:privilege_events.proto",
"//pkg/util/log/eventpb:role_events.proto",
"//pkg/util/log/eventpb:session_events.proto",
"//pkg/util/log/eventpb:sql_audit_events.proto",
"//pkg/util/log/eventpb:zone_events.proto",
],
outs = ["json_encode_generated.go"],
cmd = """
$(location //pkg/util/log/eventpb:gen) json_encode_go \
{} \
>$(location json_encode_generated.go)
""".format(_EVENTPB_PROTO_LOCATIONS),
exec_tools = [
"//pkg/util/log/eventpb:gen",
],
)
6 changes: 6 additions & 0 deletions pkg/util/log/eventpb/PROTOS.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# NOTE(ricky): Unfortunately multiple doc rules need this list of protos in a
# very specific order or else builds will fail or produce incorrect results. I
# capture that list here so we only have one thing to update when a new proto is
# added to this directory.

EVENTPB_PROTO_LOCATIONS = """$(location //pkg/util/log/eventpb:events.proto) $(location //pkg/util/log/eventpb:ddl_events.proto) $(location //pkg/util/log/eventpb:misc_sql_events.proto) $(location //pkg/util/log/eventpb:privilege_events.proto) $(location //pkg/util/log/eventpb:role_events.proto) $(location //pkg/util/log/eventpb:zone_events.proto) $(location //pkg/util/log/eventpb:session_events.proto) $(location //pkg/util/log/eventpb:sql_audit_events.proto) $(location //pkg/util/log/eventpb:cluster_events.proto) $(location //pkg/util/log/eventpb:job_events.proto) $(location //pkg/util/log/eventpb:health_events.proto)"""
2 changes: 1 addition & 1 deletion pkg/util/log/eventpb/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

// +build ignore
// +build bazel

package main

Expand Down
15 changes: 14 additions & 1 deletion pkg/util/log/logconfig/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

exports_files(["config.go"])

go_binary(
name = "gen",
srcs = ["gen.go"],
importpath = "github.com/cockroachdb/cockroach/pkg/util/log/logconfig",
visibility = ["//visibility:public"],
deps = [
"//pkg/cli/exit",
"@com_github_cockroachdb_errors//:errors",
],
)

go_library(
name = "logconfig",
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/log/logconfig/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

// +build ignore
// +build bazel

package main

Expand Down

0 comments on commit 45e72b7

Please sign in to comment.