bitfab 0.51.3 → 0.51.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bitfab/datasets.rb +23 -5
- data/lib/bitfab/git_command.rb +3 -2
- data/lib/bitfab/git_state.rb +72 -0
- data/lib/bitfab/http_client.rb +3 -0
- data/lib/bitfab/version.rb +1 -1
- data/lib/bitfab.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6bf8a9d45207caf1c5a6ef62a0e9ad6af43e5ccd904a25c8b8cd1fefd73795b9
|
|
4
|
+
data.tar.gz: 684d7a18b4dc4cde5df27bce58e9be1a7ed3dbd8a644638148d81746cd9e7683
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f3ffe75284ce984a57b524746a640ad8b51a10b32d4835d35a1d692415a23cfd09a7730105825713919c519e5dc256b444ba329c4bd0783f24a07e933315cb87
|
|
7
|
+
data.tar.gz: c9da6e278539c0fe49d5192d05624ce0e1ba0f36ce0e9e8bf23511fd336bc39a3b58427d1196fee0418a7569f2920aefa5c9f456c57d246d1d01ebabb0306b21
|
data/lib/bitfab/datasets.rb
CHANGED
|
@@ -25,10 +25,19 @@ module Bitfab
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
# List datasets, scoped to one trace function when given and
|
|
28
|
-
# organization-wide otherwise.
|
|
28
|
+
# organization-wide otherwise. Fetches all pages automatically.
|
|
29
29
|
def list(trace_function_key: nil)
|
|
30
|
-
query =
|
|
31
|
-
|
|
30
|
+
query = {"limit" => "100"}
|
|
31
|
+
query["traceFunctionKey"] = trace_function_key unless trace_function_key.nil?
|
|
32
|
+
datasets = []
|
|
33
|
+
loop do
|
|
34
|
+
result = @http_client.get("/api/sdk/datasets?#{URI.encode_www_form(query)}")
|
|
35
|
+
datasets.concat(result["datasets"])
|
|
36
|
+
cursor = result["nextCursor"]
|
|
37
|
+
return datasets if cursor.nil?
|
|
38
|
+
|
|
39
|
+
query["cursor"] = cursor
|
|
40
|
+
end
|
|
32
41
|
end
|
|
33
42
|
|
|
34
43
|
# Fetch one dataset by id. A dataset outside this organization raises
|
|
@@ -38,9 +47,18 @@ module Bitfab
|
|
|
38
47
|
end
|
|
39
48
|
|
|
40
49
|
# The ids of every trace in the dataset, the same membership a replay with
|
|
41
|
-
# dataset_id: selects.
|
|
50
|
+
# dataset_id: selects. Fetches all pages automatically.
|
|
42
51
|
def list_traces(dataset_id)
|
|
43
|
-
|
|
52
|
+
trace_ids = []
|
|
53
|
+
query = {"limit" => "100"}
|
|
54
|
+
loop do
|
|
55
|
+
page = @http_client.get("#{dataset_path(dataset_id, "/traces")}?#{URI.encode_www_form(query)}")
|
|
56
|
+
trace_ids.concat(page["traceIds"])
|
|
57
|
+
cursor = page["nextCursor"]
|
|
58
|
+
return {"datasetId" => page["datasetId"], "traceIds" => trace_ids} if cursor.nil?
|
|
59
|
+
|
|
60
|
+
query["cursor"] = cursor
|
|
61
|
+
end
|
|
44
62
|
end
|
|
45
63
|
|
|
46
64
|
# Add traces to the dataset (1 to 100 ids per call). Traces outside the
|
data/lib/bitfab/git_command.rb
CHANGED
|
@@ -8,8 +8,9 @@ module Bitfab
|
|
|
8
8
|
|
|
9
9
|
module_function
|
|
10
10
|
|
|
11
|
-
def run(cwd, args, timeout:)
|
|
12
|
-
|
|
11
|
+
def run(cwd, args, timeout:, env: nil)
|
|
12
|
+
command = env ? [env, "git", *args] : ["git", *args]
|
|
13
|
+
Open3.popen3(*command, chdir: cwd, **spawn_options) do |stdin, stdout, stderr, wait_thread|
|
|
13
14
|
stdin.close
|
|
14
15
|
out = +""
|
|
15
16
|
reader = Thread.new { out = read_all(stdout) }
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "tmpdir"
|
|
4
|
+
require_relative "git_command"
|
|
5
|
+
|
|
6
|
+
module Bitfab
|
|
7
|
+
module GitState
|
|
8
|
+
DISABLE_ENV = "BITFAB_DISABLE_GIT_STATE"
|
|
9
|
+
GIT_TIMEOUT_SECONDS = 30
|
|
10
|
+
SHA_PATTERN = /\A[0-9a-f]{40}\z/
|
|
11
|
+
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
def git(cwd, *args, env: nil)
|
|
15
|
+
GitCommand.run(cwd, args, timeout: GIT_TIMEOUT_SECONDS, env: env)&.strip
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def text(value)
|
|
19
|
+
trimmed = value&.strip
|
|
20
|
+
(trimmed.nil? || trimmed.empty?) ? nil : trimmed
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def sha(value)
|
|
24
|
+
trimmed = text(value)
|
|
25
|
+
(trimmed && SHA_PATTERN.match?(trimmed)) ? trimmed : nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def empty?(state)
|
|
29
|
+
state.values.all?(&:nil?)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def resolve_working_tree_sha(root)
|
|
33
|
+
Dir.mktmpdir("bitfab-git-") do |dir|
|
|
34
|
+
env = {"GIT_INDEX_FILE" => File.join(dir, "index")}
|
|
35
|
+
return nil if git(root, "read-tree", "HEAD", env: env).nil?
|
|
36
|
+
return nil if git(root, "add", "-A", "--", root, env: env).nil?
|
|
37
|
+
|
|
38
|
+
sha(git(root, "write-tree", env: env))
|
|
39
|
+
end
|
|
40
|
+
rescue
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def resolve(cwd)
|
|
45
|
+
refs = git(cwd, "rev-parse", "--show-toplevel", "HEAD", "HEAD^{tree}")
|
|
46
|
+
lines = refs.to_s.split("\n")
|
|
47
|
+
root = text(lines[0])
|
|
48
|
+
return nil if root.nil?
|
|
49
|
+
|
|
50
|
+
state = {
|
|
51
|
+
"githubEmail" => text(git(cwd, "config", "user.email")),
|
|
52
|
+
"branch" => text(git(cwd, "symbolic-ref", "--short", "-q", "HEAD")),
|
|
53
|
+
"commitSha" => sha(lines[1]),
|
|
54
|
+
"baseSha" => sha(lines[2]),
|
|
55
|
+
"experimentSha" => resolve_working_tree_sha(root)
|
|
56
|
+
}
|
|
57
|
+
empty?(state) ? nil : state
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def resolved
|
|
61
|
+
return nil unless ENV[DISABLE_ENV].to_s.empty?
|
|
62
|
+
|
|
63
|
+
safe_resolve
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def safe_resolve
|
|
67
|
+
resolve(Dir.pwd)
|
|
68
|
+
rescue
|
|
69
|
+
nil
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
data/lib/bitfab/http_client.rb
CHANGED
|
@@ -4,6 +4,7 @@ require "net/http"
|
|
|
4
4
|
require "json"
|
|
5
5
|
require "uri"
|
|
6
6
|
|
|
7
|
+
require_relative "git_state"
|
|
7
8
|
require_relative "compress"
|
|
8
9
|
require_relative "constants"
|
|
9
10
|
require_relative "serialize"
|
|
@@ -207,6 +208,8 @@ module Bitfab
|
|
|
207
208
|
end
|
|
208
209
|
payload["graderIds"] = grader_ids unless grader_ids.nil?
|
|
209
210
|
payload["dbBranchSettings"] = db_branch_settings unless db_branch_settings.nil?
|
|
211
|
+
git_state = GitState.resolved
|
|
212
|
+
payload["git"] = git_state if git_state
|
|
210
213
|
|
|
211
214
|
# When DB branching is on, the server resolves a Neon preview branch per
|
|
212
215
|
# item (snapshot + restore + poll), which can run several seconds each,
|
data/lib/bitfab/version.rb
CHANGED
data/lib/bitfab.rb
CHANGED
|
@@ -10,6 +10,7 @@ require_relative "bitfab/serialize"
|
|
|
10
10
|
require_relative "bitfab/db_snapshot"
|
|
11
11
|
require_relative "bitfab/git_command"
|
|
12
12
|
require_relative "bitfab/commit_ref"
|
|
13
|
+
require_relative "bitfab/git_state"
|
|
13
14
|
require_relative "bitfab/span_context"
|
|
14
15
|
require_relative "bitfab/http_client"
|
|
15
16
|
require_relative "bitfab/datasets"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bitfab
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.51.
|
|
4
|
+
version: 0.51.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Harvest Team
|
|
@@ -146,6 +146,7 @@ files:
|
|
|
146
146
|
- lib/bitfab/datasets.rb
|
|
147
147
|
- lib/bitfab/db_snapshot.rb
|
|
148
148
|
- lib/bitfab/git_command.rb
|
|
149
|
+
- lib/bitfab/git_state.rb
|
|
149
150
|
- lib/bitfab/http_client.rb
|
|
150
151
|
- lib/bitfab/mock_override.rb
|
|
151
152
|
- lib/bitfab/otel.rb
|