Skip to content

Commit

Permalink
Merge branch 'master' into freeze-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jusrhee authored May 13, 2024
2 parents 0149358 + 63461b9 commit 886e0ae
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
42 changes: 42 additions & 0 deletions api/server/handlers/billing/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
package billing

import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"

Expand Down Expand Up @@ -80,5 +83,44 @@ func (c *IngestEventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
return
}

// Call the ingest health endpoint
err = c.postIngestHealthEndpoint(ctx, proj.ID)
if err != nil {
err := telemetry.Error(ctx, span, err, "error calling ingest health endpoint")
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
return
}

c.WriteResult(w, r, "")
}

func (c *IngestEventsHandler) postIngestHealthEndpoint(ctx context.Context, projectID uint) (err error) {
ctx, span := telemetry.NewSpan(ctx, "post-ingest-health-endpoint")
defer span.End()

// Call the ingest check webhook
webhookUrl := c.Config().ServerConf.IngestStatusWebhookUrl
telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "ingest-status-webhook-url", Value: webhookUrl})

if webhookUrl == "" {
return nil
}

req := struct {
ProjectID uint `json:"project_id"`
}{
ProjectID: projectID,
}

reqBody, err := json.Marshal(req)
if err != nil {
return telemetry.Error(ctx, span, err, "error marshalling ingest status webhook request")
}

client := &http.Client{}
resp, err := client.Post(webhookUrl, "application/json", bytes.NewBuffer(reqBody))
if err != nil || resp.StatusCode != http.StatusOK {
return telemetry.Error(ctx, span, err, "error sending ingest status webhook request")
}
return nil
}
3 changes: 3 additions & 0 deletions api/server/shared/config/env/envconfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type ServerConf struct {
PorterCloudPlanID string `env:"PORTER_CLOUD_PLAN_ID"`
PorterStandardPlanID string `env:"PORTER_STANDARD_PLAN_ID"`

// The URL of the webhook to verify ingesting events works
IngestStatusWebhookUrl string `env:"INGEST_STATUS_WEBHOOK_URL"`

// This endpoint will be passed to the porter-agent so that
// the billing manager can query Prometheus.
PrometheusUrl string `env:"PROMETHEUS_URL"`
Expand Down

0 comments on commit 886e0ae

Please sign in to comment.