Skip to content

Commit c133bd0

Browse files
authored
Add the support of custom logging configuration for cockroach version greater than v21.1 (#827)
* Add the support of custom logging configuration for cockroach version greater than v21.1 * Add the support of custom logging configuration through the provided configmap * Add the logging.yaml key in log configmap * Add the change entry in CHANGELOG.md
1 parent 53e8d1f commit c133bd0

29 files changed

+212
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
# [Unreleased](https://github.com/cockroachdb/cockroach-operator/compare/v2.5.3...master)
99

10+
## Added
11+
12+
* Custom logging configuration can be used through the configmap when `spec.logConfigMap` is provided.
13+
1014
# [v2.5.3](https://github.com/cockroachdb/cockroach-operator/compare/v2.5.2...v2.5.3)
1115

1216
## Fixed

apis/v1alpha1/cluster_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ type CrdbClusterSpec struct {
130130
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Cockroach Database Ingress"
131131
// +optional
132132
Ingress *IngressConfig `json:"ingress,omitempty"`
133+
// (Optional) LogConfigMap define the config map which contains log configuration used to send the logs through the
134+
// proper channels in the cockroachdb. Logging configuration is available for cockroach version v21.1.0 onwards.
135+
// The logging configuration is taken in format of yaml file, you can check the logging configuration here (https://www.cockroachlabs.com/docs/stable/configure-logs.html#default-logging-configuration)
136+
// The default logging for cockroach version v20.x or less is stderr, logging API is ignored for older versions.
137+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Cockroach Database Logging configuration config map"
138+
// +optional
139+
LogConfigMap string `json:"logConfigMap,omitempty"`
133140
}
134141

135142
// +k8s:openapi-gen=true

apis/v1alpha1/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,4 @@ func (r *CrdbCluster) ValidateVolumeMode() error {
180180
"you have provided unsupported pvc.volumeMode, currently only Filesystem is supported.")
181181
}
182182
return nil
183-
}
183+
}

apis/v1alpha1/webhook_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ func TestCreateCrdbCluster(t *testing.T) {
102102
Image: &PodImage{Name: "testImage"},
103103
DataStore: Volume{
104104
VolumeClaim: &VolumeClaim{
105-
PersistentVolumeClaimSpec: v1.PersistentVolumeClaimSpec{
106-
},
105+
PersistentVolumeClaimSpec: v1.PersistentVolumeClaimSpec{},
107106
},
108107
},
109108
}},

