Skip to content

Commit f1d0e5a

Browse files
add warning and mock output to inspect
1 parent 3e3aa15 commit f1d0e5a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

internal/pkg/agent/cmd/inspect.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,40 @@ func inspectConfig(ctx context.Context, cfgPath string, opts inspectConfigOpts,
181181
return fmt.Errorf("failed to get binary mappings: %w", err)
182182
}
183183

184+
// service units like endpoint are special; they require a PID to monitor.
185+
// however, `inspect` doesn't talk to the coordinator backend, which means it can't know their actual PID from this point in the code
186+
// instead, we look for service units and create a fake PID, so we print the monitoring config anyway.
187+
serviceUnitExists := false
188+
fakeServicePids := map[string]uint64{}
189+
184190
// The monitoring config depends on a map from component id to
185191
// binary name.
186192
binaryMapping := make(map[string]string)
187193
for _, component := range components {
188194
if spec := component.InputSpec; spec != nil {
189195
binaryMapping[component.ID] = component.BinaryName()
196+
if spec.Spec.Service != nil {
197+
serviceUnitExists = true
198+
fakeServicePids[component.ID] = 1234
199+
}
190200
}
191201
}
192-
monitorCfg, err := monitorFn(cfg, components, binaryMapping, map[string]uint64{})
202+
monitorCfg, err := monitorFn(cfg, components, binaryMapping, fakeServicePids)
193203
if err != nil {
194204
return fmt.Errorf("failed to get monitoring config: %w", err)
195205
}
196206

197207
if monitorCfg != nil {
208+
209+
// see above comment; because we don't know endpoint's actual PID, we need to make a fake one. Warn the user.
210+
if serviceUnitExists {
211+
keys := make([]string, 0, len(fakeServicePids))
212+
for k := range fakeServicePids {
213+
keys = append(keys, k)
214+
}
215+
fmt.Fprintf(streams.Err, "WARNING: the inspect command can't accurately produce monitoring configs for service units: %v. Use the diagnostics command to get the real config used for monitoring these components\n", keys)
216+
}
217+
198218
rawCfg := config.MustNewConfigFrom(cfg)
199219

200220
if err := rawCfg.Merge(monitorCfg); err != nil {
@@ -205,7 +225,9 @@ func inspectConfig(ctx context.Context, cfgPath string, opts inspectConfigOpts,
205225
if err != nil {
206226
return fmt.Errorf("failed to convert monitoring config: %w", err)
207227
}
228+
208229
}
230+
209231
}
210232

211233
return printMapStringConfig(cfg, streams)

0 commit comments

Comments
 (0)