-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add observability, health endpoints, CLI tooling, and Dockerfile #30
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| FROM golang:1.25-bookworm AS builder | ||
|
|
||
| WORKDIR /src | ||
|
|
||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
|
|
||
| COPY . . | ||
|
|
||
| RUN CGO_ENABLED=0 go build -trimpath \ | ||
| -ldflags="-s -w -X main.version=$(git describe --tags --always --dirty 2>/dev/null || echo docker)" \ | ||
| -o /apex ./cmd/apex | ||
|
|
||
| FROM gcr.io/distroless/static-debian12:nonroot | ||
|
|
||
| COPY --from=builder /apex /apex | ||
|
|
||
| USER 65532:65532 | ||
|
|
||
| EXPOSE 8080 9090 9091 | ||
|
|
||
| ENTRYPOINT ["/apex", "start"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "encoding/hex" | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "strconv" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func blobCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "blob", | ||
| Short: "Query blobs from the indexer", | ||
| } | ||
| cmd.AddCommand(blobGetCmd()) | ||
| cmd.AddCommand(blobListCmd()) | ||
| return cmd | ||
| } | ||
|
|
||
| func blobGetCmd() *cobra.Command { | ||
| return &cobra.Command{ | ||
| Use: "get <height> <namespace-hex> <commitment-hex>", | ||
| Short: "Get a single blob by height, namespace, and commitment", | ||
| Args: cobra.ExactArgs(3), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| addr, _ := cmd.Flags().GetString("rpc-addr") | ||
tac0turtle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| height, err := strconv.ParseUint(args[0], 10, 64) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid height: %w", err) | ||
| } | ||
|
|
||
| ns, err := hex.DecodeString(args[1]) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid namespace hex: %w", err) | ||
| } | ||
|
|
||
| commitment, err := hex.DecodeString(args[2]) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid commitment hex: %w", err) | ||
| } | ||
|
|
||
| client := newRPCClient(addr) | ||
| result, err := client.call(cmd.Context(), "blob.Get", height, ns, commitment) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return printJSON(cmd, result) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func blobListCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list <height>", | ||
| Short: "List all blobs at a given height", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| addr, _ := cmd.Flags().GetString("rpc-addr") | ||
| nsHex, _ := cmd.Flags().GetString("namespace") | ||
tac0turtle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| height, err := strconv.ParseUint(args[0], 10, 64) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid height: %w", err) | ||
| } | ||
|
|
||
| var namespaces [][]byte | ||
| if nsHex != "" { | ||
| ns, err := hex.DecodeString(nsHex) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid namespace hex: %w", err) | ||
| } | ||
| namespaces = [][]byte{ns} | ||
| } | ||
|
|
||
| client := newRPCClient(addr) | ||
| result, err := client.call(cmd.Context(), "blob.GetAll", height, namespaces) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return printJSON(cmd, result) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().String("namespace", "", "filter by namespace (hex-encoded)") | ||
| return cmd | ||
| } | ||
|
|
||
| func printJSON(_ *cobra.Command, raw json.RawMessage) error { | ||
| return prettyPrintJSON(raw) | ||
| } | ||
|
|
||
| func prettyPrintJSON(raw json.RawMessage) error { | ||
| var out any | ||
| if err := json.Unmarshal(raw, &out); err != nil { | ||
| return err | ||
| } | ||
| enc := json.NewEncoder(os.Stdout) | ||
| enc.SetIndent("", " ") | ||
| return enc.Encode(out) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "time" | ||
| ) | ||
|
|
||
| // rpcClient is a thin JSON-RPC client over HTTP for CLI commands. | ||
| type rpcClient struct { | ||
| url string | ||
| client *http.Client | ||
| } | ||
|
|
||
| func newRPCClient(addr string) *rpcClient { | ||
| return &rpcClient{ | ||
| url: "http://" + addr, | ||
| client: &http.Client{ | ||
| Timeout: 10 * time.Second, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| type jsonRPCRequest struct { | ||
| Jsonrpc string `json:"jsonrpc"` | ||
| Method string `json:"method"` | ||
| Params []any `json:"params"` | ||
| ID int `json:"id"` | ||
| } | ||
|
|
||
| type jsonRPCResponse struct { | ||
| Result json.RawMessage `json:"result"` | ||
| Error *jsonRPCError `json:"error,omitempty"` | ||
| } | ||
|
|
||
| type jsonRPCError struct { | ||
| Code int `json:"code"` | ||
| Message string `json:"message"` | ||
| } | ||
|
|
||
| func (c *rpcClient) call(ctx context.Context, method string, params ...any) (json.RawMessage, error) { | ||
| if params == nil { | ||
| params = []any{} | ||
| } | ||
|
|
||
| body, err := json.Marshal(jsonRPCRequest{ | ||
| Jsonrpc: "2.0", | ||
| Method: method, | ||
| Params: params, | ||
| ID: 1, | ||
| }) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("marshal request: %w", err) | ||
| } | ||
|
|
||
| req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.url, bytes.NewReader(body)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("create request: %w", err) | ||
| } | ||
| req.Header.Set("Content-Type", "application/json") | ||
|
|
||
| resp, err := c.client.Do(req) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("send request: %w", err) | ||
| } | ||
| defer resp.Body.Close() //nolint:errcheck | ||
|
|
||
| respBody, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("read response: %w", err) | ||
| } | ||
|
|
||
| var rpcResp jsonRPCResponse | ||
| if err := json.Unmarshal(respBody, &rpcResp); err != nil { | ||
| return nil, fmt.Errorf("unmarshal response: %w", err) | ||
| } | ||
|
|
||
| if rpcResp.Error != nil { | ||
| return nil, fmt.Errorf("rpc error %d: %s", rpcResp.Error.Code, rpcResp.Error.Message) | ||
| } | ||
|
|
||
| return rpcResp.Result, nil | ||
| } | ||
|
|
||
| // fetchHealth fetches the health endpoint directly over HTTP. | ||
| func (c *rpcClient) fetchHealth(ctx context.Context) (json.RawMessage, error) { | ||
| req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.url+"/health", nil) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("create request: %w", err) | ||
| } | ||
|
|
||
| resp, err := c.client.Do(req) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("send request: %w", err) | ||
| } | ||
| defer resp.Body.Close() //nolint:errcheck | ||
|
|
||
| body, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("read response: %w", err) | ||
| } | ||
|
|
||
| return body, nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.