diff --git a/generated/models/dlq_job.go b/generated/models/dlq_job.go index 250efb5..2121a64 100644 --- a/generated/models/dlq_job.go +++ b/generated/models/dlq_job.go @@ -52,6 +52,9 @@ type DlqJob struct { // kube cluster KubeCluster string `json:"kube_cluster,omitempty"` + // name + Name string `json:"name,omitempty"` + // namespace Namespace string `json:"namespace,omitempty"` diff --git a/internal/server/v1/dlq/handler.go b/internal/server/v1/dlq/handler.go index bee8ace..8db418d 100644 --- a/internal/server/v1/dlq/handler.go +++ b/internal/server/v1/dlq/handler.go @@ -71,12 +71,16 @@ func (*Handler) createDlqJob(w http.ResponseWriter, _ *http.Request) { } func (h *Handler) getDlqJob(w http.ResponseWriter, r *http.Request) { - // sample to get job urn from route params - _ = h.jobURN(r) + ctx := r.Context() + jobURN := h.jobURN(r) - utils.WriteJSON(w, http.StatusOK, map[string]interface{}{ - "dlq_job": nil, - }) + dlqJob, err := h.service.getDlqJob(ctx, jobURN) + if err != nil { + utils.WriteErr(w, err) + return + } + + utils.WriteJSON(w, http.StatusOK, dlqJob) } func (*Handler) firehoseURN(r *http.Request) string { diff --git a/internal/server/v1/dlq/mapper.go b/internal/server/v1/dlq/mapper.go index 7a7e88e..44302dd 100644 --- a/internal/server/v1/dlq/mapper.go +++ b/internal/server/v1/dlq/mapper.go @@ -221,23 +221,28 @@ func MapToDlqJob(r *entropyv1beta1.Resource) (*models.DlqJob, error) { errorTypes := envVars["DLQ_ERROR_TYPES"] job := models.DlqJob{ - Urn: r.Urn, - ResourceID: labels["resource_id"], - ResourceType: labels["resource_type"], - Date: labels["date"], - Topic: labels["topic"], - Namespace: modConf.Namespace, - ErrorTypes: errorTypes, - BatchSize: batchSize, - NumThreads: numThreads, - Replicas: int64(modConf.Replicas), - KubeCluster: kubeCluster, - Project: r.Project, - CreatedBy: r.CreatedBy, - UpdatedBy: r.UpdatedBy, - Status: string(r.GetState().Status), - CreatedAt: strfmt.DateTime(r.CreatedAt.AsTime()), - UpdatedAt: strfmt.DateTime(r.UpdatedAt.AsTime()), + Urn: r.Urn, + Name: r.Name, + ResourceID: labels["resource_id"], + ResourceType: labels["resource_type"], + Date: labels["date"], + Topic: labels["topic"], + PrometheusHost: labels["prometheus_host"], + Namespace: modConf.Namespace, + ContainerImage: modConf.Containers[0].Image, + ErrorTypes: errorTypes, + BatchSize: batchSize, + NumThreads: numThreads, + Replicas: int64(modConf.Replicas), + KubeCluster: kubeCluster, + Project: r.Project, + CreatedBy: r.CreatedBy, + UpdatedBy: r.UpdatedBy, + Status: string(r.GetState().Status), + CreatedAt: strfmt.DateTime(r.CreatedAt.AsTime()), + UpdatedAt: strfmt.DateTime(r.UpdatedAt.AsTime()), + EnvVars: envVars, + DlqGcsCredentialPath: envVars["DLQ_GCS_CREDENTIAL_PATH"], } return &job, nil diff --git a/internal/server/v1/dlq/service.go b/internal/server/v1/dlq/service.go index 21e9de1..986b20d 100644 --- a/internal/server/v1/dlq/service.go +++ b/internal/server/v1/dlq/service.go @@ -1,8 +1,12 @@ package dlq import ( + "context" + entropyv1beta1rpc "buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/entropy/v1beta1/entropyv1beta1grpc" + entropyv1beta1 "buf.build/gen/go/gotocompany/proton/protocolbuffers/go/gotocompany/entropy/v1beta1" + "github.com/goto/dex/generated/models" "github.com/goto/dex/internal/server/gcs" ) @@ -24,3 +28,16 @@ func NewService(client entropyv1beta1rpc.ResourceServiceClient, gcsClient gcs.Bl cfg: cfg, } } + +func (s *Service) getDlqJob(ctx context.Context, jobURN string) (*models.DlqJob, error) { + res, err := s.client.GetResource(ctx, &entropyv1beta1.GetResourceRequest{Urn: jobURN}) + if err != nil { + return nil, err + } + + dlqJob, err := MapToDlqJob(res.GetResource()) + if err != nil { + return nil, err + } + return dlqJob, nil +}