• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence / 01907562-f5f0-40b6-8908-451d758b6138

02 Jul 2024 09:37PM UTC coverage: 71.512% (+0.003%) from 71.509%
01907562-f5f0-40b6-8908-451d758b6138

Pull #6155

buildkite

Groxx
Stop the ratelimiter collections when stopping the service
Pull Request #6155: Stop the ratelimiter collections when stopping the service

9 of 17 new or added lines in 1 file covered. (52.94%)

22 existing lines in 7 files now uncovered.

105315 of 147269 relevant lines covered (71.51%)

2600.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.51
/tools/cli/admin_db_decode_thrift.go
1
// The MIT License (MIT)
2
//
3
// Copyright (c) 2020 Uber Technologies, Inc.
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included in all
13
// copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22

23
package cli
24

25
import (
26
        "bytes"
27
        "encoding/base64"
28
        "encoding/hex"
29
        "encoding/json"
30
        "fmt"
31
        "strings"
32

33
        "github.com/davecgh/go-spew/spew"
34
        "github.com/urfave/cli"
35

36
        "github.com/uber/cadence/.gen/go/config"
37
        "github.com/uber/cadence/.gen/go/history"
38
        "github.com/uber/cadence/.gen/go/replicator"
39
        "github.com/uber/cadence/.gen/go/shared"
40
        "github.com/uber/cadence/.gen/go/sqlblobs"
41
        "github.com/uber/cadence/common/codec"
42
)
43

44
var decodingTypes = map[string]func() codec.ThriftObject{
45
        "shared.History":                    func() codec.ThriftObject { return &shared.History{} },
2✔
46
        "shared.HistoryEvent":               func() codec.ThriftObject { return &shared.HistoryEvent{} },
3✔
47
        "shared.HistoryBranch":              func() codec.ThriftObject { return &shared.HistoryBranch{} },
3✔
48
        "shared.Memo":                       func() codec.ThriftObject { return &shared.Memo{} },
2✔
49
        "shared.ResetPoints":                func() codec.ThriftObject { return &shared.ResetPoints{} },
3✔
50
        "shared.BadBinaries":                func() codec.ThriftObject { return &shared.BadBinaries{} },
3✔
51
        "shared.VersionHistories":           func() codec.ThriftObject { return &shared.VersionHistories{} },
6✔
52
        "replicator.FailoverMarkers":        func() codec.ThriftObject { return &replicator.FailoverMarkers{} },
3✔
53
        "history.ProcessingQueueStates":     func() codec.ThriftObject { return &history.ProcessingQueueStates{} },
3✔
54
        "config.DynamicConfigBlob":          func() codec.ThriftObject { return &config.DynamicConfigBlob{} },
2✔
55
        "sqlblobs.ShardInfo":                func() codec.ThriftObject { return &sqlblobs.ShardInfo{} },
3✔
56
        "sqlblobs.DomainInfo":               func() codec.ThriftObject { return &sqlblobs.DomainInfo{} },
3✔
57
        "sqlblobs.HistoryTreeInfo":          func() codec.ThriftObject { return &sqlblobs.HistoryTreeInfo{} },
2✔
58
        "sqlblobs.WorkflowExecutionInfo":    func() codec.ThriftObject { return &sqlblobs.WorkflowExecutionInfo{} },
2✔
59
        "sqlblobs.ActivityInfo":             func() codec.ThriftObject { return &sqlblobs.ActivityInfo{} },
4✔
60
        "sqlblobs.ChildExecutionInfo":       func() codec.ThriftObject { return &sqlblobs.ChildExecutionInfo{} },
4✔
61
        "sqlblobs.SignalInfo":               func() codec.ThriftObject { return &sqlblobs.SignalInfo{} },
2✔
62
        "sqlblobs.RequestCancelInfo":        func() codec.ThriftObject { return &sqlblobs.RequestCancelInfo{} },
2✔
63
        "sqlblobs.TimerInfo":                func() codec.ThriftObject { return &sqlblobs.TimerInfo{} },
2✔
64
        "sqlblobs.TaskInfo":                 func() codec.ThriftObject { return &sqlblobs.TaskInfo{} },
4✔
65
        "sqlblobs.TaskListInfo":             func() codec.ThriftObject { return &sqlblobs.TaskListInfo{} },
5✔
UNCOV
66
        "sqlblobs.TransferTaskInfo":         func() codec.ThriftObject { return &sqlblobs.TransferTaskInfo{} },
×
UNCOV
67
        "sqlblobs.TimerTaskInfo":            func() codec.ThriftObject { return &sqlblobs.TimerTaskInfo{} },
×
68
        "sqlblobs.ReplicationTaskInfo":      func() codec.ThriftObject { return &sqlblobs.ReplicationTaskInfo{} },
5✔
69
        "shared.AsyncWorkflowConfiguration": func() codec.ThriftObject { return &shared.AsyncWorkflowConfiguration{} },
3✔
70
}
71

