census-instrumentation/opencensus-go

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

jwcesign opened this issue · 2 comments

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?

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.

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