Skip to content

feat: add inspection name form field and enforce unique inspection names - #1036

Merged
kyasbal merged 3 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-wtqwkrtwtznu
Sep 25, 2026
Merged

kyasbal merged 3 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-wtqwkrtwtznu

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 25, 2026

Copy link
Copy Markdown
Member

Summary

  • Added InputInspectionNameTask at the top of the inspection parameter form (Priority: 200000) so users can specify a custom display name when creating an inspection.
  • Automatically generates sequential default names based on the selected cluster type (e.g., Google Kubernetes Engine, Google Kubernetes Engine(1), Google Kubernetes Engine(2), ...).
  • Added thread-safe InspectionNameRegistry (InMemoryInspectionNameRegistry) to atomically reserve, validate, and resolve unique inspection names across the server:
    • Form Parameter Validation (InputInspectionNameTask): Validates and reserves the inspection name during form evaluation, displaying an error hint if a name is empty or already reserved by another inspection.
    • .khi File Import (RegisterImportedInspection): Automatically resolves and reserves a unique sequential name when an imported .khi file collides with an existing inspection name.
    • Inspection Rename RPC (UpdateInspection): Rejects duplicate names with connect.CodeAlreadyExists and empty names with connect.CodeInvalidArgument, releasing the old name upon rename.
@kyasbal kyasbal added type:feature New feature or request area:backend-core Core backend frameworks, DAG task runner, and server API labels Sep 25, 2026
@kyasbal
kyasbal requested a review from renamoo as a code owner September 25, 2026 01:51
@kyasbal kyasbal added the area:backend-parser Log parsers and log timeline mapper tasks label Sep 25, 2026
@kyasbal
kyasbal requested a review from K53 as a code owner September 25, 2026 01:51

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an InspectionNameRegistry and a corresponding in-memory implementation to manage unique inspection names and prevent collisions across runs, imports, and updates. It also adds a new form task InputInspectionNameTask to allow users to specify custom inspection names. The review feedback suggests updating header.SuggestedFileName alongside header.InspectionName in the form task's converter to ensure consistency, and replacing defensive khictx.GetValue checks with khictx.MustGetValue for the required InspectionNameRegistryKey dependency in both the default value function and the validator.

Comment on lines +71 to +73
if header, found := typedmap.Get(metadataSet, inspectionmetadata.HeaderMetadataKey); found && header != nil {
header.InspectionName = trimmed
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The converter updates header.InspectionName with the trimmed user input, but it does not update header.SuggestedFileName. This means that for any newly run inspection, the suggested file name will remain "unnamed.khi" (its initial default value) even if the user specified a custom inspection name.

Updating header.SuggestedFileName alongside header.InspectionName ensures consistency across the application, matching the behavior in RegisterImportedInspection and UpdateInspection.

Suggested change
if header, found := typedmap.Get(metadataSet, inspectionmetadata.HeaderMetadataKey); found && header != nil {
header.InspectionName = trimmed
}
if header, found := typedmap.Get(metadataSet, inspectionmetadata.HeaderMetadataKey); found && header != nil {
header.InspectionName = trimmed
header.SuggestedFileName = fmt.Sprintf("%s.khi", trimmed)
}
Comment on lines +47 to +50
if registry, err := khictx.GetValue(ctx, inspectioncore.InspectionNameRegistryKey); err == nil && registry != nil {
return registry.ResolveUniqueName(inspectionID, baseName), nil
}
return baseName, nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the repository's general guidelines, we should avoid defensive nil fallbacks and excessive nil checks on required parameters or dependencies. Since InspectionNameRegistryKey is a required dependency for resolving unique inspection names, we should enforce its presence using khictx.MustGetValue instead of a defensive khictx.GetValue check.

registry := khictx.MustGetValue(ctx, inspectioncore.InspectionNameRegistryKey)
		return registry.ResolveUniqueName(inspectionID, baseName), nil
References
  1. For internal Go code where backward compatibility is not required, avoid model pollution and defensive nil fallbacks (such as global fallback stores or optional nil fields). Enforce strict non-nil constraints on dependencies and require callers to supply them explicitly.
Comment on lines +58 to +65
if registry, err := khictx.GetValue(ctx, inspectioncore.InspectionNameRegistryKey); err == nil && registry != nil {
if err := registry.ReserveName(inspectionID, trimmed); err != nil {
if errors.Is(err, inspectioncore.ErrInspectionNameAlreadyInUse) {
return fmt.Sprintf("inspection name %q is already in use", trimmed), nil
}
return err.Error(), nil
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similarly, in the validator, InspectionNameRegistryKey is a required dependency to validate and reserve the inspection name. Silently skipping the reservation if the registry is missing could lead to duplicate names being accepted without any error. Enforce its presence using khictx.MustGetValue.

registry := khictx.MustGetValue(ctx, inspectioncore.InspectionNameRegistryKey)
		if err := registry.ReserveName(inspectionID, trimmed); err != nil {
			if errors.Is(err, inspectioncore.ErrInspectionNameAlreadyInUse) {
				return fmt.Sprintf("inspection name %q is already in use", trimmed), nil
			}
			return err.Error(), nil
		}
References
  1. For internal Go code where backward compatibility is not required, avoid model pollution and defensive nil fallbacks (such as global fallback stores or optional nil fields). Enforce strict non-nil constraints on dependencies and require callers to supply them explicitly.
return "inspection name must not be empty", nil
}
inspectionID := khictx.MustGetValue(ctx, inspectioncore.InspectionTaskInspectionID)
if registry, err := khictx.GetValue(ctx, inspectioncore.InspectionNameRegistryKey); err == nil && registry != nil {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The registry can't be nil. It should use MustGetValue

if err != nil || baseName == "" {
baseName = "Inspection"
}
if registry, err := khictx.GetValue(ctx, inspectioncore.InspectionNameRegistryKey); err == nil && registry != nil {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The registry can't be nil. It should use MustGetValue

@kyasbal
kyasbal added this pull request to the merge queue Sep 25, 2026
Merged via the queue into GoogleCloudPlatform:main with commit aada067 Sep 25, 2026
17 checks passed
@kyasbal
kyasbal deleted the push-wtqwkrtwtznu branch September 25, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend-core Core backend frameworks, DAG task runner, and server API area:backend-parser Log parsers and log timeline mapper tasks type:feature New feature or request

1 participant