Skip to content
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

feat(ids-api): Enable getting fake users in v3 client. Configure for ids-api envs. #17201

Merged
merged 8 commits into from
Dec 13, 2024

Conversation

valurefugl
Copy link
Member

@valurefugl valurefugl commented Dec 11, 2024

What

Add a parameter to the national registry v3 client that indicates that we want to try the gervimenn api if no user found in the main api.

Provide this parameter when client is used in ids-api, based on environment setting (only set in DEV).

Why

The main api on DEV only provides a subset of the Gervimenn we are using.

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new environment variable ALSO_USE_FAKE_USER_API across various configurations (dev, staging, prod).
    • Enhanced API behavior by allowing conditional use of a fake API based on configuration settings.
  • Bug Fixes

    • Improved handling of API calls in the getAllDataIndividual method to ensure proper fallback to the fake API when needed.
  • Chores

    • Adjusted resource limits and scaling configurations for improved performance and reliability across services.

@valurefugl valurefugl requested review from a team as code owners December 11, 2024 13:41
Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

The changes in this pull request introduce a new environment variable ALSO_USE_FAKE_USER_API across multiple configuration files and service implementations. This variable is configured differently for development, staging, and production environments. The ids-api.ts file's serviceSetup function now incorporates this variable, affecting the behavior of the UserProfileService and AliveStatusService classes by allowing conditional usage of a fake API. The NationalRegistryV3ClientService method for data retrieval has also been updated to accommodate these changes.

Changes

File Path Change Summary
apps/services/auth/ids-api/infra/ids-api.ts Added environment variable ALSO_USE_FAKE_USER_API with values for dev, staging, prod.
apps/services/auth/ids-api/src/app/app.module.ts Imported ZendeskServiceConfig and added it to the load array in ConfigModule.forRoot.
apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts Added ConfigService to constructor and property alsoUseFakeApi initialized from config. Updated getClaimsFromNationalRegistry to use alsoUseFakeApi.
charts/identity-server/values.dev.yaml Added ALSO_USE_FAKE_USER_API: 'true' and DB_EXTENSIONS: 'uuid-ossp'. Updated HPA and resource limits.
charts/identity-server/values.prod.yaml Added ALSO_USE_FAKE_USER_API: 'false' and DB_EXTENSIONS: 'uuid-ossp'. Updated HPA and init container.
charts/identity-server/values.staging.yaml Added ALSO_USE_FAKE_USER_API: 'false' and DB_EXTENSIONS: 'uuid-ossp'. Updated HPA and resource limits.
charts/services/services-auth-ids-api/values.dev.yaml Added ALSO_USE_FAKE_USER_API: 'true' in env section.
charts/services/services-auth-ids-api/values.prod.yaml Added ALSO_USE_FAKE_USER_API: 'false' in env section.
charts/services/services-auth-ids-api/values.staging.yaml Added ALSO_USE_FAKE_USER_API: 'false' in env section.
libs/auth-api-lib/src/lib/delegations/alive-status.service.ts Added ConfigService to constructor and property alsoUseFakeApi. Updated getIndividualIdentity method.
libs/clients/national-registry/v3/src/lib/nationalRegistryV3.service.ts Updated getAllDataIndividual method signature and internal logic to include new parameters.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • eirikurn

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00ac57a and 9bdca79.

📒 Files selected for processing (2)
  • apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts (4 hunks)
  • libs/auth-api-lib/src/lib/delegations/alive-status.service.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts
  • libs/auth-api-lib/src/lib/delegations/alive-status.service.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
apps/services/auth/ids-api/src/app/app.module.ts (1)

2-2: LGTM! NestJS configuration setup is correct.

The addition of NestConfigModule with ignoreEnvFile: true is appropriate as the configuration values are managed through Kubernetes environment variables rather than .env files.

Also applies to: 60-62

libs/clients/national-registry/v3/src/lib/nationalRegistryV3.service.ts (1)

42-64: Implementation handles fake API fallback gracefully.

The logic properly separates concerns:

  1. Direct fake API usage when explicitly requested
  2. Real API as primary source
  3. Fallback to fake API when configured and real API returns no results

