census-instrumentation / opencensus-go

A stats collection and distributed tracing framework
http://opencensus.io
Apache License 2.0
2.05k stars 327 forks source link

Is there a function or way to transfor `view.Data` to `WriteRequest` #1281

Closed jwcesign closed 1 year ago

jwcesign commented 1 year ago

What I want?

I want implement my own remote write and push data to thanos. But when I use customer exporter, I get view.Data:

func (w *metricsRemoteWriter) ExportView(data *view.Data) {
    ...
}

For thanos, it needs struct:

func (h *Handler) receiveHTTP(w http.ResponseWriter, r *http.Request) {
    ...
    var wreq prompb.WriteRequest
    if err := proto.Unmarshal(reqBuf, &wreq); err != nil {
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }
...
type WriteRequest struct {
    Timeseries []TimeSeries     `protobuf:"bytes,1,rep,name=timeseries,proto3" json:"timeseries"`
    Metadata   []MetricMetadata `protobuf:"bytes,3,rep,name=metadata,proto3" json:"metadata"`
}

Is there a good way to implement it?

dashpole commented 1 year ago

You would need to implement this yourself, which would be a significant undertaking to do correctly for the general case. But you might be able to get enough right that it would work for your use-case.

Alternatively, you could use the OpenTelemetry collector with the OpenCensus receiver and the prometheus remote write exporter.

Or, you could use the OpenCensus prometheus exporter, and scrape it with a prometheus server, which can send remote write to thanos.

jwcesign commented 1 year ago

Thanks, I use simpleprometheus with prometheus remote write, it works for me