Skip to content

Commit 2224408

Browse files
committed
flowctl: enable self-service task logs
* Update local-stack certificate generation to create certs that work with rustls, when used with: SSL_CERT_FILE=~/estuary/data-plane-gateway/local-tls-cert.pem * When reading ops logs, obtain a DPG token which is authorized for the task name, rather than the ops collection. * Drop stats for now to remove flowctl surface area. * Remove deprecated include-partition / exclude-partition (began to panic with auth_prefixes addition to ReadArgs for unknown reasons).
1 parent 7681c66 commit 2224408

File tree

5 files changed

+17
-66
lines changed

5 files changed

+17
-66
lines changed

Tiltfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@ DPG_TLS_KEY_PATH='%s/local-tls-private-key.pem' % DPG_REPO
9292

9393
local_resource('dpg-tls-cert',
9494
dir='%s/data-plane-gateway' % REPO_BASE,
95+
# These incantations create a non-CA self-signed certificate which is
96+
# valid for localhost and its subdomains. rustls is quite fiddly about
97+
# accepting self-signed certificates so all of these are required.
9598
cmd='[ -f %s ] || openssl req -x509 -nodes -days 365 \
96-
-subj "/C=CA/ST=QC/O=Estuary/CN=localhost:28318" \
99+
-subj "/ST=QC/O=Estuary/CN=localhost" \
100+
-addext basicConstraints=critical,CA:FALSE,pathlen:1 \
101+
-addext "subjectAltName=DNS:localhost,DNS:*.localhost,IP:127.0.0.1" \
97102
-newkey rsa:2048 -keyout "%s" \
98103
-out "%s"' % (DPG_TLS_KEY_PATH, DPG_TLS_KEY_PATH, DPG_TLS_CERT_PATH))
99104

crates/flowctl/src/collection/mod.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,8 @@ pub struct CollectionJournalSelector {
2121
/// The selector is provided as JSON matching the same shape that's used
2222
/// in Flow catalog specs. For example:
2323
/// '{"include": {"myField1":["value1", "value2"]}}'
24-
#[clap(
25-
long,
26-
value_parser(parse_partition_selector),
27-
conflicts_with_all(&["include-partition", "exclude-partition"])
28-
)]
24+
#[clap(long, value_parser(parse_partition_selector))]
2925
pub partitions: Option<models::PartitionSelector>,
30-
31-
/// Deprecated, use --partitions instead
32-
#[clap(long = "include-partition", value_parser(parse_deprecated_selector))]
33-
pub include_partitions: Vec<String>,
34-
/// Deprecated, use --partitions instead
35-
#[clap(long = "exclude-partition", value_parser(parse_deprecated_selector))]
36-
pub exclude_partitions: Vec<String>,
37-
}
38-
39-
fn parse_deprecated_selector(_: &str) -> Result<String, anyhow::Error> {
40-
anyhow::bail!("this argument has been deprecated, and replaced by --partitions")
4126
}
4227