Consider adding error logging when the real API call fails to help with debugging.

 const result = await handle204(
   this.individualApi.midlunV1EinstaklingarNationalIdGetRaw({
     nationalId,
   }),
- )
+ ).catch(error => {
+   console.error('Real API call failed:', error);
+   return null;
+ });
charts/services/services-auth-ids-api/values.prod.yaml (1)

22-25: Verify the environment variable ordering.

Consider grouping related environment variables together for better maintainability. The ALSO_USE_FAKE_USER_API and DB_EXTENSIONS variables seem to be added without following any specific ordering.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7dce5d8 and 8673255.

📒 Files selected for processing (11)
  • apps/services/auth/ids-api/infra/ids-api.ts (1 hunks)
  • apps/services/auth/ids-api/src/app/app.module.ts (3 hunks)
  • apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts (4 hunks)
  • charts/identity-server/values.dev.yaml (1 hunks)
  • charts/identity-server/values.prod.yaml (1 hunks)
  • charts/identity-server/values.staging.yaml (1 hunks)
  • charts/services/services-auth-ids-api/values.dev.yaml (1 hunks)
  • charts/services/services-auth-ids-api/values.prod.yaml (1 hunks)
  • charts/services/services-auth-ids-api/values.staging.yaml (1 hunks)
  • libs/auth-api-lib/src/lib/delegations/alive-status.service.ts (3 hunks)
  • libs/clients/national-registry/v3/src/lib/nationalRegistryV3.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
apps/services/auth/ids-api/src/app/app.module.ts (2)

Pattern apps/services/**/*: "Confirm that the code adheres to the following:

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/services/auth/ids-api/infra/ids-api.ts (2)

Pattern apps/services/**/*: "Confirm that the code adheres to the following:

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts (2)

Pattern apps/services/**/*: "Confirm that the code adheres to the following:

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
libs/clients/national-registry/v3/src/lib/nationalRegistryV3.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/auth-api-lib/src/lib/delegations/alive-status.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (16)
libs/clients/national-registry/v3/src/lib/nationalRegistryV3.service.ts (1)

37-41: Method signature change improves flexibility and clarity.

The renamed parameter useFakeApiOnly and new parameter alsoTryFakeApiWhenNotFound make the behavior more explicit and provide better control over fake API usage.

charts/services/services-auth-ids-api/values.prod.yaml (1)

22-22: Production configuration correctly disables fake user API.

Setting ALSO_USE_FAKE_USER_API: 'false' in production is essential for security. This aligns with the PR objective of only using fake users in development.

✅ Verification successful

Fake user API configuration is correctly set across environments

The verification confirms that:

  • Development environment has ALSO_USE_FAKE_USER_API: 'true'
  • Both staging and production environments have ALSO_USE_FAKE_USER_API: 'false'

This configuration aligns with security best practices by ensuring fake users are only available in development, while staging and production use real authentication.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify fake API configuration across environments
echo "Checking fake API configuration in all environment files..."
rg "ALSO_USE_FAKE_USER_API" charts/services/services-auth-ids-api/values.*.yaml

Length of output: 591

charts/services/services-auth-ids-api/values.dev.yaml (1)

22-22: LGTM! Configuration aligns with PR objectives.

The addition of ALSO_USE_FAKE_USER_API: 'true' in the development environment is appropriate and matches the PR's goal of enabling fake user data retrieval for testing purposes.

Let's verify configuration consistency across environments:

✅ Verification successful

Configuration is properly set across environments

The verification confirms that ALSO_USE_FAKE_USER_API is correctly configured:

  • Set to 'true' in development environments
  • Set to 'false' in production and staging environments

This aligns with the PR's objective of enabling fake user data only in development environments while keeping it disabled in production and staging.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ALSO_USE_FAKE_USER_API configuration across environments
# Expected: 'true' in dev, 'false' in staging/prod

echo "Checking ALSO_USE_FAKE_USER_API configuration across environments..."
rg "ALSO_USE_FAKE_USER_API:" "charts/services/services-auth-ids-api/values*.yaml"

Length of output: 319


Script:

#!/bin/bash
# Let's first find the correct path to the values files
fd "values.*\.yaml" charts