72
type decodeError struct {
73
        shortMsg string
74
        err      error
75
}
76

77
// AdminDBDataDecodeThrift is the command to decode thrift binary into JSON
78
func AdminDBDataDecodeThrift(c *cli.Context) {
×
79
        input := getRequiredOption(c, FlagInput)
×
80
        encoding := c.String(FlagInputEncoding)
×
81
        data, err := decodeUserInput(input, encoding)
×
82
        if err != nil {
×
83
                ErrorAndExit("failed to decode input", err)
×
84
        }
×
85

86
        if _, err := decodeThriftPayload(data); err != nil {
×
87
                ErrorAndExit(err.shortMsg, err.err)
×
88
        }
×
89
}
90

91
func decodeThriftPayload(data []byte) (codec.ThriftObject, *decodeError) {
8✔
92
        encoder := codec.NewThriftRWEncoder()
8✔
93
        // this is an inconsistency in the code base, some place use ThriftRWEncoder(version0Thriftrw.go) some use thriftEncoder(thrift_encoder.go)
8✔
94
        dataWithPrepend := []byte{0x59}
8✔
95
        dataWithPrepend = append(dataWithPrepend, data...)
8✔
96
        datas := [][]byte{data, dataWithPrepend}
8✔
97

8✔
98
        for _, data := range datas {
16✔
99
                for typeName, objFn := range decodingTypes {
79✔
100
                        t := objFn()
71✔
101
                        if err := encoder.Decode(data, t); err != nil {
71✔
102
                                continue
×
103
                        }
104

105
                        // encoding back to confirm
106
                        data2, err := encoder.Encode(t)
71✔
107
                        if err != nil {
71✔
108
                                return nil, &decodeError{
×
109
                                        shortMsg: "cannot encode back to confirm",
×
110
                                        err:      err,
×
111
                                }
×
112
                        }
×
113
                        if !bytes.Equal(data, data2) {
134✔
114
                                continue
63✔
115
                        }
116

117
                        fmt.Printf("======= Decode into type %v ========\n", typeName)
8✔
118
                        spew.Dump(t)
8✔
119
                        // json-ify it for easier mechanical use
8✔
120
                        js, err := json.Marshal(t)
8✔
121
                        if err == nil {
16✔
122
                                fmt.Println("======= As JSON ========")
8✔
123
                                fmt.Println(string(js))
8✔
124
                        }
8✔
125
                        return t, nil
8✔
126
                }
127
        }
128

129
        return nil, &decodeError{
×
130
                shortMsg: "input data cannot be decoded into any struct",
×
131
                err:      nil,
×
132
        }
×
133
}
134

135
func decodeUserInput(input, encoding string) ([]byte, error) {
10✔
136
        switch encoding {
10✔
137
        case "", "hex":
8✔
138
                // remove "0x" from the beginning of the input. hex library doesn't expect it but that's how it's printed it out by csql
8✔
139
                input = strings.TrimPrefix(input, "0x")
8✔
140
                return hex.DecodeString(input)
8✔
141
        case "base64":
2✔
142
                return base64.StdEncoding.DecodeString(input)
2✔
143
        }
144

145
        return nil, fmt.Errorf("unknown input encoding: %s", encoding)
×
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc