Skip to content

Commit 54afbef

Browse files
committed
feat: add log export
1 parent 96a10b6 commit 54afbef

File tree

176 files changed

+7853
-3406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+7853
-3406
lines changed

Justfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ openapi:
3737
@yq eval-all '. as $item ireduce ({}; . * $item)' openapi/v1.yaml openapi/v2.yaml openapi/overlay.yaml > openapi.yaml
3838
@npx -y widdershins {{justfile_directory()}}/openapi/v2.yaml -o {{justfile_directory()}}/docs/api/README.md --search false --language_tabs 'http:HTTP' --summary --omitHeader
3939

40-
generate-client:
40+
generate-client: openapi
4141
@speakeasy generate sdk -s openapi.yaml -o ./pkg/client -l go
4242

4343
release-local:

cmd/serve.go

+39-19
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package cmd
33
import (
44
"github.com/formancehq/go-libs/v2/logging"
55
"github.com/formancehq/ledger/internal/api/common"
6-
replicationcontroller "github.com/formancehq/ledger/internal/replication/controller"
7-
"github.com/formancehq/ledger/internal/replication/leadership"
86
"github.com/formancehq/ledger/internal/leadership"
7+
"github.com/formancehq/ledger/internal/replication/drivers"
8+
"github.com/formancehq/ledger/internal/replication/drivers/all"
9+
"github.com/formancehq/ledger/internal/replication/runner"
910
systemstore "github.com/formancehq/ledger/internal/storage/system"
1011
"net/http"
1112
"net/http/pprof"
@@ -39,17 +40,20 @@ import (
3940
)
4041

4142
const (
42-
BindFlag = "bind"
43-
BallastSizeInBytesFlag = "ballast-size"
44-
NumscriptCacheMaxCountFlag = "numscript-cache-max-count"
45-
AutoUpgradeFlag = "auto-upgrade"
46-
ExperimentalFeaturesFlag = "experimental-features"
47-
BulkMaxSizeFlag = "bulk-max-size"
48-
BulkParallelFlag = "bulk-parallel"
49-
NumscriptInterpreterFlag = "experimental-numscript-interpreter"
43+
BindFlag = "bind"
44+
BallastSizeInBytesFlag = "ballast-size"
45+
NumscriptCacheMaxCountFlag = "numscript-cache-max-count"
46+
AutoUpgradeFlag = "auto-upgrade"
47+
ExperimentalFeaturesFlag = "experimental-features"
48+
BulkMaxSizeFlag = "bulk-max-size"
49+
BulkParallelFlag = "bulk-parallel"
50+
NumscriptInterpreterFlag = "experimental-numscript-interpreter"
5051
NumscriptInterpreterFlagsToPass = "numscript-interpreter-flags"
51-
DefaultPageSizeFlag = "default-page-size"
52-
MaxPageSizeFlag = "max-page-size"
52+
DefaultPageSizeFlag = "default-page-size"
53+
MaxPageSizeFlag = "max-page-size"
54+
PipelinesSyncPeriodFlag = "pipelines-sync-period"
55+
PipelinesPullIntervalFlag = "pipelines-pull-interval"
56+
PipelinesPushRetryPeriodFlag = "pipelines-push-retry-period"
5357
)
5458

5559
func NewServeCommand() *cobra.Command {
@@ -100,6 +104,13 @@ func NewServeCommand() *cobra.Command {
100104
auth.FXModuleFromFlags(cmd),
101105
bunconnect.Module(*connectionOptions, service.IsDebug(cmd)),
102106
storage.NewFXModule(serveConfiguration.autoUpgrade),
107+
runner.NewFXModule(runner.ModuleConfig{
108+
SyncPeriod: serveConfiguration.pipelinesSyncPeriod,
109+
PullInterval: serveConfiguration.pipelinesPullInterval,
110+
PushRetryPeriod: serveConfiguration.pipelinesPushRetryPeriod,
111+
}),
112+
drivers.NewFXModule(),
113+
fx.Invoke(all.Register),
103114
systemcontroller.NewFXModule(systemcontroller.ModuleConfiguration{
104115
NumscriptInterpreter: numscriptInterpreter,
105116
NumscriptInterpreterFlags: numscriptInterpreterFlags,
@@ -114,7 +125,9 @@ func NewServeCommand() *cobra.Command {
114125
}),
115126
bus.NewFxModule(),
116127
ballast.Module(serveConfiguration.ballastSize),
117-
leadership.NewFXModule(),
128+
leadership.NewFXModule(leadership.ModuleConfig{
129+
LeadershipRetryPeriod: 5 * time.Second,
130+
}),
118131
api.Module(api.Config{
119132
Version: Version,
120133
Debug: service.IsDebug(cmd),
@@ -148,8 +161,6 @@ func NewServeCommand() *cobra.Command {
148161
params.Handler,
149162
)
150163
}),
151-
replicationcontroller.NewFXModule(),
152-
leadership.NewFXModule(),
153164
fx.Invoke(func(lc fx.Lifecycle, h chi.Router) {
154165
lc.Append(httpserver.NewHook(h, httpserver.WithAddress(serveConfiguration.bind)))
155166
}),
@@ -169,6 +180,9 @@ func NewServeCommand() *cobra.Command {
169180
cmd.Flags().String(NumscriptInterpreterFlagsToPass, "", "Feature flags to pass to the experimental numscript interpreter")
170181
cmd.Flags().Uint64(MaxPageSizeFlag, 100, "Max page size")
171182
cmd.Flags().Uint64(DefaultPageSizeFlag, 15, "Default page size")
183+
cmd.Flags().Duration(PipelinesSyncPeriodFlag, 5*time.Second, "Pipelines sync period")
184+
cmd.Flags().Duration(PipelinesPullIntervalFlag, runner.DefaultPullInterval, "Pipelines pull interval")
185+
cmd.Flags().Duration(PipelinesPushRetryPeriodFlag, runner.DefaultPushRetryPeriod, "Pipelines push retry period")
172186

173187
service.AddFlags(cmd.Flags())
174188
bunconnect.AddFlags(cmd.Flags())
@@ -184,10 +198,13 @@ func NewServeCommand() *cobra.Command {
184198
}
185199

186200
type serveConfiguration struct {
187-
ballastSize uint
188-
numscriptCacheMaxCount uint
189-
autoUpgrade bool
190-
bind string
201+
ballastSize uint
202+
numscriptCacheMaxCount uint
203+
autoUpgrade bool
204+
bind string
205+
pipelinesSyncPeriod time.Duration
206+
pipelinesPullInterval time.Duration
207+
pipelinesPushRetryPeriod time.Duration
191208
}
192209

193210
func discoverServeConfiguration(cmd *cobra.Command) serveConfiguration {
@@ -196,6 +213,9 @@ func discoverServeConfiguration(cmd *cobra.Command) serveConfiguration {
196213
ret.numscriptCacheMaxCount, _ = cmd.Flags().GetUint(NumscriptCacheMaxCountFlag)
197214
ret.autoUpgrade, _ = cmd.Flags().GetBool(AutoUpgradeFlag)
198215
ret.bind, _ = cmd.Flags().GetString(BindFlag)
216+
ret.pipelinesSyncPeriod, _ = cmd.Flags().GetDuration(PipelinesSyncPeriodFlag)
217+
ret.pipelinesPullInterval, _ = cmd.Flags().GetDuration(PipelinesPullIntervalFlag)
218+
ret.pipelinesPushRetryPeriod, _ = cmd.Flags().GetDuration(PipelinesPushRetryPeriodFlag)
199219

200220
return ret
201221
}

deployments/pulumi/pkg/component.go

+64-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
batchv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/batch/v1"
88
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1"
99
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1"
10+
networkingv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/networking/v1"
1011
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
1112
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
1213
"slices"
@@ -30,6 +31,7 @@ type Component struct {
3031
ServiceNamespace pulumix.Output[string]
3132
ServicePort pulumix.Output[int]
3233
ServiceInternalURL pulumix.Output[string]
34+
Deployment *appsv1.Deployment
3335
}
3436

3537
type PostgresArgs struct {
@@ -62,6 +64,11 @@ type OtelMetricsArgs struct {
6264
OtelMetricsExporterOTLPInsecure pulumix.Input[bool]
6365
}
6466

67+
type IngressArgs struct {
68+
Host pulumix.Input[string]
69+
Secret pulumix.Input[*string]
70+
}
71+
6572
type OtelArgs struct {
6673
ResourceAttributes pulumix.Input[map[string]string]
6774
ServiceName pulumix.Input[string]
@@ -73,6 +80,7 @@ type OtelArgs struct {
7380
type ComponentArgs struct {
7481
Postgres PostgresArgs
7582
Otel *OtelArgs
83+
Ingress *IngressArgs
7684
Namespace pulumix.Input[string]
7785
Timeout pulumix.Input[int]
7886
Tag pulumix.Input[string]
@@ -442,7 +450,7 @@ func NewComponent(ctx *pulumi.Context, name string, args *ComponentArgs, opts ..
442450
terminationGracePeriodSeconds = args.TerminationGracePeriodSeconds.ToOutput(ctx.Context()).Untyped().(pulumi.IntPtrOutput)
443451
}
444452

445-
deployment, err := appsv1.NewDeployment(ctx, "ledger", &appsv1.DeploymentArgs{
453+
cmp.Deployment, err = appsv1.NewDeployment(ctx, "ledger", &appsv1.DeploymentArgs{
446454
Metadata: &metav1.ObjectMetaArgs{
447455
Namespace: namespace.Untyped().(pulumi.StringOutput),
448456
Labels: pulumi.StringMap{
@@ -560,7 +568,7 @@ func NewComponent(ctx *pulumi.Context, name string, args *ComponentArgs, opts ..
560568
Namespace: namespace.Untyped().(pulumi.StringOutput),
561569
},
562570
Spec: &corev1.ServiceSpecArgs{
563-
Selector: deployment.Spec.Selector().MatchLabels(),
571+
Selector: cmp.Deployment.Spec.Selector().MatchLabels(),
564572
Type: pulumi.String("ClusterIP"),
565573
Ports: corev1.ServicePortArray{
566574
corev1.ServicePortArgs{
@@ -598,7 +606,61 @@ func NewComponent(ctx *pulumi.Context, name string, args *ComponentArgs, opts ..
598606
return url
599607
})
600608

609+
if args.Ingress != nil {
610+
_, err = networkingv1.NewIngress(ctx, "ledger", &networkingv1.IngressArgs{
611+
Metadata: &metav1.ObjectMetaArgs{
612+
Namespace: namespace.Untyped().(pulumi.StringOutput),
613+
},
614+
Spec: &networkingv1.IngressSpecArgs{
615+
Rules: networkingv1.IngressRuleArray{
616+
networkingv1.IngressRuleArgs{
617+
Host: args.Ingress.Host.ToOutput(ctx.Context()).Untyped().(pulumi.StringOutput),
618+
Http: networkingv1.HTTPIngressRuleValueArgs{
619+
Paths: networkingv1.HTTPIngressPathArray{
620+
networkingv1.HTTPIngressPathArgs{
621+
Backend: networkingv1.IngressBackendArgs{
622+
Service: &networkingv1.IngressServiceBackendArgs{
623+
Name: cmp.ServiceName.ToOutput(ctx.Context()).Untyped().(pulumi.StringOutput),
624+
Port: networkingv1.ServiceBackendPortArgs{
625+
Name: pulumi.String("http"),
626+
},
627+
},
628+
},
629+
Path: pulumi.String("/"),
630+
PathType: pulumi.String("Prefix"),
631+
},
632+
},
633+
},
634+
},
635+
},
636+
Tls: pulumix.Apply(args.Ingress.Secret, func(secret *string) networkingv1.IngressTLSArrayInput {
637+
if secret == nil || *secret == "" {
638+
return nil
639+
}
640+
641+
return networkingv1.IngressTLSArray{
642+
networkingv1.IngressTLSArgs{
643+
Hosts: pulumi.StringArray{
644+
args.Ingress.Host.ToOutput(ctx.Context()).Untyped().(pulumi.StringOutput),
645+
},
646+
SecretName: pulumi.String(*secret),
647+
},
648+
}
649+
}).Untyped().(pulumi.AnyOutput).ApplyT(func(v any) networkingv1.IngressTLSArrayInput {
650+
if v == nil {
651+
return nil
652+
}
653+
return v.(networkingv1.IngressTLSArrayInput)
654+
}).(networkingv1.IngressTLSArrayInput),
655+
},
656+
}, pulumi.Parent(cmp))
657+
if err != nil {
658+
return nil, err
659+
}
660+
}
661+
601662
if err := ctx.RegisterResourceOutputs(cmp, pulumi.Map{
663+
"deployment-name": cmp.Deployment.Metadata.Name(),
602664
"service-name": cmp.ServiceName,
603665
"service-namespace": cmp.ServiceNamespace,
604666
"service-port": cmp.ServicePort,

0 commit comments

Comments
 (0)