# Then check for the configuration across all found files
echo -e "\nChecking ALSO_USE_FAKE_USER_API configuration in found files:"
fd "values.*\.yaml" charts --exec rg "ALSO_USE_FAKE_USER_API:" {}

Length of output: 9678

charts/services/services-auth-ids-api/values.staging.yaml (1)

22-22: LGTM! Appropriate configuration for staging environment.

Setting ALSO_USE_FAKE_USER_API: 'false' in staging is correct as fake user data should only be available in development.

apps/services/auth/ids-api/infra/ids-api.ts (1)

103-107: LGTM! Environment configuration is well-structured.

The implementation follows the established pattern for environment-specific variables and correctly configures the feature for development only.

Let's verify the implementation consistency:

✅ Verification successful

Configuration is properly implemented and used consistently

The verification confirms that the ALSO_USE_FAKE_USER_API configuration is correctly implemented and used in both services:

  • In AliveStatusService, it's used to control fake API usage for national registry lookups
  • In UserProfileService, it's properly injected and used for user profile operations

The environment-specific configuration follows the established pattern:

  • Enabled in dev environment ('true')
  • Disabled in staging and production environments ('false')
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the feature implementation in the codebase
# Expected: ConfigService usage for ALSO_USE_FAKE_USER_API

# Check for ConfigService injection and usage
ast-grep --pattern 'constructor($$$, private readonly configService: ConfigService$$$) {
  $$$
}'

# Check for configuration usage
rg "configService.get.*ALSO_USE_FAKE_USER_API"

Length of output: 422


Script:

#!/bin/bash
# Let's check the implementation details of the services using this configuration

# Check alive-status.service.ts implementation
ast-grep --pattern 'class AliveStatusService {
  $$$
}'

# Check user-profile.service.ts implementation
ast-grep --pattern 'class UserProfileService {
  $$$
}'

Length of output: 71146

libs/auth-api-lib/src/lib/delegations/alive-status.service.ts (2)

24-39: LGTM! Safe initialization of fake API feature flag.

The implementation follows best practices:

  • Default false state ensures security by default
  • Optional dependency injection maintains backward compatibility
  • Configuration-based toggle enables environment-specific control

147-151: LGTM! Proper propagation of fake API feature flag.

The feature flag is correctly passed to the national registry client, enabling conditional fake user retrieval.

apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts (2)

Line range hint 34-57: LGTM! Consistent implementation of fake API feature flag.

The implementation mirrors AliveStatusService, maintaining consistency across the codebase:

  • Default false state for security
  • Optional configuration injection
  • Safe initialization pattern

135-135: LGTM! Consistent usage of fake API feature flag.

The feature flag is properly propagated to the national registry client, maintaining consistency with AliveStatusService.

charts/identity-server/values.prod.yaml (2)

414-414: LGTM! Fake users properly disabled in production.

The configuration explicitly disables fake users in production, which is the correct security posture.


Line range hint 414-419: Verify the impact of unrelated configuration changes.

Several configuration changes appear unrelated to the fake users feature:

  • Addition of DB_EXTENSIONS
  • Changes to HPA configuration

Please confirm these changes are intentional and have been properly tested.

✅ Verification successful

Let me verify the specific configuration changes by checking their consistency across environments.


Let me check the HPA configuration using a different approach.


Configuration changes appear consistent and intentional

Based on the verification results:

  • The DB_EXTENSIONS: 'uuid-ossp' configuration is consistently set across all environments (dev, staging, prod) in the identity-server charts
  • The HPA configuration mentioned in the review comment couldn't be found in the current state of the files, suggesting it might have been removed or the change was reverted
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for related configuration changes in other environments
echo "Checking for DB_EXTENSIONS in other environment files..."
fd -e yaml -e yml . | xargs grep -l "DB_EXTENSIONS"

echo "Checking for HPA changes in other environment files..."
fd -e yaml -e yml . | xargs grep -l "max: 15"

Length of output: 1196


Script:

#!/bin/bash
# Check the actual values of DB_EXTENSIONS across environments
echo "DB_EXTENSIONS values in identity-server:"
echo "DEV:"
grep -A 1 "DB_EXTENSIONS" charts/identity-server/values.dev.yaml
echo "STAGING:"
grep -A 1 "DB_EXTENSIONS" charts/identity-server/values.staging.yaml
echo "PROD:"
grep -A 1 "DB_EXTENSIONS" charts/identity-server/values.prod.yaml

