Skip to content

Commit

Permalink
feat: Enable adding customized logging fields in sensor (#2325)
Browse files Browse the repository at this point in the history
Signed-off-by: emmayylu <44856279+emmayylu@users.noreply.github.com>
  • Loading branch information
emmayylu authored Dec 1, 2022
1 parent 76b14c2 commit 4464e57
Show file tree
Hide file tree
Showing 10 changed files with 541 additions and 274 deletions.
7 changes: 7 additions & 0 deletions api/jsonschema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3845,6 +3845,13 @@
"description": "EventBusName references to a EventBus name. By default the value is \"default\"",
"type": "string"
},
"loggingFields": {
"additionalProperties": {
"type": "string"
},
"description": "LoggingFields add additional key-value pairs when logging happens",
"type": "object"
},
"replicas": {
"description": "Replicas is the sensor deployment replicas",
"format": "int32",
Expand Down
7 changes: 7 additions & 0 deletions api/openapi-spec/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions api/sensor.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions api/sensor.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

721 changes: 447 additions & 274 deletions pkg/apis/sensor/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pkg/apis/sensor/v1alpha1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pkg/apis/sensor/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/apis/sensor/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ type SensorSpec struct {
// RevisionHistoryLimit specifies how many old deployment revisions to retain
// +optional
RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty" protobuf:"varint,7,opt,name=revisionHistoryLimit"`
// LoggingFields add additional key-value pairs when logging happens
// +optional
LoggingFields map[string]string `json:"loggingFields" protobuf:"bytes,8,rep,name=loggingFields"`
}

func (s SensorSpec) GetReplicas() int32 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/sensor/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions sensors/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func Start() {
dynamicClient := dynamic.NewForConfigOrDie(restConfig)

logger = logger.With("sensorName", sensor.Name)
for name, value := range sensor.Spec.LoggingFields {
logger.With(name, value)
}

ctx := logging.WithLogger(signals.SetupSignalHandler(), logger)
m := metrics.NewMetrics(sensor.Namespace)
go m.Run(ctx, fmt.Sprintf(":%d", common.SensorMetricsPort))
Expand Down

0 comments on commit 4464e57

Please sign in to comment.