4328
fn parse_partition_selector(arg: &str) -> Result<models::PartitionSelector, anyhow::Error> {

crates/flowctl/src/collection/read/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ pub struct ReadArgs {
2323
pub selector: CollectionJournalSelector,
2424
#[clap(flatten)]
2525
pub bounds: ReadBounds,
26-
2726
/// Read all journal data, including messages from transactions which were
2827
/// rolled back or never committed. Due to the current limitations of the Rust
2928
/// Gazette client library, this is the only mode that's currently supported,
3029
/// and this flag must be provided. In the future, committed reads will become
3130
/// the default.
3231
#[clap(long)]
3332
pub uncommitted: bool,
33+
#[clap(skip)]
34+
pub auth_prefixes: Vec<String>,
3435
}
3536

3637
/// Common definition for arguments specifying the begin and and bounds of a read command.
@@ -50,9 +51,13 @@ pub async fn journal_reader(
5051
ctx: &mut crate::CliContext,
5152
args: &ReadArgs,
5253
) -> anyhow::Result<Reader<ExponentialBackoff>> {
54+
let auth_prefixes = if args.auth_prefixes.is_empty() {
55+
vec![args.selector.collection.clone()]
56+
} else {
57+
args.auth_prefixes.clone()
58+
};
5359
let cp_client = ctx.controlplane_client().await?;
54-
let mut data_plane_client =
55-
dataplane::journal_client_for(cp_client, vec![args.selector.collection.clone()]).await?;
60+
let mut data_plane_client = dataplane::journal_client_for(cp_client, auth_prefixes).await?;
5661

5762
let selector = args.selector.build_label_selector();
5863
tracing::debug!(?selector, "build label selector");

crates/flowctl/src/lib.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,8 @@ pub enum Command {
9898
/// They can be edited, developed, and tested while still a draft.
9999
/// Then when you're ready, publish your draft to make your changes live.
100100
Draft(draft::Draft),
101-
/// This command does not (yet) work for end users
102-
///
103-
/// Note: We're still working on allowing users access to task logs, and this command will not work until we do.
104-
/// Prints the runtime logs of a task (capture, derivation, or materialization).
105-
/// Reads contents from the `ops.<data-plane>/logs` collection, selecting the partition
106-
/// that corresponds to the selected task. This command is essentially equivalent to the much longer:
107-
/// `flowctl collections read --collection ops.<data-plane>/logs --include-partition estuary.dev/field/name=<task> --uncommitted`
101+
/// Read operational logs of your tasks (captures, derivations, and materializations).
108102
Logs(ops::Logs),
109-
/// This command does not (yet) work for end users
110-
///
111-
/// Note: We're still working on allowing users access to task stats, and this command will not work until we do.
112-
/// Prints the runtime stats of a task (capture, derivation, or materialization).
113-
/// Reads contents from the `ops.<data-plane>/stats` collection, selecting the partition
114-
/// that corresponds to the selected task. This command is essentially equivalent to the much longer:
115-
/// `flowctl collections read --collection ops.<data-plane>/stats --include-partition estuary.dev/field/name=<task>`
116-
Stats(ops::Stats),
117103
/// Advanced, low-level, and experimental commands which are less common.
118104
Raw(raw::Advanced),
119105
}
@@ -194,7 +180,6 @@ impl Cli {
194180
Command::Preview(preview) => preview.run(&mut context).await,
195181
Command::Draft(draft) => draft.run(&mut context).await,
196182
Command::Logs(logs) => logs.run(&mut context).await,
197-
Command::Stats(stats) => stats.run(&mut context).await,
198183
Command::Raw(advanced) => advanced.run(&mut context).await,
199184
}?;
200185

crates/flowctl/src/ops.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,9 @@ impl Logs {
2828
}
2929
}
3030

31-
#[derive(clap::Args, Debug)]
32-
pub struct Stats {
33-
#[clap(flatten)]
34-
pub task: TaskSelector,
35-
36-
#[clap(flatten)]
37-
pub bounds: ReadBounds,
38-
39-
/// Read raw data from stats journals, including possibly uncommitted or rolled back transactions.
40-
/// This flag is currently required, but will be made optional in the future as we add support for
41-
/// committed reads, which will become the default.
42-
#[clap(long)]
43-
pub uncommitted: bool,
44-
}
45-
46-
impl Stats {
47-
pub async fn run(&self, ctx: &mut crate::CliContext) -> anyhow::Result<()> {
48-
let read_args = read_args(
49-
&self.task.task,
50-
OpsCollection::Stats,
51-
&self.bounds,
52-
self.uncommitted,
53-
);
54-
read_collection(ctx, &read_args).await?;
55-
Ok(())
56-
}
57-
}
58-
5931
#[derive(Debug, PartialEq, Clone, Copy)]
6032
pub enum OpsCollection {
6133
Logs,
62-
Stats,
6334
}
6435

6536
pub fn read_args(
@@ -70,7 +41,6 @@ pub fn read_args(
7041
) -> ReadArgs {
7142
let logs_or_stats = match collection {
7243
OpsCollection::Logs => "logs",
73-
OpsCollection::Stats => "stats",
7444
};
7545
// Once we implement federated data planes, we'll need to update this to
7646
// fetch the name of the data plane based on the tenant.
@@ -93,6 +63,7 @@ pub fn read_args(
9363
selector,
9464
uncommitted,
9565
bounds: bounds.clone(),
66+
auth_prefixes: vec![task_name.to_string()],
9667
}
9768
}
9869

0 commit comments

Comments
 (0)