# Check HPA configuration across environments
echo -e "\nHPA configuration in identity-server:"
echo "DEV:"
grep -A 5 "horizontalPodAutoscaler:" charts/identity-server/values.dev.yaml
echo "STAGING:"
grep -A 5 "horizontalPodAutoscaler:" charts/identity-server/values.staging.yaml
echo "PROD:"
grep -A 5 "horizontalPodAutoscaler:" charts/identity-server/values.prod.yaml

Length of output: 1201


Script:

#!/bin/bash
# Search for HPA-related configuration in identity-server values files
echo "Searching for HPA configuration in identity-server:"
echo "DEV:"
rg -A 5 "maxReplicas|minReplicas" charts/identity-server/values.dev.yaml
echo -e "\nSTAGING:"
rg -A 5 "maxReplicas|minReplicas" charts/identity-server/values.staging.yaml
echo -e "\nPROD:"
rg -A 5 "maxReplicas|minReplicas" charts/identity-server/values.prod.yaml

Length of output: 419

charts/identity-server/values.dev.yaml (3)

417-417: LGTM: Environment variable correctly configured for development

The addition of ALSO_USE_FAKE_USER_API: 'true' aligns with the PR objective to enable fake user retrieval in the development environment.


417-417: Verify resource allocation increases

The significant increases in resource allocations (max replicas: 15, CPU: 800m, memory: 768Mi) should be justified by load testing or metrics.

✅ Verification successful

Resource increases appear justified for fake user API integration

The resource allocation increases are aligned with the codebase changes:

  • The ALSO_USE_FAKE_USER_API: 'true' flag is enabled, requiring additional resources for handling fake user data
  • Infrastructure code shows deliberate resource configuration:
    • CPU increased from 400m to 800m
    • Memory increased from 512Mi to 768Mi
    • Max replicas increased to handle higher load

The changes appear to be intentionally configured in the infrastructure code rather than arbitrary increases.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for performance-related changes that might justify resource increases

# Search for performance-related code changes
rg -l 'performance|optimization|cache' apps/services/auth/ids-api/

# Look for load testing configurations
fd -e yaml -e json --exec rg -l 'load.*test|performance.*test' {}

Length of output: 314


Script:

#!/bin/bash
# Let's examine the content of the files that showed performance-related matches
rg -A 5 'performance|optimization|cache' apps/services/auth/ids-api/esbuild.json apps/services/auth/ids-api/project.json apps/services/auth/ids-api/infra/ids-api.ts apps/services/auth/ids-api/infra/identity-server.ts

# Check the current and previous resource configurations
cat charts/identity-server/values.dev.yaml

# Look for any recent changes in the infrastructure code
rg -A 5 'resources|replicas|memory|cpu' apps/services/auth/ids-api/infra/

Length of output: 40011


417-417: Verify database migration handling of uuid-ossp extension

The addition of DB_EXTENSIONS: 'uuid-ossp' requires verification that database migrations properly handle this dependency.

✅ Verification successful

Database extension dependency is properly handled

The migration file 20230322150959-add-uuid-ossp-extension.js correctly manages the uuid-ossp extension with proper up/down migrations, ensuring the extension is created when needed and can be safely removed if required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if database migrations handle uuid-ossp extension

# Search for uuid-ossp related migrations
fd -e js -e ts --exec rg -l 'uuid-ossp|CREATE EXTENSION' {} migrations/

Length of output: 65705


Script:

#!/bin/bash
# Check the content of the migration file that adds uuid-ossp extension
cat ./libs/auth-api-lib/migrations/20230322150959-add-uuid-ossp-extension.js

Length of output: 376

charts/identity-server/values.staging.yaml (2)

417-417: LGTM: Staging environment correctly configured

The staging configuration appropriately disables fake user API (ALSO_USE_FAKE_USER_API: 'false') while maintaining consistent resource allocations with the development environment.


417-417: Verify security controls for fake user access

Ensure that the feature toggle for fake users is properly restricted to development environment only.

✅ Verification successful

