(srv client.Ingester_PushStreamServer)
| 1685 | } |
| 1686 | |
| 1687 | func (i *Ingester) PushStream(srv client.Ingester_PushStreamServer) error { |
| 1688 | ctx := srv.Context() |
| 1689 | for { |
| 1690 | select { |
| 1691 | case <-ctx.Done(): |
| 1692 | level.Warn(logutil.WithContext(ctx, i.logger)).Log("msg", "PushStream closed") |
| 1693 | return ctx.Err() |
| 1694 | default: |
| 1695 | } |
| 1696 | |
| 1697 | req, err := srv.Recv() |
| 1698 | |
| 1699 | if err == io.EOF { |
| 1700 | return nil |
| 1701 | } |
| 1702 | |
| 1703 | if err != nil { |
| 1704 | return err |
| 1705 | } |
| 1706 | |
| 1707 | if contextOrgID, extractErr := users.TenantID(ctx); extractErr == nil { |
| 1708 | if !isDistributorWorkerOrgID(contextOrgID) && contextOrgID != req.TenantID { |
| 1709 | req.Free() |
| 1710 | return status.Errorf(codes.PermissionDenied, |
| 1711 | "tenant ID mismatch: stream authenticated as %q but request specifies %q", |
| 1712 | contextOrgID, req.TenantID) |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | pushCtx := user.InjectOrgID(ctx, req.TenantID) |
| 1717 | resp, err := i.Push(pushCtx, req.Request) |
| 1718 | if resp == nil { |
| 1719 | resp = &cortexpb.WriteResponse{} |
| 1720 | } |
| 1721 | resp.Code = http.StatusOK |
| 1722 | if err != nil { |
| 1723 | httpResponse, isGRPCError := httpgrpc.HTTPResponseFromError(err) |
| 1724 | if !isGRPCError { |
| 1725 | err = httpgrpc.Errorf(http.StatusInternalServerError, "%s", err) |
| 1726 | httpResponse, _ = httpgrpc.HTTPResponseFromError(err) |
| 1727 | } |
| 1728 | resp.Code = httpResponse.Code |
| 1729 | resp.Message = string(httpResponse.Body) |
| 1730 | } |
| 1731 | err = srv.Send(resp) |
| 1732 | req.Free() |
| 1733 | if err != nil { |
| 1734 | level.Error(logutil.WithContext(ctx, i.logger)).Log("msg", "error sending from PushStream", "err", err) |
| 1735 | } |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | // isDistributorWorkerOrgID reports whether orgID matches the synthetic worker-name pattern |
| 1740 | // that the distributor injects as X-Scope-OrgID when opening a long-lived PushStream: |
nothing calls this directly
no test coverage detected