config/crd/bases/crdb.cockroachlabs.com_crdbclusters.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,15 @@ spec:
973973
- host
974974
type: object
975975
type: object
976+
logConfigMap:
977+
description: (Optional) LogConfigMap define the config map which contains
978+
log configuration used to send the logs through the proper channels
979+
in the cockroachdb. Logging configuration is available for cockroach
980+
version v21.1.0 onwards. The logging configuration is taken in format
981+
of yaml file, you can check the logging configuration here (https://www.cockroachlabs.com/docs/stable/configure-logs.html#default-logging-configuration)
982+
The default logging for cockroach version v20.x or less is stderr,
983+
logging API is ignored for older versions.
984+
type: string
976985
maxSQLMemory:
977986
description: '(Optional) The maximum in-memory storage capacity available
978987
to store temporary data for SQL queries (`--max-sql-memory` parameter)

config/rbac/role.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ rules:
128128
- configmaps
129129
verbs:
130130
- get
131+
- list
132+
- watch
131133
- apiGroups:
132134
- ""
133135
resources:

e2e/create/create_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package e2e
1818

1919
import (
20+
"encoding/json"
2021
"os"
2122
"testing"
2223

@@ -54,8 +55,14 @@ func TestCreateInsecureCluster(t *testing.T) {
5455
sb := testenv.NewDiffingSandbox(t, env)
5556
sb.StartManager(t, controller.InitClusterReconcilerWithLogger(testLog))
5657

58+
// Create cluster with different logging config than the default one.
59+
logJson := []byte(`{"sinks": {"file-groups": {"dev": {"channels": "DEV", "filter": "WARNING"}}}}`)
60+
logConfig := make(map[string]interface{})
61+
require.NoError(t, json.Unmarshal(logJson, &logConfig))
62+
testutil.RequireLoggingConfigMap(t, sb, "logging-configmap", string(logJson))
63+
5764
builder := testutil.NewBuilder("crdb").WithNodeCount(3).
58-
WithImage(e2e.MajorVersion).
65+
WithImage(e2e.MajorVersion).WithClusterLogging("logging-configmap").
5966
WithPVDataStore("1Gi", "standard" /* default storage class in KIND */)
6067

6168
steps := testutil.Steps{

e2e/versionchecker/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go_test(
55
size = "enormous",
66
srcs = ["versionchecker_test.go"],
77
deps = [
8+
"//apis/v1alpha1:go_default_library",
89
"//e2e:go_default_library",
910
"//pkg/controller:go_default_library",
1011
"//pkg/testutil:go_default_library",
@@ -13,6 +14,7 @@ go_test(
1314
"@com_github_stretchr_testify//require:go_default_library",
1415
"@io_k8s_api//core/v1:go_default_library",
1516
"@io_k8s_apimachinery//pkg/api/resource:go_default_library",
17+
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
1618
"@org_uber_go_zap//zaptest:go_default_library",
1719
],
1820
)

e2e/versionchecker/versionchecker_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ limitations under the License.
1717
package versionchecker_test
1818

1919
import (
20+
"encoding/json"
2021
"testing"
2122
"time"
2223

2324
corev1 "k8s.io/api/core/v1"
2425
apiresource "k8s.io/apimachinery/pkg/api/resource"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2527

28+
crdbv1alpha1 "github.com/cockroachdb/cockroach-operator/apis/v1alpha1"
2629
"github.com/cockroachdb/cockroach-operator/e2e"
2730
"github.com/cockroachdb/cockroach-operator/pkg/controller"
2831
"github.com/cockroachdb/cockroach-operator/pkg/testutil"
@@ -70,3 +73,47 @@ func TestVersionCheckerJobPodPending(t *testing.T) {
7073
}
7174
steps.Run(t)
7275
}
76+
77+
func TestLoggingAPIValidCheck(t *testing.T) {
78+
if testing.Short() {
79+
t.Skip("skipping test in short mode.")
80+
}
81+
testLog := zapr.NewLogger(zaptest.NewLogger(t))
82+
83+
e := testenv.CreateActiveEnvForTest()
84+
env := e.Start()
85+
defer e.Stop()
86+
87+
sb := testenv.NewDiffingSandbox(t, env)
88+
sb.StartManager(t, controller.InitClusterReconcilerWithLogger(testLog))
89+
90+
logJson := []byte(`{"sinkss": "invalidvalue"}`)
91+
logConfig := make(map[string]interface{})
92+
require.NoError(t, json.Unmarshal(logJson, &logConfig))
93+
testutil.RequireLoggingConfigMap(t, sb, "logging-configmap", string(logJson))
94+
95+
builder := testutil.NewBuilder("crdb").Namespaced(sb.Namespace).WithNodeCount(3).WithTLS().
96+
WithImage("cockroachdb/cockroach:v21.1.0").
97+
WithPVDataStore("32Mi", "standard" /* default storage class in KIND */).
98+
WithClusterLogging("logging-configmap")
99+
100+
steps := testutil.Steps{
101+
{
102+
Name: "validate the logging API input",
103+
Test: func(t *testing.T) {
104+
require.NoError(t, sb.Create(builder.Cr()))
105+
crdbCluster := &crdbv1alpha1.CrdbCluster{
106+
ObjectMeta: metav1.ObjectMeta{
107+
Name: builder.Cr().Name,
108+
Namespace: builder.Cr().Namespace,
109+
},
110+
}
111+
// Added sleep to reconcile the CR.
112+
time.Sleep(2 * time.Second)
113+
require.NoError(t, sb.Get(crdbCluster))
114+
require.Equal(t, crdbCluster.Status.ClusterStatus, "Failed")
115+
},
116+
},
117+
}
118+
steps.Run(t)
119+
}

hack/bin/deps.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,13 @@ filegroup(
442442
def install_crdb():
443443
http_archive(
444444
name = "crdb_darwin", # todo fix or remove
445-
sha256 = "bbe3a03c661555e8b083856c56c8a3b459f83064d1d552ed3467cbfb66e76db7",
446-
urls = ["https://binaries.cockroachdb.com/cockroach-v20.2.5.darwin-10.9-amd64.tgz"],
445+
sha256 = "bbbd0a75f81d3df4acd139fdc7f0961480161454db24f25263c9276c3959db54",
446+
urls = ["https://binaries.cockroachdb.com/cockroach-v21.2.0.darwin-10.9-amd64.tgz"],
447447
build_file_content = """
448448
filegroup(
449449
name = "file",
450450
srcs = [
451-
"cockroach-v20.2.5.darwin-10.9-amd64/cockroach",
451+
"cockroach-v21.2.0.darwin-10.9-amd64/cockroach",
452452
],
453453
visibility = ["//visibility:public"],
454454
)
@@ -457,13 +457,13 @@ filegroup(
457457

458458
http_archive(
459459
name = "crdb_linux",
460-
sha256 = "57f4b00c736d8511328d6f33997a3a66cb4ec7142cb126d872dade399a0922e6",
461-
urls = ["https://binaries.cockroachdb.com/cockroach-v20.2.5.linux-amd64.tgz"],
460+
sha256 = "c9fda447b9db98ade4444f5855ceb6ffe94549a20bd7cad8fdf70c398add8c02",
461+
urls = ["https://binaries.cockroachdb.com/cockroach-v21.2.0.linux-amd64.tgz"],
462462
build_file_content = """
463463
filegroup(
464464
name = "file",
465465
srcs = [
466-
"cockroach-v20.2.5.linux-amd64/cockroach",
466+
"cockroach-v21.2.0.linux-amd64/cockroach",
467467
],
468468
visibility = ["//visibility:public"],
469469
)

0 commit comments

Comments
 (0)