Security controls for fake user access are properly configured

The feature toggle ALSO_USE_FAKE_USER_API is correctly configured across all environments:

  • Development environments have it set to 'true'
  • Both staging and production environments have it set to 'false'
  • This configuration is consistently applied in both identity-server and services-auth-ids-api deployments
  • The implementation safely defaults to 'false' when the configuration is missing
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify security controls for fake user feature

# Check for any hardcoded feature flags or environment checks
rg -A 5 'ALSO_USE_FAKE_USER_API|fake.*user|development.*only' apps/services/auth/ids-api/

# Look for environment-specific configurations
fd -e yaml -e json --exec rg -l 'ALSO_USE_FAKE_USER_API' {}

Length of output: 1463


Script:

#!/bin/bash
# Let's verify the values in all environment configurations to ensure consistent security controls

# Check the values in identity-server configurations
echo "=== Identity Server Configurations ==="
echo "DEV environment:"
rg "ALSO_USE_FAKE_USER_API" ./charts/identity-server/values.dev.yaml -C 1

echo -e "\nSTAGING environment:"
rg "ALSO_USE_FAKE_USER_API" ./charts/identity-server/values.staging.yaml -C 1

echo -e "\nPROD environment:"
rg "ALSO_USE_FAKE_USER_API" ./charts/identity-server/values.prod.yaml -C 1

# Check the values in services-auth-ids-api configurations
echo -e "\n=== Services Auth IDS API Configurations ==="
echo "DEV environment:"
rg "ALSO_USE_FAKE_USER_API" ./charts/services/services-auth-ids-api/values.dev.yaml -C 1

echo -e "\nSTAGING environment:"
rg "ALSO_USE_FAKE_USER_API" ./charts/services/services-auth-ids-api/values.staging.yaml -C 1

echo -e "\nPROD environment:"
rg "ALSO_USE_FAKE_USER_API" ./charts/services/services-auth-ids-api/values.prod.yaml -C 1

# Check the implementation to see how this flag is used
echo -e "\n=== Implementation Usage ==="
rg "ALSO_USE_FAKE_USER_API" apps/services/auth/ids-api/src/ -C 3

Length of output: 2162

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 77.77778% with 4 lines in your changes missing coverage. Please review.

