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

uber / cadence / 018df3b0-7004-4cc1-9aee-181011e7265f

29 Feb 2024 07:04AM UTC coverage: 62.892% (-0.009%) from 62.901%
018df3b0-7004-4cc1-9aee-181011e7265f

Pull #5695

buildkite

jakobht
Fix the local integration test docker-compose file

Moved updates to the docker-compose file used in the CI to the local
docker-compose, so we can run the integration tests locally in docker.
Pull Request #5695: Fix the local integration test docker-compose file

92958 of 147805 relevant lines covered (62.89%)

2327.92 hits per line

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

68.83
/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{} },
3✔
46
        "shared.HistoryEvent":            func() codec.ThriftObject { return &shared.HistoryEvent{} },
3✔
47
        "shared.HistoryBranch":           func() codec.ThriftObject { return &shared.HistoryBranch{} },
4✔
48
        "shared.Memo":                    func() codec.ThriftObject { return &shared.Memo{} },
4✔
49
        "shared.ResetPoints":             func() codec.ThriftObject { return &shared.ResetPoints{} },
6✔
50
        "shared.BadBinaries":             func() codec.ThriftObject { return &shared.BadBinaries{} },
3✔
51
        "shared.VersionHistories":        func() codec.ThriftObject { return &shared.VersionHistories{} },
4✔
52
        "replicator.FailoverMarkers":     func() codec.ThriftObject { return &replicator.FailoverMarkers{} },
1✔
53
        "history.ProcessingQueueStates":  func() codec.ThriftObject { return &history.ProcessingQueueStates{} },
4✔
54
        "config.DynamicConfigBlob":       func() codec.ThriftObject { return &config.DynamicConfigBlob{} },
3✔
55
        "sqlblobs.ShardInfo":             func() codec.ThriftObject { return &sqlblobs.ShardInfo{} },
3✔
56
        "sqlblobs.DomainInfo":            func() codec.ThriftObject { return &sqlblobs.DomainInfo{} },
1✔
57
        "sqlblobs.HistoryTreeInfo":       func() codec.ThriftObject { return &sqlblobs.HistoryTreeInfo{} },
5✔
58
        "sqlblobs.WorkflowExecutionInfo": func() codec.ThriftObject { return &sqlblobs.WorkflowExecutionInfo{} },
4✔
59
        "sqlblobs.ActivityInfo":          func() codec.ThriftObject { return &sqlblobs.ActivityInfo{} },
3✔
60
        "sqlblobs.ChildExecutionInfo":    func() codec.ThriftObject { return &sqlblobs.ChildExecutionInfo{} },
4✔
61
        "sqlblobs.SignalInfo":            func() codec.ThriftObject { return &sqlblobs.SignalInfo{} },
4✔
62
        "sqlblobs.RequestCancelInfo":     func() codec.ThriftObject { return &sqlblobs.RequestCancelInfo{} },
4✔
63
        "sqlblobs.TimerInfo":             func() codec.ThriftObject { return &sqlblobs.TimerInfo{} },
4✔
64
        "sqlblobs.TaskInfo":              func() codec.ThriftObject { return &sqlblobs.TaskInfo{} },
×
65
        "sqlblobs.TaskListInfo":          func() codec.ThriftObject { return &sqlblobs.TaskListInfo{} },
2✔
66
        "sqlblobs.TransferTaskInfo":      func() codec.ThriftObject { return &sqlblobs.TransferTaskInfo{} },
×
67
        "sqlblobs.TimerTaskInfo":         func() codec.ThriftObject { return &sqlblobs.TimerTaskInfo{} },
×
68
        "sqlblobs.ReplicationTaskInfo":   func() codec.ThriftObject { return &sqlblobs.ReplicationTaskInfo{} },
5✔
69
}
70

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

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

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

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

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

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

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

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

134
func decodeUserInput(input, encoding string) ([]byte, error) {
10✔
135
        switch encoding {
10✔
136
        case "", "hex":
8✔
137
                // 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✔
138
                input = strings.TrimPrefix(input, "0x")
8✔
139
                return hex.DecodeString(input)
8✔
140
        case "base64":
2✔
141
                return base64.StdEncoding.DecodeString(input)
2✔
142
        }
143

144
        return nil, fmt.Errorf("unknown input encoding: %s", encoding)
×
145
}
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

© 2026 Coveralls, Inc