Skip to content

Commit

Permalink
Merge branch 'main' into SRE-1609-add-max-data-points-options-to-pane…
Browse files Browse the repository at this point in the history
…l-builder
  • Loading branch information
Atrax1 authored Jan 10, 2025
2 parents ef3e9a1 + 149f084 commit f29e050
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 212 deletions.
39 changes: 38 additions & 1 deletion observability-lib/grafana/panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ func newTransform(options *TransformOptions) dashboard.DataTransformerConfig {
}
}

type ToolTipOptions struct {
Mode common.TooltipDisplayMode
Sort common.SortOrder
MaxWidth *float64
MaxHeight *float64
}

func newToolTip(options *ToolTipOptions) *common.VizTooltipOptionsBuilder {
if options.Mode == "" {
options.Mode = common.TooltipDisplayModeSingle
}

if options.Sort == "" {
options.Sort = common.SortOrderNone
}

builder := common.NewVizTooltipOptionsBuilder().
Mode(options.Mode).
Sort(options.Sort)

if options.MaxWidth != nil {
builder.MaxWidth(*options.MaxWidth)
}

if options.MaxHeight != nil {
builder.MaxHeight(*options.MaxHeight)
}

return builder
}

type PanelOptions struct {
Datasource string
Title string
Expand Down Expand Up @@ -235,6 +266,7 @@ type TimeSeriesPanelOptions struct {
FillOpacity float64
ScaleDistribution common.ScaleDistribution
LegendOptions *LegendOptions
ToolTipOptions *ToolTipOptions
ThresholdStyle common.GraphThresholdsStyleMode
}

Expand All @@ -249,6 +281,10 @@ func NewTimeSeriesPanel(options *TimeSeriesPanelOptions) *Panel {
options.LegendOptions = &LegendOptions{}
}

if options.ToolTipOptions == nil {
options.ToolTipOptions = &ToolTipOptions{}
}

newPanel := timeseries.NewPanelBuilder().
Datasource(datasourceRef(options.Datasource)).
Title(options.Title).
Expand All @@ -262,7 +298,8 @@ func NewTimeSeriesPanel(options *TimeSeriesPanelOptions) *Panel {
Legend(newLegend(options.LegendOptions)).
ScaleDistribution(common.NewScaleDistributionConfigBuilder().
Type(options.ScaleDistribution),
)
).
Tooltip(newToolTip(options.ToolTipOptions))

if options.MaxDataPoints != nil {
newPanel.MaxDataPoints(*options.MaxDataPoints)
Expand Down
2 changes: 2 additions & 0 deletions pkg/capabilities/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type RequestMetadata struct {
WorkflowDonConfigVersion uint32
// The step reference ID of the workflow
ReferenceID string
// Use DecodedWorkflowName if the human readable name needs to be exposed, such as for logging purposes.
DecodedWorkflowName string
}

type RegistrationMetadata struct {
Expand Down
328 changes: 170 additions & 158 deletions pkg/capabilities/pb/capabilities.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/capabilities/pb/capabilities.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ message RequestMetadata {
uint32 workflow_don_id = 6;
uint32 workflow_don_config_version = 7;
string reference_id = 8;
string decoded_workflow_name = 9;
}

message CapabilityRequest {
Expand Down
2 changes: 2 additions & 0 deletions pkg/capabilities/pb/capabilities_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func CapabilityRequestToProto(req capabilities.CapabilityRequest) *CapabilityReq
WorkflowDonId: req.Metadata.WorkflowDonID,
WorkflowDonConfigVersion: req.Metadata.WorkflowDonConfigVersion,
ReferenceId: req.Metadata.ReferenceID,
DecodedWorkflowName: req.Metadata.DecodedWorkflowName,
},
Inputs: values.ProtoMap(inputs),
Config: values.ProtoMap(config),
Expand Down Expand Up @@ -101,6 +102,7 @@ func CapabilityRequestFromProto(pr *CapabilityRequest) (capabilities.CapabilityR
WorkflowDonID: md.WorkflowDonId,
WorkflowDonConfigVersion: md.WorkflowDonConfigVersion,
ReferenceID: md.ReferenceId,
DecodedWorkflowName: md.DecodedWorkflowName,
},
Config: config,
Inputs: inputs,
Expand Down
1 change: 1 addition & 0 deletions pkg/capabilities/pb/capabilities_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestMarshalUnmarshalRequest(t *testing.T) {
WorkflowDonID: 1,
WorkflowDonConfigVersion: 1,
ReferenceID: anyReferenceID,
DecodedWorkflowName: "test-workflow-name",
},
Config: &values.Map{Underlying: map[string]values.Value{
testConfigKey: &values.String{Underlying: testConfigValue},
Expand Down
22 changes: 21 additions & 1 deletion pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,33 @@ import (
"go.uber.org/zap/zaptest/observer"
)

// Logger is a minimal subset of smartcontractkit/chainlink/core/logger.Logger implemented by go.uber.org/zap.SugaredLogger
// Logger is a basic logging interface implemented by smartcontractkit/chainlink/core/logger.Logger and go.uber.org/zap.SugaredLogger
//
// Loggers should be injected (and usually Named as well): e.g. lggr.Named("<service name>")
//
// Tests
// - Tests should use a [Test] logger, with [New] being reserved for actual runtime and limited direct testing.
//
// Levels
// - Fatal: Logs and then calls os.Exit(1). Be careful about using this since it does NOT unwind the stack and may exit uncleanly.
// - Panic: Unrecoverable error. Example: invariant violation, programmer error
// - Error: Something bad happened, and it was clearly on the node op side. No need for immediate action though. Example: database write timed out
// - Warn: Something bad happened, not clear who/what is at fault. Node ops should have a rough look at these once in a while to see whether anything stands out. Example: connection to peer was closed unexpectedly. observation timed out.
// - Info: High level information. First level we’d expect node ops to look at. Example: entered new epoch with leader, made an observation with value, etc.
// - Debug: Useful for forensic debugging, but we don't expect nops to look at this. Example: Got a message, dropped a message, ...
//
// Node Operator Docs: https://docs.chain.link/docs/configuration-variables/#log_level
type Logger interface {
// Name returns the fully qualified name of the logger.
Name() string

Debug(args ...interface{})
Info(args ...interface{})
Warn(args ...interface{})
Error(args ...interface{})
Panic(args ...interface{})
// Fatal logs and then calls os.Exit(1)
// Be careful about using this since it does NOT unwind the stack and may exit uncleanly
Fatal(args ...interface{})

Debugf(format string, values ...interface{})
Expand All @@ -36,6 +54,8 @@ type Logger interface {
Panicw(msg string, keysAndValues ...interface{})
Fatalw(msg string, keysAndValues ...interface{})

// Sync flushes any buffered log entries.
// Some insignificant errors are suppressed.
Sync() error
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/logger/sugared.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package logger

// SugaredLogger extends the base Logger interface with syntactic sugar, similar to zap.SugaredLogger.
// SugaredLogger extends the base Logger interface with syntactic sugar, similar to zap.SugaredLogger, include two new levels.
// - Critical: Requires quick action from the node op, obviously these should happen extremely rarely. Example: failed to listen on TCP port
// - Trace: Only included if compiled with the trace tag. For example: go test -tags trace ...
type SugaredLogger interface {
Logger

Expand Down Expand Up @@ -29,8 +31,16 @@ type SugaredLogger interface {
Tracef(format string, vals ...interface{})
Tracew(msg string, keysAndVals ...interface{})

// Named creates a new Logger sub-scoped with name.
// Names are inherited and dot-separated.
// a := l.Named("A") // logger=A
// b := a.Named("A") // logger=A.B
// Names are generally `MixedCaps`, without spaces, like Go names. `Foo.Bar.HTTPBaz`
Named(string) SugaredLogger
// With returns a new Logger with the given arguments.
With(keyvals ...any) SugaredLogger
// Helper returns a new logger with the number of callers skipped by caller annotation increased by skip.
// This allows wrappers and helpers to point higher up the stack (like testing.T.Helper()).
Helper(skip int) SugaredLogger
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/types/llo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (
// ReportFormatRetirement is a special "capstone" report format to indicate
// a retired OCR instance, and handover crucial information to a new one
ReportFormatRetirement ReportFormat = 3
// ReportFormatEVMAbiEncodeUnpacked supports encoding reports with a fixed
// schema followed by an arbitrary ABI-encoded payload
ReportFormatEVMAbiEncodeUnpacked = 4

_ ReportFormat = math.MaxUint32 // reserved
)
Expand Down
8 changes: 5 additions & 3 deletions pkg/workflows/wasm/host/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,11 +728,13 @@ func write(memory, src []byte, ptr, size int32) int64 {
return -1
}

if len(src) != int(size) {
return -1
}

if int32(len(memory)) < ptr+size {
return -1
}
buffer := memory[ptr : ptr+size]
dataLen := int64(len(src))
copy(buffer, src)
return dataLen
return int64(copy(buffer, src))
}
20 changes: 17 additions & 3 deletions pkg/workflows/wasm/host/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,31 @@ func Test_write(t *testing.T) {
giveSrc := []byte("hello, world")
memory := make([]byte, len(giveSrc)-1)
n := write(memory, giveSrc, 0, int32(len(giveSrc)))
assert.Equal(t, n, int64(-1))
assert.Equal(t, int64(-1), n)
})

t.Run("fails to write to invalid access", func(t *testing.T) {
giveSrc := []byte("hello, world")
memory := make([]byte, len(giveSrc))
n := write(memory, giveSrc, 0, -1)
assert.Equal(t, n, int64(-1))
assert.Equal(t, int64(-1), n)

n = write(memory, giveSrc, -1, 1)
assert.Equal(t, n, int64(-1))
assert.Equal(t, int64(-1), n)
})

t.Run("truncated write due to size being smaller than len", func(t *testing.T) {
giveSrc := []byte("hello, world")
memory := make([]byte, 12)
n := write(memory, giveSrc, 0, int32(len(giveSrc)-2))
assert.Equal(t, int64(-1), n)
})

t.Run("unwanted data when size exceeds written data", func(t *testing.T) {
giveSrc := []byte("hello, world")
memory := make([]byte, 20)
n := write(memory, giveSrc, 0, 20)
assert.Equal(t, int64(-1), n)
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/workflows/wasm/host/wasip1.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func pollOneoff(caller *wasmtime.Caller, subscriptionptr int32, eventsptr int32,
// - 8-16: timeout
// - 16-24: precision
// - 24-32: flag
newTimeout := binary.LittleEndian.Uint16(argBuf[8:16])
newTimeout := binary.LittleEndian.Uint64(argBuf[8:16])
flag := binary.LittleEndian.Uint16(argBuf[24:32])

var errno Errno
Expand Down
99 changes: 55 additions & 44 deletions pkg/workflows/wasm/pb/wasm.pb.go

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

1 change: 1 addition & 0 deletions pkg/workflows/wasm/pb/wasm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ message FetchRequestMetadata {
string workflowName = 2;
string workflowOwner = 3;
string workflowExecutionId = 4;
string decodedWorkflowName = 5;
}

message FetchRequest {
Expand Down
Loading

0 comments on commit f29e050

Please sign in to comment.