diff --git a/README.md b/README.md index 5c86799..9a2ec9a 100644 --- a/README.md +++ b/README.md @@ -104,8 +104,6 @@ request := gush.FlowRequest{Flow: Notify, Input: receipt} err := ctx.RunFlow(request) ``` -`WithCron("0 2 * * *")` runs a flow on a schedule in UTC until it is canceled, terminated or stopped by `WithTimeout`. Start it with `StartFlow`, because `RunFlow` returns an error: a schedule has no result to wait for. A client's `StartFlow` returns an error for an invalid expression. On a child flow, Temporal instead fails the parent's workflow task, which retries until the parent's `WithTimeout`, so check an expression that comes from outside first. - Flows and steps are registered under their bare Go function names, and can be called by that name as a string. Two functions with the same name in different packages collide, and `Serve` reports it. Use `NewFlowHandler` and `NewStepHandler` to choose a name, which closures and the instantiations of a generic function need too. `string` and `[]byte` travel as raw bytes and everything else as JSON, so read a value back as the type it was written. @@ -156,10 +154,9 @@ A step that is already running only finds out about the cancellation through `ct | `WithFairKey(key)` | both | Group to schedule fairly against, such as a tenant. | | `WithLogAttribute(k, v)` | both | Attribute on every log line of this run and its children. | | `WithLogAttributes(m)` | both | The same, for several attributes. | -| `WithID(id)` | flow | Flow ID. Otherwise one is generated, which `StartFlow` returns. A client's `RunFlow` or `StartFlow` joins a flow already running with this ID and ignores this run's input, and a child flow gets an error. `RunFlow` then waits for that flow, even across a `WithCron` schedule. | -| `WithTimeout(d)` | flow | Limit on the whole execution, including every retry and every scheduled run. | -| `WithCron(expr)` | flow | Schedule in UTC. Use with `StartFlow`. | -| `WithConfig(c)` | flow | Starts from a `FlowConfig`, such as one decoded from a queue. Fields left out of the JSON keep their defaults. Whoever applies it chooses `RunFlow` or `StartFlow`, and one with a cron schedule needs `StartFlow`. | +| `WithID(id)` | flow | Flow ID. Otherwise one is generated, which `StartFlow` returns. A client's `RunFlow` or `StartFlow` joins a flow already running with this ID and ignores this run's input, and a child flow gets an error. | +| `WithTimeout(d)` | flow | Limit on the whole execution, including every retry. | +| `WithConfig(c)` | flow | Starts from a `FlowConfig`, such as one decoded from a queue. Fields left out of the JSON keep their defaults. Whoever applies it chooses `RunFlow` or `StartFlow`. | | `WithQueue(q)` | step | Runs on another queue. | | `WithAttemptTimeout(d)` | step | Limit on each attempt, not the step as a whole. | | `WithHeartbeatTimeout(d)` | step | Fails an attempt that stops calling `ctx.Heartbeat()`. | @@ -282,13 +279,14 @@ Lines written while Temporal replays a flow are dropped, so each appears once. H ### Export over OTLP -`gush.Dial` starts exporting when an endpoint is set, and `Close` flushes. A process that logs without a client calls `gush.InitLogExport()` itself. The first variable set here wins: +`gush.Dial` starts exporting when `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` or `OTEL_EXPORTER_OTLP_ENDPOINT` is set, and `Close` flushes. A process that logs without a client calls `gush.InitLogExport()` itself. [OpenTelemetry's other variables](https://opentelemetry.io/docs/specs/otel/protocol/exporter/) set the headers and TLS, and the protocol is `http/protobuf` unless they ask for `grpc`: + +```sh +OTEL_EXPORTER_OTLP_ENDPOINT=https://collector:4317 +OTEL_EXPORTER_OTLP_PROTOCOL=grpc +``` -| Variable | Protocol | -|---|---| -| `OTEL_ENDPOINT` | OTLP/gRPC. A bare `host:port` is plaintext; a URL's scheme chooses, and `https://` means TLS. | -| `OTEL_HTTP_ENDPOINT` | OTLP/HTTP, as an `http://` or `https://` URL. Logs go to `/v1/logs`. | -| `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`, `OTEL_EXPORTER_OTLP_ENDPOINT` | The [standard OpenTelemetry variables](https://opentelemetry.io/docs/specs/otel/protocol/exporter/), with their protocol, header and TLS settings. | +The endpoint must be a URL, or `Dial` returns an error. `https://` is TLS and `http://` is plaintext, and `OTEL_EXPORTER_OTLP_INSECURE` does not change that. Give the port too, because leaving it out does not select OTLP's 4317 or 4318. Over HTTP, `/v1/logs` is added to `OTEL_EXPORTER_OTLP_ENDPOINT`, but `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` is used as written, so it needs the full path, such as `http://collector:4318/v1/logs`. An application with its own logging pipeline keeps control: a provider set with OpenTelemetry's `global.SetLoggerProvider` always wins, and Gush uses it instead of starting an export. Importing Gush never changes that global. With no provider and no endpoint, logs go to standard error, as do the Temporal SDK's own messages unless `Options.Logger` says otherwise. @@ -328,7 +326,7 @@ options := gush.Options{ c, err := gush.Dial(options) ``` -An empty `HostPort` falls back to `TEMPORAL_ENDPOINT`, then `TEMPORAL_ADDRESS`, then `localhost:7233`. An empty `Namespace` falls back to `TEMPORAL_NAMESPACE`, then the default namespace. +An empty `HostPort` falls back to `TEMPORAL_ADDRESS`, then `localhost:7233`. An empty `Namespace` falls back to `TEMPORAL_NAMESPACE`, then the default namespace. The package-level functions, such as `gush.RunFlow` and `gush.Serve`, use a shared client configured from those variables. They suit a process that talks to one server. diff --git a/SECURITY.md b/SECURITY.md index 11962c9..5e0f682 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -21,5 +21,6 @@ vulnerabilities even if you cannot reproduce them on the latest release. stores them in its history. Do not put secrets in them. - Resume tokens let their holder finish a suspended step. Treat them as credentials when handing them to another system. -- `OTEL_ENDPOINT` set to a bare `host:port` sends logs in plaintext. Use an - `https://` URL when logs leave a trusted network. +- With no certificate variable set, an `http://` value in `OTEL_EXPORTER_OTLP_ENDPOINT` + or `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` sends logs in plaintext. Use an `https://` URL + when logs leave a trusted network. diff --git a/client.go b/client.go index 2a994d5..a02709d 100644 --- a/client.go +++ b/client.go @@ -24,12 +24,12 @@ type Client struct { // Dial connects to Temporal and starts OTLP log export when it is configured; see // InitLogExport. // -// An empty HostPort falls back to TEMPORAL_ENDPOINT, then TEMPORAL_ADDRESS, then the -// SDK's default of localhost:7233. An empty Namespace falls back to TEMPORAL_NAMESPACE, -// then the SDK's default namespace. +// An empty HostPort falls back to TEMPORAL_ADDRESS, then the SDK's default of +// localhost:7233. An empty Namespace falls back to TEMPORAL_NAMESPACE, then the SDK's +// default namespace. func Dial(options Options) (*Client, error) { if options.HostPort == "" { - options.HostPort = temporalEndpointFromEnv() + options.HostPort = os.Getenv(envTemporalAddress) } if options.Namespace == "" { options.Namespace = os.Getenv(envTemporalNamespace) diff --git a/config_json_test.go b/config_json_test.go index 770ca92..5945a92 100644 --- a/config_json_test.go +++ b/config_json_test.go @@ -1,7 +1,6 @@ package gush_test import ( - "encoding/json" "testing" "time" @@ -12,7 +11,6 @@ func TestFlowConfigMarshalUsesSnakeCaseJSONTags(t *testing.T) { config := gush.DefaultFlowConfig() config.ID = "flow-123" config.Timeout = 5 * time.Minute - config.Cron = "0 2 * * *" config.Priority = gush.PriorityHigh config.FairKey = "tenant-a" config.InitialInterval = 2 * time.Second @@ -36,14 +34,13 @@ func TestFlowConfigMarshalUsesSnakeCaseJSONTags(t *testing.T) { expectedKeys := []string{ "id", "timeout", - "cron", "priority", - "fairness", + "fair_key", "initial_interval", "backoff_coefficient", - "maximum_interval", - "maximum_attempts", - "non_retryable_error_types", + "max_interval", + "max_attempts", + "no_retry", "log_attributes", } @@ -54,18 +51,6 @@ func TestFlowConfigMarshalUsesSnakeCaseJSONTags(t *testing.T) { } } -// A config can wait in a queue, so it may hold keys its reader no longer has. -func TestFlowConfigIgnoresKeysItDoesNotKnow(t *testing.T) { - var config gush.FlowConfig - err := json.Unmarshal([]byte(`{"id":"flow-1","async":true}`), &config) - if err != nil { - t.Fatalf("Unmarshal returned error: %v", err) - } - if config.ID != "flow-1" { - t.Errorf("ID = %q", config.ID) - } -} - func TestStepConfigMarshalUsesSnakeCaseJSONTags(t *testing.T) { config := gush.DefaultStepConfig() config.Queue = "queue-a" @@ -93,15 +78,17 @@ func TestStepConfigMarshalUsesSnakeCaseJSONTags(t *testing.T) { expectedKeys := []string{ "queue", - "timeout", - "worker_pickup_timeout", + "attempt_timeout", + "pickup_timeout", + "heartbeat_timeout", + "wait_for_cancel", "priority", - "fairness", + "fair_key", "initial_interval", "backoff_coefficient", - "maximum_interval", - "maximum_attempts", - "non_retryable_error_types", + "max_interval", + "max_attempts", + "no_retry", "log_attributes", } diff --git a/env.go b/env.go index e0b381d..8d7f1f2 100644 --- a/env.go +++ b/env.go @@ -3,13 +3,9 @@ package gush import "os" const ( - envTemporalEndpoint = "TEMPORAL_ENDPOINT" envTemporalAddress = "TEMPORAL_ADDRESS" envTemporalNamespace = "TEMPORAL_NAMESPACE" - envLogGRPCEndpoint = "OTEL_ENDPOINT" - envLogHTTPEndpoint = "OTEL_HTTP_ENDPOINT" - envOTLPLogsEndpoint = "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT" envOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT" envOTLPLogsProtocol = "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL" @@ -26,7 +22,3 @@ func firstEnv(names ...string) string { } return "" } - -func temporalEndpointFromEnv() string { - return firstEnv(envTemporalEndpoint, envTemporalAddress) -} diff --git a/flow.go b/flow.go index a470ebe..7a64883 100644 --- a/flow.go +++ b/flow.go @@ -2,16 +2,11 @@ package gush import ( "context" - "errors" "time" "go.temporal.io/sdk/client" ) -// errCronNeedsStartFlow is what RunFlow returns for a schedule, which never gives it a -// result to wait for. -var errCronNeedsStartFlow = errors.New("gush: a cron schedule has no result for RunFlow to wait for; use StartFlow") - // FlowHandlerFunc is the signature of a flow. type FlowHandlerFunc func(ctx *FlowContext) (output any, err error) @@ -64,14 +59,10 @@ type FlowInfo struct { CloseTime *time.Time // nil while running } -// RunFlow starts a flow and waits for its result. It returns an error for a WithCron -// schedule, which never gives a result to wait for, so start one with StartFlow. +// RunFlow starts a flow and waits for its result. func (c *Client) RunFlow(ctx context.Context, request FlowRequest, options ...FlowOption) error { config := DefaultFlowConfig() config.Apply(options...) - if config.Cron != "" { - return errCronNeedsStartFlow - } run, err := c.startFlow(ctx, request, config) if err != nil { diff --git a/flow_config.go b/flow_config.go index 4ed297c..0ca2e92 100644 --- a/flow_config.go +++ b/flow_config.go @@ -11,9 +11,9 @@ import ( // FlowConfig holds the settings of one flow run. Its JSON form is stable, so a config can // be queued and applied later with WithConfig. A field left out of the JSON keeps its -// default, while a zero written out is taken as it is, so "maximum_attempts": 0 still +// default, while a zero written out is taken as it is, so "max_attempts": 0 still // means unlimited. Waiting is not part of a config: whoever applies it chooses RunFlow or -// StartFlow, and one with a Cron needs StartFlow. +// StartFlow. // // Like time.Time, it decodes itself from JSON, so a struct that embeds it would decode // through that method and lose its own fields. Hold it in a named field to decode it. @@ -23,14 +23,8 @@ type FlowConfig struct { // ID is the flow ID. If empty, one is generated. ID string `json:"id"` - // Timeout limits the whole execution, including every retry and every scheduled run. - // Zero means unlimited. + // Timeout limits the whole execution, including every retry. Zero means unlimited. Timeout time.Duration `json:"timeout"` - - // Cron is a schedule in UTC, such as "0 2 * * *" for daily at 2 AM. A run starts only - // after the previous one ends, and the schedule continues until canceled, terminated - // or stopped by Timeout. - Cron string `json:"cron"` } // DefaultFlowConfig returns the settings a flow run starts from: one attempt, medium @@ -111,8 +105,7 @@ func WithConfig(config *FlowConfig) FlowOption { // WithID sets the flow ID. Without it one is generated, which StartFlow returns. While a // flow with this ID is running, a client's RunFlow or StartFlow joins it instead of starting -// another and ignores this run's input, and a child flow gets an error. RunFlow then waits -// for that flow, even across a WithCron schedule. +// another and ignores this run's input, and a child flow gets an error. func WithID(flowID string) FlowOption { apply := func(config *FlowConfig) { config.ID = flowID @@ -120,24 +113,10 @@ func WithID(flowID string) FlowOption { return flowOption(apply) } -// WithTimeout limits the whole flow execution, including every retry and every scheduled -// run of a WithCron schedule, so it also ends the schedule. +// WithTimeout limits the whole flow execution, including every retry. func WithTimeout(timeout time.Duration) FlowOption { apply := func(config *FlowConfig) { config.Timeout = timeout } return flowOption(apply) } - -// WithCron runs the flow on a schedule in UTC, such as "0 2 * * *" for daily at 2 AM. Start -// it with StartFlow, because RunFlow returns an error: a schedule has no result to wait for. -// -// A client's StartFlow returns an error for an invalid expression. On a child flow, Temporal -// instead fails the parent's workflow task, which retries until the parent's WithTimeout, so -// check an expression that comes from outside first. -func WithCron(cron string) FlowOption { - apply := func(config *FlowConfig) { - config.Cron = cron - } - return flowOption(apply) -} diff --git a/flow_config_test.go b/flow_config_test.go index c995bf2..705daaf 100644 --- a/flow_config_test.go +++ b/flow_config_test.go @@ -20,9 +20,6 @@ func TestDefaultFlowConfig(t *testing.T) { if config.ID != "" { t.Errorf("Expected ID to be empty, got %v", config.ID) } - if config.Cron != "" { - t.Errorf("Expected Cron to be empty, got %v", config.Cron) - } // Test LogAttributes initialization if config.LogAttributes == nil { @@ -81,13 +78,6 @@ func TestFlowOptions(t *testing.T) { return c.Priority == gush.PriorityHigh }, }, - { - name: "WithCron", - option: gush.WithCron("0 2 * * *"), - expected: func(c *gush.FlowConfig) bool { - return c.Cron == "0 2 * * *" - }, - }, { name: "WithRetryPolicy", option: gush.WithRetryPolicy(retryPolicy), @@ -119,7 +109,6 @@ func TestMultipleFlowOptions(t *testing.T) { gush.WithID("batch-process-123"), gush.WithTimeout(10 * time.Minute), gush.WithPriority(gush.PriorityLow), - gush.WithCron("0 3 * * *"), gush.WithLogAttribute("user_id", "batch-user"), gush.WithLogAttribute("process_type", "batch"), } @@ -138,9 +127,6 @@ func TestMultipleFlowOptions(t *testing.T) { if config.Priority != gush.PriorityLow { t.Errorf("Expected Priority to be PriorityLow, got %v", config.Priority) } - if config.Cron != "0 3 * * *" { - t.Errorf("Expected Cron to be '0 3 * * *', got %v", config.Cron) - } if config.LogAttributes["user_id"] != "batch-user" { t.Errorf("Expected LogAttributes[user_id] to be 'batch-user', got %v", config.LogAttributes["user_id"]) } @@ -183,7 +169,6 @@ func TestWithConfigAllowsLaterOverrides(t *testing.T) { }, ID: "config-flow-id", Timeout: 15 * time.Minute, - Cron: "0 4 * * *", } options := []gush.FlowOption{ @@ -203,9 +188,6 @@ func TestWithConfigAllowsLaterOverrides(t *testing.T) { if config.Timeout != 20*time.Minute { t.Errorf("Expected Timeout to be overridden, got %v", config.Timeout) } - if config.Cron != "0 4 * * *" { - t.Errorf("Expected Cron to come from custom config, got %v", config.Cron) - } if config.Priority != gush.PriorityHigh { t.Errorf("Expected Priority to come from custom config, got %v", config.Priority) } @@ -250,26 +232,6 @@ func TestFlowConfigRetryPolicyInheritance(t *testing.T) { } } -func TestCronScheduleValidation(t *testing.T) { - validCronSchedules := []string{ - "0 2 * * *", // Daily at 2 AM - "0 */6 * * *", // Every 6 hours - "0 9 * * 1", // Every Monday at 9 AM - "30 14 * * *", // Daily at 2:30 PM - "0 0 1 * *", // First day of every month - } - - for _, cron := range validCronSchedules { - t.Run("ValidCron_"+cron, func(t *testing.T) { - config := gush.DefaultFlowConfig() - config.Apply(gush.WithCron(cron)) - if config.Cron != cron { - t.Errorf("Expected Cron to be %s, got %s", cron, config.Cron) - } - }) - } -} - func decodedConfig(t *testing.T, raw string) *gush.FlowConfig { t.Helper() @@ -297,7 +259,7 @@ func TestPartialJSONConfigKeepsTheDefaults(t *testing.T) { } func TestJSONConfigTakesAWrittenZero(t *testing.T) { - config := decodedConfig(t, `{"maximum_attempts":0}`) + config := decodedConfig(t, `{"max_attempts":0}`) if config.MaxAttempts != 0 { t.Errorf("attempts = %d, want the written 0, which means unlimited", config.MaxAttempts) @@ -358,7 +320,7 @@ func TestWithConfigOverridesWhatItSets(t *testing.T) { inherited := gush.DefaultFlowConfig() inherited.Priority = gush.PriorityHigh - config := decodedConfig(t, `{"priority":"low","fairness":"tenant-2"}`) + config := decodedConfig(t, `{"priority":"low","fair_key":"tenant-2"}`) inherited.Apply(gush.WithConfig(config)) if inherited.Priority != gush.PriorityLow || inherited.FairKey != "tenant-2" { @@ -372,13 +334,13 @@ func TestJSONConfigDecodesOverExistingSettings(t *testing.T) { config.MaxAttempts = 5 config.Priority = gush.PriorityHigh - err := gush.Decode([]byte(`{"cron":"0 2 * * *"}`), config) + err := gush.Decode([]byte(`{"timeout":60000000000}`), config) if err != nil { t.Fatalf("Decode() error = %v", err) } - if config.Cron != "0 2 * * *" { - t.Errorf("cron = %q", config.Cron) + if config.Timeout != time.Minute { + t.Errorf("timeout = %v", config.Timeout) } if config.ID != "kept" || config.MaxAttempts != 5 || config.Priority != gush.PriorityHigh { t.Errorf("existing settings changed: %q, %d, %q", config.ID, config.MaxAttempts, config.Priority) diff --git a/flow_context.go b/flow_context.go index 1101a20..6ad9d0f 100644 --- a/flow_context.go +++ b/flow_context.go @@ -133,13 +133,9 @@ func (flowCtx *FlowContext) RunStep(step any, input, output any, options ...Step } // RunFlow runs a child flow and waits for its result. The child inherits this flow's -// priority, fair key and log attributes unless options override them. A WithCron schedule -// never gives a result to wait for, so RunFlow aborts the flow; start one with StartFlow. +// priority, fair key and log attributes unless options override them. func (flowCtx *FlowContext) RunFlow(request FlowRequest, options ...FlowOption) error { config := flowCtx.childFlowConfig(options) - if config.Cron != "" { - return flowCtx.Abort(errCronNeedsStartFlow) - } childOptions := newChildWorkflowOptions(request.Queue, config) childContext := workflow.WithChildOptions(flowCtx.Context, childOptions) diff --git a/flow_test.go b/flow_test.go index 257d1bf..a05c5bc 100644 --- a/flow_test.go +++ b/flow_test.go @@ -35,31 +35,6 @@ func TestRunFlowSendsNoRetryTypesToTemporal(t *testing.T) { } } -func TestRunFlowRejectsACronSchedule(t *testing.T) { - config := DefaultFlowConfig() - config.Cron = "0 2 * * *" - tests := map[string]FlowOption{ - "WithCron": WithCron("0 2 * * *"), - "WithConfig": WithConfig(config), - } - - for name, option := range tests { - t.Run(name, func(t *testing.T) { - capture := &startCaptureClient{} - flowClient := &Client{temporalClient: capture} - - request := FlowRequest{Queue: "queue", Flow: "handler"} - err := flowClient.RunFlow(context.Background(), request, option) - if !errors.Is(err, errCronNeedsStartFlow) { - t.Fatalf("RunFlow() error = %v", err) - } - if capture.options.TaskQueue != "" { - t.Errorf("RunFlow() started a flow on %q", capture.options.TaskQueue) - } - }) - } -} - func TestStartFlowRejectsAFlowThatCannotRun(t *testing.T) { flowClient := &Client{temporalClient: &startCaptureClient{}} @@ -103,7 +78,7 @@ func TestOptionsAddNoRetryTypesOnFlowsAndSteps(t *testing.T) { } func TestDefaultClientReportsAFailedConnection(t *testing.T) { - t.Setenv(envTemporalEndpoint, "127.0.0.1:1") + t.Setenv(envTemporalAddress, "127.0.0.1:1") _, err := DefaultClient() if err == nil || !strings.Contains(err.Error(), "connect to Temporal") { @@ -120,21 +95,3 @@ func TestDefaultClientReportsAFailedConnection(t *testing.T) { func TestPackageCloseWithoutAConnectionDoesNothing(t *testing.T) { Close() } - -func TestTemporalEndpointFromEnv(t *testing.T) { - t.Setenv(envTemporalEndpoint, "") - t.Setenv(envTemporalAddress, "") - if got := temporalEndpointFromEnv(); got != "" { - t.Errorf("no variables: %q", got) - } - - t.Setenv(envTemporalAddress, "address:7233") - if got := temporalEndpointFromEnv(); got != "address:7233" { - t.Errorf("TEMPORAL_ADDRESS: %q", got) - } - - t.Setenv(envTemporalEndpoint, "endpoint:7233") - if got := temporalEndpointFromEnv(); got != "endpoint:7233" { - t.Errorf("TEMPORAL_ENDPOINT should win: %q", got) - } -} diff --git a/integration_test.go b/integration_test.go index a154635..0431672 100644 --- a/integration_test.go +++ b/integration_test.go @@ -85,8 +85,8 @@ func runWithTemporal(m *testing.M) int { ExpiringApprovalFlow, TimeoutFlow, HeartbeatFlow, SilentFlow, ReplayFlow, AttributesFlow, AttributesChildFlow, WaitingFlow, InheritanceFlow, VersionFlow, SmallFlow, BadStepFlow, ChildOnOwnQueueFlow, WrappedAbortFlow, WrappingFlow, ParallelFlow, CleanupFlow, CountdownFlow, AttributeEchoFlow, CancelOneStepFlow, ChargeThenRefundFlow, - DetachingParentFlow, CronChildFlow, DetailReadingFlow, AttributeRecordingFlow, InheritingDetachingParentFlow, - CanceledDetachingFlow, HoldingEchoFlow, InvalidChildStartFlow, DuplicateChildStartFlow, CronChildStartFlow, + DetachingParentFlow, DetailReadingFlow, AttributeRecordingFlow, InheritingDetachingParentFlow, + CanceledDetachingFlow, HoldingEchoFlow, InvalidChildStartFlow, DuplicateChildStartFlow, IdleFlow, IdleDetachingParentFlow, UnpolledChildStartFlow). WithSteps(DoubleStep, FailingStep, PlainFailureStep, AbortStep, ApprovalStep, SlowStep, HeartbeatStep, SilentStep, PurgeCacheStep, AttributesStep, InheritanceStep, WrappedAbortStep, DecliningStep, CleanupStep, AttributeEchoStep, ChargingStep, RefundStep, DetailedStep). @@ -665,7 +665,7 @@ func TestConfigDecodedFromJSONRuns(t *testing.T) { ctx := testContext(t) flowID := uniqueKey(t) - raw := fmt.Sprintf(`{"id":%q,"priority":"high","fairness":"tenant-json","maximum_attempts":1}`, flowID) + raw := fmt.Sprintf(`{"id":%q,"priority":"high","fair_key":"tenant-json","max_attempts":1}`, flowID) config := &gush.FlowConfig{} require.NoError(t, gush.Decode([]byte(raw), config)) @@ -680,23 +680,6 @@ func TestConfigDecodedFromJSONRuns(t *testing.T) { assert.Equal(t, "tenant-json", flow.FairKey) } -func TestCronFlowRunsUntilStopped(t *testing.T) { - ctx := testContext(t) - flowID := uniqueKey(t) - - _, err := testClient.StartFlow(ctx, flowRequest(SmallFlow, nil, nil), - gush.WithID(flowID), - gush.WithCron("0 0 1 1 *"), - ) - require.NoError(t, err) - - flow, err := testClient.GetFlow(ctx, flowID) - require.NoError(t, err) - assert.Equal(t, "Running", flow.Status) - - require.NoError(t, testClient.TerminateFlow(ctx, flowID, "test finished")) -} - func TestCancelFlow(t *testing.T) { ctx := testContext(t) flowID := uniqueKey(t) @@ -850,8 +833,10 @@ func otlpRecords(t *testing.T) (*httptest.Server, *sync.Map) { // by flow_id and the inherited attributes, which is what distributed log search relies on. func TestLogsFromOneRunReachTheCollectorCorrelated(t *testing.T) { server, records := otlpRecords(t) - t.Setenv("OTEL_ENDPOINT", "") - t.Setenv("OTEL_HTTP_ENDPOINT", server.URL) + t.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", server.URL) + t.Setenv("OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "") + t.Setenv("OTEL_EXPORTER_OTLP_PROTOCOL", "") + t.Setenv("OTEL_EXPORTER_OTLP_LOGS_PROTOCOL", "") clientOptions := gush.Options{HostPort: testHostPort} exporting, err := gush.Dial(clientOptions) @@ -917,7 +902,7 @@ func TestClientsRunInTheirNamespace(t *testing.T) { func TestPackageLevelFunctionsUseTheDefaultClient(t *testing.T) { ctx := testContext(t) - t.Setenv("TEMPORAL_ENDPOINT", testHostPort) + t.Setenv("TEMPORAL_ADDRESS", testHostPort) t.Setenv("TEMPORAL_NAMESPACE", "") defer gush.Close() @@ -1302,61 +1287,6 @@ func TestStartFlowRunsAChildOnItsQueue(t *testing.T) { require.NoError(t, testClient.TerminateFlow(ctx, childID, "test")) } -func TestRunFlowJoiningACronScheduleWaitsForIt(t *testing.T) { - ctx := testContext(t) - flowID := uniqueKey(t) - - _, err := testClient.StartFlow(ctx, flowRequest(SmallFlow, nil, nil), gush.WithID(flowID), gush.WithCron("0 0 1 1 *")) - require.NoError(t, err) - - waiting, cancel := context.WithTimeout(ctx, time.Second) - defer cancel() - err = testClient.RunFlow(waiting, flowRequest(SmallFlow, nil, nil), gush.WithID(flowID)) - assert.Error(t, err) - assert.ErrorIs(t, waiting.Err(), context.DeadlineExceeded) - require.NoError(t, testClient.TerminateFlow(ctx, flowID, "test")) -} - -func CronChildStartFlow(ctx *gush.FlowContext) (any, error) { - var childID string - err := ctx.Decode(&childID) - if err != nil { - return nil, err - } - - request := gush.FlowRequest{Flow: SmallFlow} - return ctx.StartFlow(request, gush.WithID(childID), gush.WithCron("0 0 1 1 *")) -} - -func TestStartFlowRunsACronChild(t *testing.T) { - ctx := testContext(t) - childID := uniqueKey(t) - - var started string - err := testClient.RunFlow(ctx, flowRequest(CronChildStartFlow, childID, &started)) - require.NoError(t, err) - assert.Equal(t, childID, started) - - flow, err := testClient.GetFlow(ctx, childID) - require.NoError(t, err) - assert.Equal(t, "Running", flow.Status) - require.NoError(t, testClient.TerminateFlow(ctx, childID, "test")) -} - -func CronChildFlow(ctx *gush.FlowContext) (any, error) { - request := gush.FlowRequest{Flow: SmallFlow} - return nil, ctx.RunFlow(request, gush.WithCron("0 0 1 1 *")) -} - -func TestRunFlowAbortsOnACronChild(t *testing.T) { - ctx := testContext(t) - - err := testClient.RunFlow(ctx, flowRequest(CronChildFlow, nil, nil)) - require.Error(t, err) - assert.True(t, gush.IsPermanentError(err)) - assert.Contains(t, err.Error(), "StartFlow") -} - func TestParallelStepsRunThroughWithContext(t *testing.T) { var total int diff --git a/log_export.go b/log_export.go index a682f5b..8a5cfa0 100644 --- a/log_export.go +++ b/log_export.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "net/url" "os" "reflect" "strings" @@ -59,17 +60,11 @@ var logExport struct { users int } -// InitLogExport starts exporting logs over OTLP when an endpoint is set in the environment, -// and returns a function that flushes them and stops. Dial calls it, so call it directly -// only for a process that logs without a Client. -// -// The first variable set here wins: -// -// - OTEL_ENDPOINT: OTLP/gRPC. A bare host:port is plaintext, and a URL's scheme chooses: -// https means TLS. -// - OTEL_HTTP_ENDPOINT: OTLP/HTTP, as an http:// or https:// URL. Logs go to /v1/logs. -// - OTEL_EXPORTER_OTLP_LOGS_ENDPOINT or OTEL_EXPORTER_OTLP_ENDPOINT: the standard -// OpenTelemetry variables, including their protocol, header and TLS settings. +// InitLogExport starts exporting logs over OTLP when OTEL_EXPORTER_OTLP_LOGS_ENDPOINT or +// OTEL_EXPORTER_OTLP_ENDPOINT is set, and returns a function that flushes them and stops. +// The endpoint must be an http:// or https:// URL. OpenTelemetry's other standard variables +// set the protocol, headers and TLS, and the default protocol is http/protobuf. Dial calls +// it, so call it directly only for a process that logs without a Client. // // A LoggerProvider the host already set with OpenTelemetry's global.SetLoggerProvider // always wins, and InitLogExport leaves it alone. Importing gush never changes the global @@ -132,52 +127,19 @@ func releaseLogExport() { } } -// newLogExporterFromEnv returns nil when no endpoint is configured. +// newLogExporterFromEnv returns nil when no endpoint is configured. Otherwise the exporter +// reads OpenTelemetry's standard variables itself. It accepts a malformed endpoint, such as +// collector:4318, and then loses every record, so that is an error here. func newLogExporterFromEnv(ctx context.Context) (sdklog.Exporter, error) { - grpcEndpoint := firstEnv(envLogGRPCEndpoint) - if grpcEndpoint != "" { - return newGRPCLogExporter(ctx, grpcEndpoint) - } - - httpEndpoint := firstEnv(envLogHTTPEndpoint) - if httpEndpoint != "" { - return newHTTPLogExporter(ctx, httpEndpoint) - } - - if firstEnv(envOTLPLogsEndpoint, envOTLPEndpoint) != "" { - return newStandardLogExporter(ctx) + endpoint := firstEnv(envOTLPLogsEndpoint, envOTLPEndpoint) + if endpoint == "" { + return nil, nil } - return nil, nil -} - -func newGRPCLogExporter(ctx context.Context, endpoint string) (sdklog.Exporter, error) { - options := []otlploggrpc.Option{otlploggrpc.WithEndpoint(endpoint), otlploggrpc.WithInsecure()} - if strings.Contains(endpoint, "://") { - options = []otlploggrpc.Option{otlploggrpc.WithEndpointURL(endpoint)} + parsed, err := url.Parse(endpoint) + if err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") || parsed.Hostname() == "" { + return nil, fmt.Errorf("gush: OTLP log endpoint %q must be an http:// or https:// URL with a host", endpoint) } - exporter, err := otlploggrpc.New(ctx, options...) - if err != nil { - return nil, fmt.Errorf("gush: create OTLP/gRPC log exporter: %w", err) - } - return exporter, nil -} - -func newHTTPLogExporter(ctx context.Context, endpoint string) (sdklog.Exporter, error) { - if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") { - return nil, fmt.Errorf("gush: OTLP/HTTP log endpoint %q must start with http:// or https://", endpoint) - } - - exporter, err := otlploghttp.New(ctx, otlploghttp.WithEndpointURL(endpoint), otlploghttp.WithURLPath("/v1/logs")) - if err != nil { - return nil, fmt.Errorf("gush: create OTLP/HTTP log exporter: %w", err) - } - return exporter, nil -} - -// newStandardLogExporter lets the exporter read OpenTelemetry's own variables. Their -// default protocol is http/protobuf. -func newStandardLogExporter(ctx context.Context) (sdklog.Exporter, error) { if firstEnv(envOTLPLogsProtocol, envOTLPProtocol) == "grpc" { exporter, err := otlploggrpc.New(ctx) if err != nil { @@ -186,7 +148,15 @@ func newStandardLogExporter(ctx context.Context) (sdklog.Exporter, error) { return exporter, nil } - exporter, err := otlploghttp.New(ctx) + // The exporter appends /v1/logs to the general variable as written, so a trailing slash + // would post to //v1/logs. The logs variable is used as written, slash included. + var options []otlploghttp.Option + if os.Getenv(envOTLPLogsEndpoint) == "" && strings.HasSuffix(parsed.Path, "/") { + logsPath := strings.TrimRight(parsed.Path, "/") + "/v1/logs" + options = append(options, otlploghttp.WithURLPath(logsPath)) + } + + exporter, err := otlploghttp.New(ctx, options...) if err != nil { return nil, fmt.Errorf("gush: create OTLP/HTTP log exporter: %w", err) } diff --git a/log_export_test.go b/log_export_test.go index 2be3f10..61d9a9e 100644 --- a/log_export_test.go +++ b/log_export_test.go @@ -2,11 +2,15 @@ package gush import ( "context" + "crypto/x509" + "encoding/pem" "fmt" "io" "net" "net/http" "net/http/httptest" + "os" + "path/filepath" "sync" "testing" "time" @@ -17,16 +21,14 @@ import ( sdklog "go.opentelemetry.io/otel/sdk/log" logcollector "go.opentelemetry.io/proto/otlp/collector/logs/v1" "google.golang.org/grpc" + "google.golang.org/grpc/credentials" "google.golang.org/protobuf/proto" ) // clearLogEnv isolates a test from endpoints set in the environment running it. func clearLogEnv(t *testing.T) { t.Helper() - names := []string{ - envLogGRPCEndpoint, envLogHTTPEndpoint, - envOTLPLogsEndpoint, envOTLPEndpoint, envOTLPLogsProtocol, envOTLPProtocol, - } + names := []string{envOTLPLogsEndpoint, envOTLPEndpoint, envOTLPLogsProtocol, envOTLPProtocol} for _, name := range names { t.Setenv(name, "") } @@ -72,6 +74,15 @@ func (collected *collectedLogs) attributesOf(body string) (map[string]string, bo func startHTTPCollector(t *testing.T) (*httptest.Server, *collectedLogs, *[]string) { t.Helper() + server, collected, paths := newHTTPCollector(t) + server.Start() + return server, collected, paths +} + +// newHTTPCollector returns a fake OTLP/HTTP collector for the caller to start. +func newHTTPCollector(t *testing.T) (*httptest.Server, *collectedLogs, *[]string) { + t.Helper() + collected := newCollectedLogs() paths := &[]string{} var pathsMu sync.Mutex @@ -97,7 +108,7 @@ func startHTTPCollector(t *testing.T) (*httptest.Server, *collectedLogs, *[]stri writer.WriteHeader(http.StatusOK) } - server := httptest.NewServer(http.HandlerFunc(handler)) + server := httptest.NewUnstartedServer(http.HandlerFunc(handler)) t.Cleanup(server.Close) return server, collected, paths } @@ -114,14 +125,14 @@ func (collector *grpcCollector) Export(_ context.Context, request *logcollector. } // startGRPCCollector runs a fake OTLP/gRPC collector and returns its host:port. -func startGRPCCollector(t *testing.T) (string, *collectedLogs) { +func startGRPCCollector(t *testing.T, options ...grpc.ServerOption) (string, *collectedLogs) { t.Helper() listener, err := net.Listen("tcp", "127.0.0.1:0") require.NoError(t, err) collected := newCollectedLogs() - server := grpc.NewServer() + server := grpc.NewServer(options...) collector := &grpcCollector{collected: collected} logcollector.RegisterLogsServiceServer(server, collector) @@ -138,6 +149,17 @@ func startGRPCCollector(t *testing.T) (string, *collectedLogs) { return listener.Addr().String(), collected } +// trustCertificate makes the exporter trust a test collector's certificate. +func trustCertificate(t *testing.T, certificate *x509.Certificate) { + t.Helper() + + block := &pem.Block{Type: "CERTIFICATE", Bytes: certificate.Raw} + path := filepath.Join(t.TempDir(), "collector.pem") + err := os.WriteFile(path, pem.EncodeToMemory(block), 0o600) + require.NoError(t, err) + t.Setenv("OTEL_EXPORTER_OTLP_CERTIFICATE", path) +} + // exportOneRecord logs through a running export and flushes it to the collector. func exportOneRecord(t *testing.T, body string) { t.Helper() @@ -190,7 +212,7 @@ func TestTimeEndUsesTheLoggersClock(t *testing.T) { func TestExportsOverHTTP(t *testing.T) { clearLogEnv(t) server, collected, paths := startHTTPCollector(t) - t.Setenv(envLogHTTPEndpoint, server.URL) + t.Setenv(envOTLPEndpoint, server.URL) exportOneRecord(t, "over http") @@ -198,99 +220,151 @@ func TestExportsOverHTTP(t *testing.T) { assert.Contains(t, *paths, "/v1/logs") } -func TestExportsOverGRPCToABareHostPort(t *testing.T) { +func TestExportsOverGRPC(t *testing.T) { clearLogEnv(t) endpoint, collected := startGRPCCollector(t) - t.Setenv(envLogGRPCEndpoint, endpoint) + t.Setenv(envOTLPLogsEndpoint, "http://"+endpoint) + t.Setenv(envOTLPLogsProtocol, "grpc") exportOneRecord(t, "over grpc") assertCollected(t, collected, "over grpc") } -func TestExportsOverGRPCToAURL(t *testing.T) { +func TestExportsOverHTTPS(t *testing.T) { clearLogEnv(t) - endpoint, collected := startGRPCCollector(t) - t.Setenv(envLogGRPCEndpoint, "http://"+endpoint) + server, collected, _ := newHTTPCollector(t) + server.StartTLS() + t.Setenv(envOTLPEndpoint, server.URL) + trustCertificate(t, server.Certificate()) - exportOneRecord(t, "over grpc url") + exportOneRecord(t, "over https") - assertCollected(t, collected, "over grpc url") + assertCollected(t, collected, "over https") } -func TestExportsThroughStandardVariables(t *testing.T) { +// This is the configuration the README shows. +func TestExportsOverGRPCWithTLS(t *testing.T) { clearLogEnv(t) - server, collected, paths := startHTTPCollector(t) - t.Setenv(envOTLPEndpoint, server.URL) + certificates := httptest.NewTLSServer(http.NotFoundHandler()) + defer certificates.Close() + serverTLS := credentials.NewServerTLSFromCert(&certificates.TLS.Certificates[0]) + endpoint, collected := startGRPCCollector(t, grpc.Creds(serverTLS)) + t.Setenv(envOTLPEndpoint, "https://"+endpoint) + t.Setenv(envOTLPProtocol, "grpc") + trustCertificate(t, certificates.Certificate()) - exportOneRecord(t, "over standard http") + exportOneRecord(t, "over grpc with tls") - assertCollected(t, collected, "over standard http") - assert.Contains(t, *paths, "/v1/logs") + assertCollected(t, collected, "over grpc with tls") } -func TestExportsThroughStandardVariablesOverGRPC(t *testing.T) { +func TestExportsWithAnUppercaseScheme(t *testing.T) { clearLogEnv(t) - endpoint, collected := startGRPCCollector(t) - t.Setenv(envOTLPLogsEndpoint, "http://"+endpoint) - t.Setenv(envOTLPLogsProtocol, "grpc") + server, collected, _ := startHTTPCollector(t) + t.Setenv(envOTLPEndpoint, "HTTP://"+server.Listener.Addr().String()) - exportOneRecord(t, "over standard grpc") + exportOneRecord(t, "uppercase scheme") - assertCollected(t, collected, "over standard grpc") + assertCollected(t, collected, "uppercase scheme") } -func TestGRPCEndpointWinsOverHTTP(t *testing.T) { - clearLogEnv(t) - endpoint, grpcCollected := startGRPCCollector(t) - server, httpCollected, _ := startHTTPCollector(t) - t.Setenv(envLogGRPCEndpoint, endpoint) - t.Setenv(envLogHTTPEndpoint, server.URL) +func TestGeneralEndpointGetsTheLogsPath(t *testing.T) { + tests := map[string]struct { + suffix string + path string + }{ + "no path": {suffix: "", path: "/v1/logs"}, + "only a slash": {suffix: "/", path: "/v1/logs"}, + "a path": {suffix: "/base", path: "/base/v1/logs"}, + "a path ending in slash": {suffix: "/base/", path: "/base/v1/logs"}, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + clearLogEnv(t) + server, collected, paths := startHTTPCollector(t) + t.Setenv(envOTLPEndpoint, server.URL+test.suffix) - exportOneRecord(t, "precedence") + exportOneRecord(t, "general endpoint") - assertCollected(t, grpcCollected, "precedence") - _, reachedHTTP := httpCollected.attributesOf("precedence") - assert.False(t, reachedHTTP) + assertCollected(t, collected, "general endpoint") + assert.Equal(t, []string{test.path}, *paths) + }) + } } -func TestHTTPEndpointWinsOverTheStandardVariables(t *testing.T) { +func TestLogsEndpointWinsAndIsUsedAsWritten(t *testing.T) { clearLogEnv(t) - own, ownCollected, _ := startHTTPCollector(t) - standard, standardCollected, _ := startHTTPCollector(t) - t.Setenv(envLogHTTPEndpoint, own.URL) - t.Setenv(envOTLPEndpoint, standard.URL) + general, generalCollected, _ := startHTTPCollector(t) + logs, logsCollected, paths := startHTTPCollector(t) + t.Setenv(envOTLPEndpoint, general.URL) + t.Setenv(envOTLPLogsEndpoint, logs.URL+"/ingest/") - exportOneRecord(t, "http over standard") + exportOneRecord(t, "logs endpoint") - assertCollected(t, ownCollected, "http over standard") - _, reachedStandard := standardCollected.attributesOf("http over standard") - assert.False(t, reachedStandard) + assertCollected(t, logsCollected, "logs endpoint") + assert.Equal(t, []string{"/ingest/"}, *paths) + _, reachedGeneral := generalCollected.attributesOf("logs endpoint") + assert.False(t, reachedGeneral) } -func TestGRPCEndpointWinsOverTheStandardVariables(t *testing.T) { +// The exporter never reads the general variable here, so its value does not matter. +func TestOnlyTheEndpointInUseIsChecked(t *testing.T) { clearLogEnv(t) - own, ownCollected := startGRPCCollector(t) - standard, standardCollected, _ := startHTTPCollector(t) - t.Setenv(envLogGRPCEndpoint, own) - t.Setenv(envOTLPEndpoint, standard.URL) + server, collected, _ := startHTTPCollector(t) + t.Setenv(envOTLPEndpoint, "collector:4318") + t.Setenv(envOTLPLogsEndpoint, server.URL+"/v1/logs") - exportOneRecord(t, "grpc over standard") + exportOneRecord(t, "endpoint in use") - assertCollected(t, ownCollected, "grpc over standard") - _, reachedStandard := standardCollected.attributesOf("grpc over standard") - assert.False(t, reachedStandard) + assertCollected(t, collected, "endpoint in use") } -func TestRejectsAnHTTPEndpointThatIsNotAURL(t *testing.T) { +func TestLogsProtocolWinsOverTheGeneralOne(t *testing.T) { clearLogEnv(t) - t.Setenv(envLogHTTPEndpoint, "collector:4318") + server, collected, _ := startHTTPCollector(t) + t.Setenv(envOTLPEndpoint, server.URL) + t.Setenv(envOTLPProtocol, "grpc") + t.Setenv(envOTLPLogsProtocol, "http/protobuf") + + exportOneRecord(t, "logs protocol") + + assertCollected(t, collected, "logs protocol") +} + +func TestRejectsAnEndpointThatIsNotAURL(t *testing.T) { + tests := map[string]struct { + variable string + protocol string + endpoint string + }{ + "no scheme": {variable: envOTLPEndpoint, endpoint: "collector:4318"}, + "an address": {variable: envOTLPEndpoint, endpoint: "127.0.0.1:4318"}, + "no scheme over grpc": {variable: envOTLPEndpoint, protocol: "grpc", endpoint: "collector:4317"}, + "no scheme, logs variable": {variable: envOTLPLogsEndpoint, endpoint: "collector:4318"}, + "another scheme": {variable: envOTLPEndpoint, endpoint: "ftp://collector:4318"}, + "no host": {variable: envOTLPEndpoint, endpoint: "http://"}, + "no host over https": {variable: envOTLPEndpoint, endpoint: "https://"}, + "only a port": {variable: envOTLPEndpoint, endpoint: "http://:4318"}, + "a bad port": {variable: envOTLPEndpoint, endpoint: "http://collector:43x8"}, + "a space in the host": {variable: envOTLPEndpoint, endpoint: "http://coll ector:4317"}, + "a trailing newline": {variable: envOTLPEndpoint, endpoint: "http://collector:4318\n"}, + } - _, err := InitLogExport() + for name, test := range tests { + t.Run(name, func(t *testing.T) { + clearLogEnv(t) + t.Setenv(test.variable, test.endpoint) + t.Setenv(envOTLPProtocol, test.protocol) - require.Error(t, err) - assert.Contains(t, err.Error(), "must start with http") - assert.Same(t, unconfiguredLogProvider, global.GetLoggerProvider()) + _, err := InitLogExport() + + require.Error(t, err) + assert.Contains(t, err.Error(), "must be an http:// or https:// URL") + assert.Same(t, unconfiguredLogProvider, global.GetLoggerProvider()) + }) + } } func TestNoEndpointLeavesGlobalProviderAlone(t *testing.T) { @@ -306,7 +380,7 @@ func TestNoEndpointLeavesGlobalProviderAlone(t *testing.T) { func TestExportSetsTheGlobalProviderUntilItStops(t *testing.T) { clearLogEnv(t) server, _, _ := startHTTPCollector(t) - t.Setenv(envLogHTTPEndpoint, server.URL) + t.Setenv(envOTLPEndpoint, server.URL) shutdown, err := InitLogExport() require.NoError(t, err) @@ -319,7 +393,7 @@ func TestExportSetsTheGlobalProviderUntilItStops(t *testing.T) { func TestExportIsSharedUntilTheLastUserStops(t *testing.T) { clearLogEnv(t) server, collected, _ := startHTTPCollector(t) - t.Setenv(envLogHTTPEndpoint, server.URL) + t.Setenv(envOTLPEndpoint, server.URL) first, err := InitLogExport() require.NoError(t, err) @@ -340,7 +414,7 @@ func TestExportIsSharedUntilTheLastUserStops(t *testing.T) { func TestHostProviderWinsOverEndpoints(t *testing.T) { clearLogEnv(t) server, collected, _ := startHTTPCollector(t) - t.Setenv(envLogHTTPEndpoint, server.URL) + t.Setenv(envOTLPEndpoint, server.URL) hostLogs := captureHostLogs(t) host := global.GetLoggerProvider() @@ -359,7 +433,7 @@ func TestHostProviderWinsOverEndpoints(t *testing.T) { func TestHostProviderSetAfterExportStartedTakesOver(t *testing.T) { clearLogEnv(t) server, _, _ := startHTTPCollector(t) - t.Setenv(envLogHTTPEndpoint, server.URL) + t.Setenv(envOTLPEndpoint, server.URL) // Runs last, because captureHostLogs restores the export's stopped provider. t.Cleanup(func() { global.SetLoggerProvider(unconfiguredLogProvider) }) diff --git a/options.go b/options.go index 135997d..293869a 100644 --- a/options.go +++ b/options.go @@ -14,7 +14,7 @@ type CommonConfig struct { // FairKey groups work for fair scheduling across tenants or user groups. Keys are // cut to the 64 bytes Temporal accepts, so keys that agree up to there share a group. - FairKey string `json:"fairness"` + FairKey string `json:"fair_key"` // LogAttributes are attached to every log record and inherited by child flows and steps. LogAttributes map[string]any `json:"log_attributes"` diff --git a/retry.go b/retry.go index c040e9b..104be5e 100644 --- a/retry.go +++ b/retry.go @@ -16,14 +16,14 @@ type RetryPolicy struct { BackoffCoefficient float64 `json:"backoff_coefficient"` // MaxInterval caps the delay between retries. Zero means 100 times InitialInterval. - MaxInterval time.Duration `json:"maximum_interval"` + MaxInterval time.Duration `json:"max_interval"` // MaxAttempts is the total number of attempts, including the first. Zero means // unlimited. - MaxAttempts int32 `json:"maximum_attempts"` + MaxAttempts int32 `json:"max_attempts"` // NoRetry lists the ApplicationError types that fail immediately. - NoRetry []string `json:"non_retryable_error_types"` + NoRetry []string `json:"no_retry"` } // totalBackoff returns the time spent waiting between attempts if all MaxAttempts are used, diff --git a/step_config.go b/step_config.go index b274fd2..1f6252a 100644 --- a/step_config.go +++ b/step_config.go @@ -11,14 +11,14 @@ type StepConfig struct { // AttemptTimeout limits each attempt, not the step as a whole. It also bounds how long // a suspended step waits for Resume. - AttemptTimeout time.Duration `json:"timeout"` + AttemptTimeout time.Duration `json:"attempt_timeout"` // HeartbeatTimeout fails an attempt that goes this long without calling Heartbeat. // Zero disables it. HeartbeatTimeout time.Duration `json:"heartbeat_timeout"` // PickupTimeout fails the step if no worker picks it up in time. Zero means unlimited. - PickupTimeout time.Duration `json:"worker_pickup_timeout"` + PickupTimeout time.Duration `json:"pickup_timeout"` // WaitForCancel makes RunStep wait for a canceled step to end. See WithWaitForCancel. WaitForCancel bool `json:"wait_for_cancel"` diff --git a/temporal_options.go b/temporal_options.go index db9183a..ed45276 100644 --- a/temporal_options.go +++ b/temporal_options.go @@ -31,7 +31,6 @@ func newStartWorkflowOptions(queue string, config *FlowConfig) client.StartWorkf ID: config.ID, TaskQueue: queue, RetryPolicy: config.temporalPolicy(), - CronSchedule: config.Cron, Priority: newTemporalPriority(&config.CommonConfig), WorkflowExecutionTimeout: config.Timeout, } @@ -43,7 +42,6 @@ func newChildWorkflowOptions(queue string, config *FlowConfig) workflow.ChildWor WorkflowID: config.ID, TaskQueue: queue, RetryPolicy: config.temporalPolicy(), - CronSchedule: config.Cron, Priority: newTemporalPriority(&config.CommonConfig), WorkflowExecutionTimeout: config.Timeout, VersioningIntent: defaultCommandVersioningIntent(),