Project coverage is 35.75%. Comparing base (c4977d1) to head (133e11c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...-registry/v3/src/lib/nationalRegistryV3.service.ts 42.85% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17201   +/-   ##
=======================================
  Coverage   35.74%   35.75%           
=======================================
  Files        6935     6935           
  Lines      148102   148113   +11     
  Branches    42229    42233    +4     
=======================================
+ Hits        52946    52953    +7     
- Misses      95156    95160    +4     
Flag Coverage Δ
api 3.33% <ø> (ø)
api-domains-auth-admin 48.49% <ø> (ø)
api-domains-education 31.17% <0.00%> (-0.05%) ⬇️
application-system-api 38.74% <0.00%> (-0.02%) ⬇️
application-template-api-modules 27.82% <ø> (+<0.01%) ⬆️
application-ui-shell 22.50% <ø> (ø)
services-auth-admin-api 52.55% <41.66%> (+<0.01%) ⬆️
services-auth-delegation-api 58.53% <66.66%> (-0.01%) ⬇️
services-auth-ids-api 52.55% <61.11%> (+0.01%) ⬆️
services-auth-public-api 49.40% <41.66%> (+<0.01%) ⬆️
services-user-notification 46.52% <0.00%> (-0.02%) ⬇️
services-user-profile 56.94% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
apps/services/auth/ids-api/src/app/app.module.ts 100.00% <100.00%> (ø)
...s-api/src/app/user-profile/user-profile.service.ts 93.15% <100.00%> (-0.52%) ⬇️
...pi-lib/src/lib/delegations/alive-status.service.ts 92.59% <100.00%> (+0.38%) ⬆️
...-registry/v3/src/lib/nationalRegistryV3.service.ts 28.57% <42.85%> (-2.68%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4977d1...133e11c. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Dec 11, 2024

Datadog Report

All test runs 2de58d4 🔗

18 Total Test Services: 0 Failed, 14 Passed
🔻 Test Sessions change in coverage: 4 decreased, 1 increased (+0.01%), 36 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.5s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 10.15s 1 no change Link
api-domains-education 0 0 0 8 0 18.26s 1 decreased (-0.06%) Link
application-system-api 0 0 0 46 0 2m 18.25s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 7.71s 1 no change Link
application-templates-public-debt-payment-plan 0 0 0 3 0 9.27s 1 no change Link
application-ui-shell 0 0 0 74 0 30.96s 1 no change Link
auth-api-lib 0 0 0 20 0 28.46s 1 no change Link
download-service 0 0 0 0 0 535.8ms 1 no change Link
services-auth-admin-api 0 0 0 130 0 3m 31.8s 1 decreased (-0.01%) Link

🔻 Code Coverage Decreases vs Default Branch (4)

  • api-domains-education - jest 31.02% (-0.06%) - Details
  • services-user-profile - jest 49.27% (-0.05%) - Details
  • services-user-notification - jest 68.92% (-0.02%) - Details
  • services-auth-admin-api - jest 46.91% (-0.01%) - Details

Copy link
Member

@thorkellmani thorkellmani left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 612f9ad and 00ac57a.

📒 Files selected for processing (2)
  • apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts (3 hunks)
  • libs/auth-api-lib/src/lib/delegations/alive-status.service.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/auth-api-lib/src/lib/delegations/alive-status.service.ts
🧰 Additional context used
📓 Path-based instructions (1)
apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts (2)

Pattern apps/services/**/*: "Confirm that the code adheres to the following:

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (2)
apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts (2)

1-1: Implementation follows NestJS best practices.

The service implementation adheres to NestJS architecture guidelines:

  • Proper use of dependency injection and decorators
  • Clear separation of concerns
  • Appropriate error handling
  • Good service encapsulation

133-133: Verify error handling for fake API responses.

The alsoUseFakeApi parameter is being passed to getAllDataIndividual, but we should ensure proper error handling for fake API responses, especially since this is behind a feature flag.

Let's verify the error handling implementation in the National Registry V3 client:

✅ Verification successful

Let me gather more information about the error handling implementation.


Let me check the handle204 middleware implementation to complete the verification.


Error handling for fake API responses is properly implemented

The implementation shows a robust error handling approach:

  • The handle204 middleware properly handles both successful responses and errors for both real and fake API calls
  • The fake API fallback is controlled by the ALSO_USE_FAKE_USER_API feature flag which is disabled in staging/prod
  • The service gracefully handles "not found" scenarios by attempting the fake API when alsoTryFakeApiWhenNotFound is true
  • Null responses are properly handled when no data is found from either API
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check error handling in National Registry V3 client for fake API responses

# Search for error handling in the National Registry V3 client
ast-grep --pattern 'catch ($_) {
  $$$
}'

# Search for fake API related error handling
rg -A 5 'alsoTryFakeApiWhenNotFound|ALSO_USE_FAKE_USER_API'

Length of output: 6671


Script:

#!/bin/bash
# Search for handle204 function implementation and related error handling
rg -A 10 "handle204" libs/clients/national-registry/v3/src/lib/

# Search for error handling in the fake API implementation
ast-grep --pattern 'try {
  $$$
  this.fakeApi.$$$
  $$$
} catch ($_) {
  $$$
}'

Length of output: 12434


Script:

#!/bin/bash
# Search for handle204 middleware implementation
rg -A 10 "export.*handle204" libs/clients/middlewares/

# Search for error handling in the middleware
ast-grep --pattern 'catch ($_) {
  $$$
}' libs/clients/middlewares/

Length of output: 972

Copy link
Member

@robertaandersen robertaandersen left a comment

Choose a reason for hiding this comment

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

LGTM

@valurefugl valurefugl added the automerge Merge this PR as soon as all checks pass label Dec 12, 2024
@valurefugl valurefugl added automerge Merge this PR as soon as all checks pass and removed automerge Merge this PR as soon as all checks pass labels Dec 13, 2024
@kodiakhq kodiakhq bot merged commit 3719969 into main Dec 13, 2024
72 checks passed
@kodiakhq kodiakhq bot deleted the auth-api/also-fake-api branch December 13, 2024 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants