Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
chore(dlq): access app config for mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmatrhd committed Oct 9, 2023
1 parent 32a2676 commit 0e8151d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cli/server/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type optimusConfig struct {
}

type dlqConfig struct {
Addr string `mapstructure:"addr"`
DlqJobImage string `mapstructure:"dlq_job_image"`
}

type serveConfig struct {
Expand Down
7 changes: 7 additions & 0 deletions cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
shieldv1beta1 "buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/shield/v1beta1/shieldv1beta1grpc"
sirenv1beta1 "buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/siren/v1beta1/sirenv1beta1grpc"
"github.com/MakeNowJust/heredoc"
dlqv1 "github.com/goto/dex/internal/server/v1/dlq"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/spf13/cobra"
"go.uber.org/zap"
Expand Down Expand Up @@ -104,6 +105,11 @@ func runServer(baseCtx context.Context, nrApp *newrelic.Application, zapLog *zap
if err != nil {
return err
}

dlqConfig := &dlqv1.DlqJobConfig{
// TODO: map cfg.Dlq
}

return server.Serve(ctx, cfg.Service.Addr(), nrApp, zapLog,
shieldv1beta1.NewShieldServiceClient(shieldConn),
entropyv1beta1.NewResourceServiceClient(entropyConn),
Expand All @@ -113,5 +119,6 @@ func runServer(baseCtx context.Context, nrApp *newrelic.Application, zapLog *zap
&gcs.Client{StorageClient: gcsClient},
cfg.Odin.Addr,
cfg.StencilAddr,
dlqConfig,
)
}
3 changes: 2 additions & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func Serve(ctx context.Context, addr string,
gcsClient gcs.BlobStorageClient,
odinAddr string,
stencilAddr string,
dlqConfig *dlqv1.DlqJobConfig,
) error {
alertSvc := &alertsv1.Service{Siren: sirenClient}

Expand All @@ -62,7 +63,7 @@ func Serve(ctx context.Context, addr string,
r.Route("/subscriptions", alertsv1.SubscriptionRoutes(sirenClient, shieldClient))
r.Route("/optimus", optimusv1.Routes(optimusClient))
r.Route("/projects", projectsv1.Routes(shieldClient))
r.Route("/dlq", dlqv1.Routes(entropyClient, gcsClient))
r.Route("/dlq", dlqv1.Routes(entropyClient, gcsClient, dlqConfig))
r.Route("/firehoses", firehosev1.Routes(entropyClient, shieldClient, alertSvc, compassClient, odinAddr, stencilAddr))
r.Route("/kubernetes", kubernetesv1.Routes(entropyClient))
})
Expand Down
8 changes: 1 addition & 7 deletions internal/server/v1/dlq/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import (
type Handler struct {
service *Service
}
type DlqConfig struct {
ContainerImage string `json:"container_image,omitempty"`
}

func NewHandler(service *Service) *Handler {
return &Handler{service: service}
Expand Down Expand Up @@ -66,10 +63,7 @@ func (*Handler) listDlqJobs(w http.ResponseWriter, _ *http.Request) {

func (*Handler) createDlqJob(w http.ResponseWriter, _ *http.Request) {
// transform request body into DlqJob (validation?)
// fetch firehose details
// enrich DlqJob with firehose details
// map DlqJob to entropy resource -> return entropy.Resource (kind = job)
// entropy create resource
// call service.CreateDLQJob

utils.WriteJSON(w, http.StatusOK, map[string]interface{}{
"dlq_job": nil,
Expand Down
5 changes: 3 additions & 2 deletions internal/server/v1/dlq/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type DlqJob struct {
PrometheusHost string `json:"prometheus_host,omitempty"`
}

func enrichDlqJob(job *DlqJob, f models.Firehose, ac DlqConfig) error {
func enrichDlqJob(job *DlqJob, f models.Firehose, cfg *DlqJobConfig) error {

Check failure on line 89 in internal/server/v1/dlq/mapper.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`enrichDlqJob` is unused (deadcode)

Check failure on line 89 in internal/server/v1/dlq/mapper.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`enrichDlqJob` is unused (deadcode)
var env_vars []string
for key := range f.Configs.EnvVars {
env_vars = append(env_vars, key)
Expand All @@ -96,7 +96,8 @@ func enrichDlqJob(job *DlqJob, f models.Firehose, ac DlqConfig) error {
FirehoseDeployment: f.Configs.DeploymentID,
KubeCluster: *f.Configs.KubeCluster,
EnvVars: env_vars,
// ContainerImage: ac.ContainerImage,
ContainerImage: cfg.DlqJobImage,
PrometheusHost: cfg.PrometheusHost,
}
return nil
}
Expand Down
8 changes: 6 additions & 2 deletions internal/server/v1/dlq/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import (
"github.com/goto/dex/internal/server/gcs"
)

func Routes(entropyClient entropyv1beta1rpc.ResourceServiceClient, gcsClient gcs.BlobStorageClient) func(r chi.Router) {
service := NewService(entropyClient, gcsClient)
func Routes(
entropyClient entropyv1beta1rpc.ResourceServiceClient,
gcsClient gcs.BlobStorageClient,
cfg *DlqJobConfig,
) func(r chi.Router) {
service := NewService(entropyClient, gcsClient, cfg)
handler := NewHandler(service)

return func(r chi.Router) {
Expand Down
20 changes: 19 additions & 1 deletion internal/server/v1/dlq/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,32 @@ import (
"github.com/goto/dex/internal/server/gcs"
)

type DlqJobConfig struct {
DlqJobImage string `mapstructure:"dlq_job_image"`
PrometheusHost string `mapstructure:"prometheus_host"`
}

type Service struct {
client entropyv1beta1rpc.ResourceServiceClient
gcsClient gcs.BlobStorageClient
cfg *DlqJobConfig
}

func NewService(client entropyv1beta1rpc.ResourceServiceClient, gcsClient gcs.BlobStorageClient) *Service {
func NewService(client entropyv1beta1rpc.ResourceServiceClient, gcsClient gcs.BlobStorageClient, cfg *DlqJobConfig) *Service {
return &Service{
client: client,
gcsClient: gcsClient,
cfg: cfg,
}
}

// TODO: replace *DlqJob with a generated models.DlqJob
func (s *Service) CreateDLQJob(dlqJob *DlqJob) error {
// validate dlqJob for creation

// fetch firehose details
// enrich DlqJob with firehose details
// map DlqJob to entropy resource -> return entropy.Resource (kind = job)
// entropy create resource
return nil
}

0 comments on commit 0e8151d

Please sign in to comment.