Skip to content

Commit 5026e49

Browse files
authored
Merge pull request #1 from parca-dev/override-timestamp
Allow overriding timestamps to current timestamp
2 parents fcaf0ac + c6f896e commit 5026e49

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

.golangci.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ issues:
4444

4545
linters-settings:
4646
depguard:
47-
list-type: blacklist
48-
include-go-root: true
49-
packages-with-error-message:
50-
- sync/atomic: "Use go.uber.org/atomic instead of sync/atomic"
51-
- github.com/stretchr/testify/assert: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
52-
- github.com/go-kit/kit/log: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
53-
- github.com/pkg/errors: "Use fmt.Errorf instead"
47+
rules:
48+
Main:
49+
deny:
50+
- pkg: sync/atomic
51+
desc: Use go.uber.org/atomic instead of sync/atomic
52+
- pkg: github.com/stretchr/testify/assert
53+
desc: Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert
54+
- pkg: github.com/go-kit/kit/log
55+
desc: Use github.com/go-kit/log instead of github.com/go-kit/kit/log
56+
- pkg: github.com/pkg/errors
57+
desc: Use fmt.Errorf instead
5458
errcheck:
5559
exclude: ./.errcheck_excludes.txt
5660
goimports:

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Flags:
2424
--labels=node=foo
2525
--normalized Whether the profile sample addresses are
2626
already normalized by the mapping offset.
27+
--override-timestamp Update the timestamp in the pprof profile to be
28+
the current time.
2729
--remote-store-address=STRING
2830
gRPC address to send profiles and symbols to.
2931
--remote-store-bearer-token=STRING

cmd/parca-push/main.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
package main
1616

1717
import (
18+
"bytes"
1819
"context"
1920
"crypto/tls"
2021
"fmt"
2122
"io"
2223
"os"
24+
"time"
2325

2426
"github.com/alecthomas/kong"
27+
"github.com/google/pprof/profile"
2528
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
2629
grun "github.com/oklog/run"
2730
profilestorepb "github.com/parca-dev/parca/gen/proto/go/parca/profilestore/v1alpha1"
@@ -32,9 +35,10 @@ import (
3235
)
3336

3437
type flags struct {
35-
Path string `kong:"arg,help='Path to the profile data.'"`
36-
Labels map[string]string `kong:"help='Labels to attach to the profile data. For example --labels=__name__=process_cpu --labels=node=foo',short='l'"`
37-
Normalized bool `kong:"help='Whether the profile sample addresses are already normalized by the mapping offset.',default='false'"`
38+
Path string `kong:"arg,help='Path to the profile data.'"`
39+
Labels map[string]string `kong:"help='Labels to attach to the profile data. For example --labels=__name__=process_cpu --labels=node=foo',short='l'"`
40+
Normalized bool `kong:"help='Whether the profile sample addresses are already normalized by the mapping offset.',default='false'"`
41+
OverrideTimestamp bool `kong:"help='Update the timestamp in the pprof profile to be the current time.'"`
3842

3943
RemoteStore FlagsRemoteStore `embed:"" prefix:"remote-store-"`
4044
}
@@ -75,27 +79,42 @@ func run(flags flags) error {
7579
}
7680
defer conn.Close()
7781

78-
var profile []byte
82+
var profileContent []byte
7983
if flags.Path == "-" {
80-
profile, err = io.ReadAll(os.Stdin)
84+
profileContent, err = io.ReadAll(os.Stdin)
8185
if err != nil {
8286
return fmt.Errorf("read profile from stdin: %w", err)
8387
}
8488
} else {
85-
profile, err = os.ReadFile(flags.Path)
89+
profileContent, err = os.ReadFile(flags.Path)
8690
if err != nil {
8791
return fmt.Errorf("read profile file: %w", err)
8892
}
8993
}
9094

95+
p, err := profile.ParseData(profileContent)
96+
if err != nil {
97+
return fmt.Errorf("parse pprof profile: %w", err)
98+
}
99+
100+
if flags.OverrideTimestamp {
101+
now := time.Now()
102+
p.TimeNanos = now.UnixNano()
103+
buf := bytes.NewBuffer(nil)
104+
if err := p.Write(buf); err != nil {
105+
return fmt.Errorf("serialize pprof profile: %w", err)
106+
}
107+
profileContent = buf.Bytes()
108+
}
109+
91110
profilestoreClient := profilestorepb.NewProfileStoreServiceClient(conn)
92111
_, err = profilestoreClient.WriteRaw(ctx, &profilestorepb.WriteRawRequest{
93112
Series: []*profilestorepb.RawProfileSeries{{
94113
Labels: &profilestorepb.LabelSet{
95114
Labels: labels,
96115
},
97116
Samples: []*profilestorepb.RawSample{{
98-
RawProfile: profile,
117+
RawProfile: profileContent,
99118
}},
100119
}},
101120
Normalized: flags.Normalized,

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.19
44

55
require (
66
github.com/alecthomas/kong v0.7.1
7+
github.com/google/pprof v0.0.0-20221203041831-ce31453925ec
78
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
89
github.com/oklog/run v1.1.0
910
github.com/parca-dev/parca v0.15.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw
1515
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
1616
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1717
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
18+
github.com/google/pprof v0.0.0-20221203041831-ce31453925ec h1:fR20TYVVwhK4O7r7y+McjRYyaTH6/vjwJOajE+XhlzM=
19+
github.com/google/pprof v0.0.0-20221203041831-ce31453925ec/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
1820
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
1921
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
2022
github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0 h1:t7uX3JBHdVwAi3G7sSSdbsk8NfgA+LnUS88V/2EKaA0=

0 commit comments

Comments
 (0)