Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experiment: add experimental metrics exporter #2899

Closed
wants to merge 2 commits into from

Conversation

kolesnikovae
Copy link
Collaborator

@kolesnikovae kolesnikovae commented Jan 9, 2024

A PoC of derived metrics. See #2908 for details

Comment on lines +152 to +174
func (v *TimerVec) createPprofLabels(lvs []string) pprof.LabelSet {
k := v.labels.Copy()
if len(lvs) > 0 {
for i, lv := range lvs {
k[i].Value = lv
}
}
sort.Sort(k)
var b bytes.Buffer
b.WriteString(pprofMetricLabelPrefix)
b.WriteByte('{')
for i, l := range k {
if i > 0 {
b.WriteByte(',')
b.WriteByte(' ')
}
b.WriteString(l.Name)
b.WriteByte('=')
b.WriteString(strconv.Quote(l.Value))
}
b.WriteByte('}')
return pprof.Labels(b.String(), "")
}
Copy link
Collaborator Author

@kolesnikovae kolesnikovae Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ineffective, but very simple method. Note that we should not mix metric labels with pprof labels

Comment on lines +325 to +343
for _, series := range req.Series {
for _, sample := range series.Samples {
mr := exporter.WriteRequest{
Timestamp: time.Unix(0, sample.Profile.TimeNanos).UnixMilli(),
}
pprof.ExtractMetrics(sample.Profile.Profile, func(labels labels.Labels, v int64) {
mr.TimeSeries = append(mr.TimeSeries, exporter.TimeSeries{Labels: labels, Value: float64(v)})
})

if len(mr.TimeSeries) > 0 {
go func() {
if sendErr := d.exporter.Send(context.Background(), &mr); sendErr != nil {
_ = d.logger.Log("msg", "failed to push metrics", "err", sendErr)
}
}()
}
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For PoC purposes only. Prometheus remote write protocol requires strict order by time within series, therefore we'll likely need a dedicated component that will handle proxying to receiver

if err := buf.Marshal(p); err != nil {
return err
}
return e.client.Store(ctx, snappy.Encode(nil, buf.Bytes()), 0)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prometheus also provides a "fat" remote storage that uses WAL. We should probably consider this option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant