├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md ├── copilot-instructions.md ├── dependabot.yml └── workflows │ ├── ci.yml │ ├── openapi-pr.yml │ ├── openapi.yml │ └── service.yml ├── .gitignore ├── .golangci-strict.yml ├── .golangci.yml ├── .redocly.yaml ├── .yamllint.yml ├── CONTRIBUTING.md ├── Dockerfile ├── Jenkinsfile ├── LICENSE ├── Makefile ├── README.md ├── auth ├── auth.go ├── auth_test.go ├── auth_time_sensitive_test.go ├── collection_access.go ├── collection_access_test.go ├── cors.go ├── jwt.go ├── jwt_test.go ├── jwt_test_utils.go ├── main_test.go ├── oidc.go ├── oidc_test.go ├── oidc_verify.go ├── password_hash.go ├── password_hash_test.go ├── principal.go ├── role.go ├── role_collection_access.go ├── role_test.go ├── session.go ├── session_test.go ├── user.go ├── user_collection_access.go └── user_test.go ├── base ├── audit_events.go ├── audit_events_fields.go ├── audit_events_test.go ├── audit_types.go ├── auditd_descriptor.go ├── auditd_descriptor_test.go ├── auditd_types.go ├── bootstrap.go ├── bootstrap_test.go ├── bucket.go ├── bucket_gocb.go ├── bucket_gocb_test.go ├── bucket_n1ql.go ├── bucket_n1ql_test.go ├── bucket_test.go ├── bucket_view_test.go ├── cbgt.go ├── cluster_n1ql.go ├── collection.go ├── collection_common.go ├── collection_gocb.go ├── collection_gocb_utils.go ├── collection_n1ql.go ├── collection_n1ql_common.go ├── collection_view.go ├── collection_xattr.go ├── collection_xattr_common.go ├── collection_xattr_test.go ├── config_persistence.go ├── config_persistence_test.go ├── constants.go ├── constants_ce.go ├── constants_ee.go ├── constants_syncdocs.go ├── constants_syncdocs_test.go ├── dcp_client.go ├── dcp_client_metadata.go ├── dcp_client_stream_event.go ├── dcp_client_stream_observer.go ├── dcp_client_test.go ├── dcp_client_worker.go ├── dcp_common.go ├── dcp_common_test.go ├── dcp_dest.go ├── dcp_feed_type.go ├── dcp_receiver.go ├── dcp_sharded.go ├── dcp_sharded_test.go ├── dcp_test.go ├── devmode.go ├── devmode_off.go ├── devmode_on.go ├── error.go ├── error_test.go ├── git_info.go ├── gocb_connection_string.go ├── gocb_connection_string_test.go ├── gocb_dcp_feed.go ├── gocb_utils.go ├── gocb_utils_test.go ├── heartbeat.go ├── heartbeat_test.go ├── http_listener.go ├── leaky_bucket.go ├── leaky_datastore.go ├── log_keys.go ├── log_keys_test.go ├── log_level.go ├── log_level_test.go ├── logger.go ├── logger_audit.go ├── logger_audit_test.go ├── logger_console.go ├── logger_console_test.go ├── logger_external.go ├── logger_external_test.go ├── logger_file.go ├── logger_file_test.go ├── logging.go ├── logging_config.go ├── logging_config_test.go ├── logging_context.go ├── logging_context_test.go ├── logging_test.go ├── lru_cache.go ├── lru_cache_test.go ├── main_test.go ├── main_test_bucket_pool.go ├── main_test_bucket_pool_config.go ├── main_test_bucket_pool_stats.go ├── main_test_bucket_pool_util.go ├── main_test_cluster.go ├── main_test_util.go ├── redactable_error.go ├── redactable_error_test.go ├── redactable_string.go ├── redactor.go ├── redactor_metadata.go ├── redactor_metadata_test.go ├── redactor_systemdata.go ├── redactor_systemdata_test.go ├── redactor_test.go ├── redactor_userdata.go ├── redactor_userdata_test.go ├── rlimit.go ├── rlimit_test.go ├── rlimit_windows.go ├── rosmar_cluster.go ├── set.go ├── set_test.go ├── sg_cluster_cfg.go ├── stats.go ├── stats_descriptions.go ├── stats_test.go ├── user_agent.go ├── util.go ├── util_ce.go ├── util_ee.go ├── util_logging_mutex.go ├── util_logging_mutex_test.go ├── util_test.go ├── util_test_norace.go ├── util_test_race.go ├── util_testing.go ├── version.go ├── version_comparable_build.go ├── version_comparable_build_test.go ├── version_test.go └── views.go ├── bench.sh ├── bootstrap.sh ├── build.sh ├── build ├── README.Debian.tmpl ├── README.txt ├── changelog.tmpl ├── compat.tmpl ├── control.tmpl ├── copyright.tmpl ├── manifest.txt.tmpl ├── manifest.xml.tmpl ├── package-deb.rb ├── package-mac.rb ├── package-rpm.rb ├── package-win.rb ├── postinst.tmpl ├── postrm.tmpl ├── preinst.tmpl ├── prerm.tmpl ├── rpm.spec.tmpl ├── rules.tmpl ├── watch.tmpl └── windows │ ├── InstallShield_2014_Projects │ └── sync-gateway.ism │ ├── couchbase.ico │ └── wix_installer │ ├── Config.wxi │ ├── assets │ ├── cb_installer_banner.jpg │ ├── cb_installer_bg.jpg │ └── couchbase.ico │ ├── create-installer.bat │ ├── sync-gateway.wxs │ └── wix-exclude.xlst ├── channels ├── active_channels.go ├── active_channels_test.go ├── channelmapper.go ├── channelmapper_test.go ├── log_entry.go ├── main_test.go ├── range_safe_collection.go ├── range_safe_collection_test.go ├── set.go ├── set_test.go ├── sync_runner.go ├── sync_runner_test.go ├── timed_set.go ├── timed_set_test.go └── util_testing.go ├── db ├── access_test.go ├── active_replicator.go ├── active_replicator_checkpointer.go ├── active_replicator_checkpointer_test.go ├── active_replicator_common.go ├── active_replicator_common_collections.go ├── active_replicator_config.go ├── active_replicator_pull.go ├── active_replicator_pull_collections.go ├── active_replicator_push.go ├── active_replicator_push_collections.go ├── active_replicator_test.go ├── attachment.go ├── attachment_compaction.go ├── attachment_compaction_test.go ├── attachment_test.go ├── background_mgr.go ├── background_mgr_async_index_init.go ├── background_mgr_attachment_compaction.go ├── background_mgr_resync_dcp.go ├── background_mgr_resync_dcp_test.go ├── background_mgr_tombstone_compaction.go ├── blip.go ├── blip_collection_context.go ├── blip_connected_client.go ├── blip_handler.go ├── blip_handler_collections.go ├── blip_handler_collections_test.go ├── blip_handler_test.go ├── blip_messages.go ├── blip_messages_utils.go ├── blip_subprotocol.go ├── blip_sync_context.go ├── blip_sync_context_test.go ├── blip_sync_messages.go ├── blip_sync_stats.go ├── blip_test.go ├── change_cache.go ├── change_cache_test.go ├── change_listener.go ├── change_listener_test.go ├── changes.go ├── changes_test.go ├── changes_view.go ├── channel_cache.go ├── channel_cache_single.go ├── channel_cache_single_test.go ├── channel_cache_test.go ├── crud.go ├── crud_test.go ├── data_for_test.go ├── database.go ├── database_collection.go ├── database_error.go ├── database_stats.go ├── database_test.go ├── dcp_sharded_upgrade_test.go ├── design_doc.go ├── design_doc_test.go ├── design_doc_util_test.go ├── document.go ├── document_test.go ├── event.go ├── event_handler.go ├── event_handler_test.go ├── event_manager.go ├── event_manager_test.go ├── event_test.go ├── functions.go ├── functions │ ├── function.go │ ├── function_test.go │ ├── js_callbacks.go │ ├── js_function.go │ ├── js_runner.go │ ├── js_wrapper.js │ ├── main_test.go │ ├── n1ql_function.go │ └── n1ql_function_test.go ├── hybrid_logical_vector.go ├── hybrid_logical_vector_test.go ├── import.go ├── import_listener.go ├── import_pindex.go ├── import_test.go ├── indexes.go ├── indexes_test.go ├── indextest │ ├── indextest_test.go │ ├── main_test.go │ ├── post_upgrade_test.go │ └── util.go ├── main_test.go ├── query.go ├── query_test.go ├── repair_bucket.go ├── repair_bucket_test.go ├── revision.go ├── revision_cache_bypass.go ├── revision_cache_interface.go ├── revision_cache_lru.go ├── revision_cache_test.go ├── revision_test.go ├── revtree.go ├── revtree_data_test.go ├── revtree_test.go ├── sequence_allocator.go ├── sequence_allocator_test.go ├── sequence_id.go ├── sequence_id_test.go ├── sg_replicate_cfg.go ├── sg_replicate_cfg_test.go ├── sg_replicate_conflict_resolver.go ├── sg_replicate_conflict_resolver_test.go ├── sg_replicate_util.go ├── skipped_sequence.go ├── skipped_sequence_test.go ├── special_docs.go ├── users.go ├── util_testing.go ├── utils.go └── validation.go ├── docs ├── BUILD.md ├── BUILD_EXTRA.md ├── antora.yml ├── api │ ├── README.md │ ├── admin-capella.yaml │ ├── admin.yaml │ ├── components │ │ ├── parameters.yaml │ │ ├── requestBodies.yaml │ │ ├── responses.yaml │ │ └── schemas.yaml │ ├── diagnostic.yaml │ ├── metric-capella.yaml │ ├── metric.yaml │ ├── paths │ │ ├── admin │ │ │ ├── -.yaml │ │ │ ├── _all_dbs.yaml │ │ │ ├── _config.yaml │ │ │ ├── _debug-fgprof.yaml │ │ │ ├── _debug-pprof-block.yaml │ │ │ ├── _debug-pprof-cmdline.yaml │ │ │ ├── _debug-pprof-goroutine.yaml │ │ │ ├── _debug-pprof-heap.yaml │ │ │ ├── _debug-pprof-mutex.yaml │ │ │ ├── _debug-pprof-profile.yaml │ │ │ ├── _debug-pprof-symbol.yaml │ │ │ ├── _debug-pprof-threadcreate.yaml │ │ │ ├── _debug-pprof-trace.yaml │ │ │ ├── _expvar.yaml │ │ │ ├── _heap.yaml │ │ │ ├── _logging.yaml │ │ │ ├── _post_upgrade.yaml │ │ │ ├── _profile-profilename.yaml │ │ │ ├── _profile.yaml │ │ │ ├── _sgcollect_info.yaml │ │ │ ├── _stats.yaml │ │ │ ├── _status.yaml │ │ │ ├── db-.yaml │ │ │ ├── db-_blipsync.yaml │ │ │ ├── db-_compact.yaml │ │ │ ├── db-_config-audit.yaml │ │ │ ├── db-_config.yaml │ │ │ ├── db-_design-ddoc-_view-view.yaml │ │ │ ├── db-_design-ddoc.yaml │ │ │ ├── db-_dump-view.yaml │ │ │ ├── db-_facebook.yaml │ │ │ ├── db-_flush.yaml │ │ │ ├── db-_google.yaml │ │ │ ├── db-_index_init.yaml │ │ │ ├── db-_offline.yaml │ │ │ ├── db-_oidc.yaml │ │ │ ├── db-_oidc_callback.yaml │ │ │ ├── db-_oidc_challenge.yaml │ │ │ ├── db-_oidc_refresh.yaml │ │ │ ├── db-_online.yaml │ │ │ ├── db-_repair.yaml │ │ │ ├── db-_replication-.yaml │ │ │ ├── db-_replication-replicationid.yaml │ │ │ ├── db-_replicationStatus-.yaml │ │ │ ├── db-_replicationStatus-replicationid.yaml │ │ │ ├── db-_resync.yaml │ │ │ ├── db-_role-.yaml │ │ │ ├── db-_role-name.yaml │ │ │ ├── db-_session-sessionid.yaml │ │ │ ├── db-_session.yaml │ │ │ ├── db-_user-.yaml │ │ │ ├── db-_user-name-_session-sessionid.yaml │ │ │ ├── db-_user-name-_session.yaml │ │ │ ├── db-_user-name.yaml │ │ │ ├── db-_view-view.yaml │ │ │ ├── keyspace-.yaml │ │ │ ├── keyspace-_all_docs.yaml │ │ │ ├── keyspace-_bulk_docs.yaml │ │ │ ├── keyspace-_bulk_get.yaml │ │ │ ├── keyspace-_changes.yaml │ │ │ ├── keyspace-_config-import_filter.yaml │ │ │ ├── keyspace-_config-sync.yaml │ │ │ ├── keyspace-_dumpchannel-channel.yaml │ │ │ ├── keyspace-_local-docid.yaml │ │ │ ├── keyspace-_purge.yaml │ │ │ ├── keyspace-_raw-docid.yaml │ │ │ ├── keyspace-_revs_diff.yaml │ │ │ ├── keyspace-_revtree-docid.yaml │ │ │ ├── keyspace-docid-attach.yaml │ │ │ └── keyspace-docid.yaml │ │ ├── common │ │ │ ├── _ping.yaml │ │ │ ├── db-_ensure_full_commit.yaml │ │ │ ├── db-_oidc_testing-.well-known-openid-configuration.yaml │ │ │ ├── db-_oidc_testing-authenticate.yaml │ │ │ ├── db-_oidc_testing-authorize.yaml │ │ │ ├── db-_oidc_testing-certs.yaml │ │ │ └── db-_oidc_testing-token.yaml │ │ ├── diagnostic │ │ │ ├── db-_user-name-_all_channels.yaml │ │ │ ├── keyspace-_user-name.yaml │ │ │ ├── keyspace-docid-_all_channels.yaml │ │ │ ├── keyspace-import_filter.yaml │ │ │ └── keyspace-sync.yaml │ │ ├── metric │ │ │ ├── _expvar.yaml │ │ │ └── metrics.yaml │ │ └── public │ │ │ ├── -.yaml │ │ │ ├── db-.yaml │ │ │ ├── db-_blipsync.yaml │ │ │ ├── db-_design-ddoc-_view-view.yaml │ │ │ ├── db-_design-ddoc.yaml │ │ │ ├── db-_facebook.yaml │ │ │ ├── db-_google.yaml │ │ │ ├── db-_oidc.yaml │ │ │ ├── db-_oidc_callback.yaml │ │ │ ├── db-_oidc_challenge.yaml │ │ │ ├── db-_oidc_refresh.yaml │ │ │ ├── db-_session.yaml │ │ │ ├── keyspace-.yaml │ │ │ ├── keyspace-_all_docs.yaml │ │ │ ├── keyspace-_bulk_docs.yaml │ │ │ ├── keyspace-_bulk_get.yaml │ │ │ ├── keyspace-_changes.yaml │ │ │ ├── keyspace-_local-docid.yaml │ │ │ ├── keyspace-_revs_diff.yaml │ │ │ ├── keyspace-docid-attach.yaml │ │ │ ├── keyspace-docid.yaml │ │ │ └── targetdb-.yaml │ ├── plugins │ │ ├── decorators │ │ │ ├── excise-rbac-capella.js │ │ │ ├── replace-description-capella.js │ │ │ └── replace-server-capella.js │ │ ├── plugin.js │ │ ├── rules.js │ │ └── rules │ │ │ ├── check-additional-properties-names.js │ │ │ └── typecheck-defaults.js │ ├── public.yaml │ └── replace-servers-capella.js ├── design │ ├── cache │ │ ├── README.md │ │ ├── cache_overview.md │ │ ├── front_end_cache_writes.md │ │ ├── multi-writer.md │ │ ├── multi_writer_dcp.png │ │ ├── multi_writer_projector.png │ │ ├── single_writer.md │ │ ├── single_writer.png │ │ └── timestamp_sequence.md │ └── channel_index │ │ ├── clock_handling.md │ │ ├── feed_management.md │ │ ├── index_reads.md │ │ ├── index_storage.md │ │ ├── index_writes.md │ │ ├── overview.md │ │ └── sequence_handling.md └── modules │ └── ROOT │ ├── _attributes.adoc │ ├── assets │ └── images │ │ ├── admin-ui-getting-started.png │ │ └── windows-installation-complete.png │ └── pages │ ├── _attributes.adoc │ └── installation.adoc ├── examples ├── README.md ├── database_config │ ├── collections-with-custom-scope.json │ ├── collections-with-default-collection.json │ ├── ee-basic-delta-sync.json │ ├── ee-cache-config.json │ ├── events-webhook.json │ ├── import-filter.json │ ├── openid-connect.json │ └── sync-function.json ├── grafana │ ├── README.md │ ├── dashboard.json │ ├── install_grafana.sh │ └── makefile ├── legacy_config │ ├── basic-couchbase-bucket.json │ ├── basic-sync-function.json │ ├── config-server.json │ ├── config-shared-bucket-filter.json │ ├── config-shared-bucket.json │ ├── cors.json │ ├── democlusterconfig.json │ ├── ee-cache-config.json │ ├── ee_basic-delta-sync.json │ ├── events_webhook.json │ ├── logging-with-redaction.json │ ├── logging-with-rotation.json │ ├── openid-connect.json │ ├── read-write-timeouts.json │ ├── replications-in-config.json │ ├── ssl.json │ └── users-roles.json ├── prometheus │ ├── README.md │ ├── prometheus.yml │ └── rules │ │ └── sync-gateway.rules.yml ├── serviceconfig.json ├── ssl │ ├── README.md │ ├── cert.cer │ ├── cert.pem │ ├── privkey.pem │ └── ssl.json └── startup_config │ ├── basic.json │ ├── cors.json │ ├── logging-with-rotation.json │ ├── logging-without-redaction.json │ └── x509.json ├── go.mod ├── go.sum ├── integration-test ├── docker-compose.yml ├── service-install-tests.sh ├── service-test.sh └── start_server.sh ├── jenkins-integration-build.sh ├── licenses ├── APL2.txt ├── BSL-Couchbase.txt └── addlicense.tmpl ├── main.go ├── manifest ├── 1.3.1.xml ├── 1.4.0.xml ├── 1.4.1.xml ├── 1.5.0.xml ├── 1.5.1.xml ├── 1.5.2.xml ├── 2.0.0.xml ├── 2.1.0.xml ├── 2.1.1.xml ├── 2.1.xml ├── 2.1 │ ├── 2.1.2.1.xml │ ├── 2.1.2.xml │ └── 2.1.3.xml ├── 2.5.xml ├── 2.5 │ ├── 2.5.0.xml │ └── 2.5.1.xml ├── 2.6.xml ├── 2.6 │ ├── 2.6.0.xml │ └── 2.6.1.xml ├── 2.7.xml ├── 2.7 │ ├── 2.7.0.xml │ ├── 2.7.1.xml │ ├── 2.7.2.xml │ └── 2.7.3.xml ├── 2.8.xml ├── 2.8 │ ├── 2.8.0.1.xml │ ├── 2.8.0.xml │ ├── 2.8.1.xml │ ├── 2.8.2.xml │ ├── 2.8.3.1.xml │ ├── 2.8.3.2.xml │ ├── 2.8.3.3.xml │ ├── 2.8.3.4.xml │ └── 2.8.3.xml ├── 3.0.xml ├── 3.0 │ ├── 3.0.0.xml │ ├── 3.0.1.xml │ ├── 3.0.2.xml │ ├── 3.0.3.xml │ ├── 3.0.4.1.xml │ ├── 3.0.4.xml │ ├── 3.0.5.xml │ ├── 3.0.6.xml │ ├── 3.0.7.xml │ ├── 3.0.8.1.xml │ ├── 3.0.8.2.xml │ └── 3.0.8.xml ├── 3.1.xml ├── 3.1 │ ├── 3.1.0.xml │ ├── 3.1.1.1.xml │ ├── 3.1.1.xml │ ├── 3.1.10.1.xml │ ├── 3.1.10.xml │ ├── 3.1.11.1.xml │ ├── 3.1.11.xml │ ├── 3.1.2.xml │ ├── 3.1.3.1.xml │ ├── 3.1.3.xml │ ├── 3.1.4.xml │ ├── 3.1.5.xml │ ├── 3.1.6.xml │ ├── 3.1.7.xml │ ├── 3.1.8.xml │ └── 3.1.9.xml ├── 3.2.xml ├── 3.2 │ ├── 3.2.0.xml │ ├── 3.2.1.xml │ ├── 3.2.2.1.xml │ ├── 3.2.2.xml │ ├── 3.2.3.xml │ ├── 3.2.4.1.xml │ ├── 3.2.4.xml │ ├── 3.2.5.1.xml │ └── 3.2.5.xml ├── 3.3.xml ├── 4.0.xml ├── default.xml ├── dev.xml └── product-config.json ├── pyproject.toml ├── pytest.ini ├── rest ├── access_test.go ├── admin_api.go ├── admin_api_auth_routing_permissions.go ├── admin_api_auth_test.go ├── admin_functions_api.go ├── adminapitest │ ├── admin_api_test.go │ ├── collections_admin_api_test.go │ ├── main_test.go │ └── resync_test.go ├── api.go ├── api_benchmark_test.go ├── api_collections_test.go ├── api_test.go ├── api_test_helpers.go ├── api_test_no_race_test.go ├── attachment_test.go ├── attachmentcompactiontest │ ├── attachment_compaction_api_test.go │ └── main_test.go ├── audit_test.go ├── blip_api_attachment_test.go ├── blip_api_collections_test.go ├── blip_api_crud_test.go ├── blip_api_delta_sync_test.go ├── blip_api_no_race_test.go ├── blip_api_replication_test.go ├── blip_channel_filter_test.go ├── blip_client_test.go ├── blip_stats_test.go ├── blip_sync.go ├── blip_sync_messages_test.go ├── blip_sync_test.go ├── bootstrap_test.go ├── bulk_api.go ├── bulk_api_test.go ├── bytes_read_public_api_test.go ├── changes_api.go ├── changes_request_plus_test.go ├── changes_test.go ├── changestest │ ├── changes_api_test.go │ ├── changes_collection_test.go │ └── main_test.go ├── config.go ├── config_database.go ├── config_database_test.go ├── config_flags.go ├── config_flags_test.go ├── config_legacy.go ├── config_legacy_test.go ├── config_manager.go ├── config_manager_test.go ├── config_registry.go ├── config_registry_test.go ├── config_startup.go ├── config_startup_test.go ├── config_test.go ├── cors_test.go ├── counted_request_reader.go ├── counted_response_writer.go ├── counted_response_writer_test.go ├── database_init_manager.go ├── database_init_manager_test.go ├── debug.go ├── diagnostic_api.go ├── diagnostic_api_test.go ├── diagnostic_doc_api.go ├── diagnostic_doc_api_test.go ├── doc_api.go ├── doc_api_test.go ├── encoded_response_writer.go ├── facebook.go ├── functions_api.go ├── functionsapitest │ ├── main_test.go │ ├── user_functions_admin_test.go │ └── user_functions_queries_test.go ├── google.go ├── handler.go ├── handler_config_database.go ├── handler_test.go ├── importtest │ ├── collections_import_test.go │ ├── import_data_test.go │ ├── import_logging_test.go │ ├── import_partition_test.go │ ├── import_test.go │ └── main_test.go ├── importuserxattrtest │ ├── admin_api_test.go │ ├── import_test.go │ ├── main_test.go │ ├── rawdoc_test.go │ ├── revcache_test.go │ └── revid_import_test.go ├── indextest │ ├── index_init_api_test.go │ ├── index_test.go │ ├── main_test.go │ ├── post_upgrade_test.go │ └── resync_test.go ├── jwt_auth_test.go ├── logging_test.go ├── main.go ├── main_legacy.go ├── main_legacy_test.go ├── main_test.go ├── multipart.go ├── multipart_test.go ├── non_counted_response_writer.go ├── oidc_api.go ├── oidc_api_test.go ├── oidc_test_provider.go ├── oidc_test_provider_test.go ├── persistent_config_test.go ├── replicatortest │ ├── main_test.go │ ├── replicator_collection_test.go │ ├── replicator_test.go │ └── replicator_test_helper.go ├── rest_tester_cluster_test.go ├── revocation_test.go ├── role_api_test.go ├── rosmar_test.go ├── routing.go ├── server_context.go ├── server_context_test.go ├── serverless_test.go ├── session_api.go ├── session_test.go ├── sgcollect.go ├── sgcollecttest │ ├── main_test.go │ └── sgcollect_test.go ├── stats_context.go ├── stats_context_test.go ├── sync_fn_test.go ├── testdata_test.go ├── upgradetest │ ├── main_test.go │ ├── remove_collection_test.go │ └── upgrade_registry_test.go ├── user_agent_version.go ├── user_agent_version_test.go ├── user_api_test.go ├── utilities_testing.go ├── utilities_testing_async.go ├── utilities_testing_attachment.go ├── utilities_testing_bootstrap.go ├── utilities_testing_functions_api.go ├── utilities_testing_functions_api_test.go ├── utilities_testing_resttester.go ├── utilities_testing_test.go ├── utilities_testing_user.go ├── view_api.go ├── view_api_test.go ├── x509_test.go ├── x509_utils_test.go └── xattr_upgrade_test.go ├── rewrite-manifest.sh ├── ruleguard ├── README.md ├── go.mod ├── go.sum ├── internal │ └── test_pkg │ │ └── base │ │ └── log.go ├── logwrappederr_test.go ├── rules-logwrappederr.go └── rules-requirefailnow.go ├── service ├── README.md ├── script_templates │ ├── com.couchbase.mobile.sync_gateway.plist │ ├── systemd_debian_sync_gateway.tpl │ ├── systemd_sync_gateway.tpl │ ├── sysv_sync_gateway.tpl │ ├── upstart_redhat_sync_gateway.tpl │ └── upstart_ubuntu_sync_gateway.tpl ├── sg-windows │ ├── build.cmd │ └── sg-service │ │ └── sg-service.go ├── sync_gateway_service_install.sh ├── sync_gateway_service_uninstall.sh └── sync_gateway_service_upgrade.sh ├── set-version-stamp.sh ├── snap-manifest.sh ├── sync_gateway.sublime-project ├── test-integration-init.sh ├── test.sh ├── test_with_coverage.sh ├── tools-tests ├── parser_test.py ├── password_remover_test.py ├── sgcollect_info_test.py ├── tasks_test.py └── upload_test.py ├── tools.go ├── tools ├── README.adoc ├── cache_perf_tool │ ├── dcpDataGeneration.go │ ├── main.go │ ├── processEntry.go │ └── sgwNodeAbstraction.go ├── manifest-helper ├── password_remover.py ├── sgcollect.py ├── sgcollect_info ├── stats-definition-exporter │ ├── README.md │ ├── main.go │ ├── main_test.go │ ├── stat_definition.go │ └── stat_traverser.go └── tasks.py ├── uv.lock └── xdcr ├── cbs_xdcr.go ├── main_test.go ├── replication.go ├── rosmar_xdcr.go ├── stats.go └── xdcr_test.go /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | The Sync Gateway issue tracker is reserved for bug reports and enhancement 2 | requests. For general questions, please use the Couchbase forums: 3 | https://forums.couchbase.com/c/mobile/sync-gateway. Thank you! 4 | 5 | ### Sync Gateway version 6 | Version information is written on startup to the Sync Gateway log, or can 7 | be obtained by accessing the root endpoint (`/`) on the Sync Gateway Admin REST API. 8 | 9 | ### Operating system 10 | The operating system you're running Sync Gateway on. 11 | 12 | ### Config file 13 | ```javascript 14 | # When relevant, copy-paste your sync gateway config here. Remove any sensitive information 15 | as appropriate (including addresses, passwords, etc). 16 | ``` 17 | 18 | ### Log output 19 | Provide a link to a GitHub Gist containing relevant Sync Gateway log output when 20 | the error occured. Do NOT paste the log output in the issue, just paste the 21 | link to the Gist. 22 | 23 | ### Expected behavior 24 | What should have happened? 25 | 26 | ### Actual behavior 27 | What actually happened? 28 | 29 | ### Steps to reproduce 30 | 1. 31 | 2. 32 | 3. 33 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | CBG-0000 2 | 3 | Describe your PR here... 4 | - Use bullet points if there's more than one thing changed 5 | 6 | ## Pre-review checklist 7 | - [ ] Removed debug logging (`fmt.Print`, `log.Print`, ...) 8 | - [ ] Logging sensitive data? Make sure it's tagged (e.g. `base.UD(docID)`, `base.MD(dbName)`) 9 | - [ ] Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in `docs/api` 10 | 11 | ## Dependencies (if applicable) 12 | - [ ] Link upstream PRs 13 | - [ ] Update Go module dependencies when merged 14 | 15 | ## [Integration Tests](https://jenkins.sgwdev.com/job/SyncGateway-Integration/build?delay=0sec) 16 | - [ ] `GSI=true,xattrs=true` https://jenkins.sgwdev.com/job/SyncGateway-Integration/000/ 17 | -------------------------------------------------------------------------------- /.github/copilot-instructions.md: -------------------------------------------------------------------------------- 1 | When performing a code review, if there are any changes to the REST APIs (e.g. REST handler code, query parameters, structs returned via handler functions), ensure the OpenAPI specifications are updated accordingly in the `docs/api` directory. 2 | 3 | When performing a code review, if there is any dev-time logging using `log.Printf`, `fmt.Printf`, or similar, ensure it is removed or replaced with appropriate Sync Gateway logging (e.g. `base.Infof`, `base.Warnf`, `base.Debugf`). 4 | 5 | When performing a code review, if a log message includes User Data, ensure the value is wrapped with the `base.UD()` helper function to enable redaction. User Data includes: Document IDs, JSON document contents (keys and values), usernames, email addresses, or other personally identifiable information (PII). 6 | 7 | When performing a code review, be mindful of performance implications, such as mutex contention, race conditions, and other concurrency-related issues. 8 | 9 | When performing a code review, ensure code comments explain the *intent* or *reasoning* behind an implementation, rather than just restating what the code does. 10 | 11 | When performing a code review, ensure `for` loops have sufficient exit conditions and are not prone to infinite loops. Prefer expressing the exit condition in the loop declaration itself, rather than relying on `break` statements within the loop body. 12 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2023-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included in 4 | # the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 5 | # file, in accordance with the Business Source License, use of this software 6 | # will be governed by the Apache License, Version 2.0, included in the file 7 | # licenses/APL2.txt. 8 | 9 | version: 2 10 | updates: 11 | - package-ecosystem: "gomod" 12 | directory: "/" 13 | schedule: 14 | interval: "weekly" 15 | registries: 16 | - gh-private 17 | registries: 18 | gh-private: 19 | type: git 20 | url: https://github.com 21 | username: x-access-token 22 | password: ${{secrets.GH_PERSONAL_ACCESS_TOKEN_CBROBOTSG}} 23 | -------------------------------------------------------------------------------- /.github/workflows/service.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included in 4 | # the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 5 | # file, in accordance with the Business Source License, use of this software 6 | # will be governed by the Apache License, Version 2.0, included in the file 7 | # licenses/APL2.txt. 8 | 9 | name: service 10 | 11 | on: 12 | push: 13 | # Only run when we modify service files 14 | paths: 15 | - 'service/**' 16 | - 'integration-test/**' 17 | branches: 18 | - 'main' 19 | - 'release/*' 20 | - 'feature/*' 21 | - 'beryllium' 22 | - 'CBG*' 23 | - 'ci-*' 24 | - 'api-ci-*' 25 | pull_request: 26 | # Only run when we modify service files 27 | paths: 28 | - 'service/**' 29 | - 'integration-test/**' 30 | branches: 31 | - 'main' 32 | - 'release/*' 33 | 34 | concurrency: 35 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} 36 | cancel-in-progress: ${{ !contains(github.ref, 'release/')}} 37 | 38 | jobs: 39 | scripts: 40 | runs-on: ubuntu-latest 41 | name: Verify service script installation. 42 | steps: 43 | - uses: actions/checkout@v4 44 | # build sync gateway since the executable is needed for service installation 45 | - uses: actions/setup-go@v5 46 | with: 47 | go-version: 1.23.3 48 | - name: "Build Sync Gateway" 49 | run: mkdir -p ./bin && go build -o ./bin ./... 50 | - name: "Run test scripts" 51 | run: ./integration-test/service-install-tests.sh 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.idea 2 | *.sublime-workspace 3 | *.walrus 4 | **/git_info.go.bak 5 | \#* 6 | *~ 7 | .#* 8 | \#*\# 9 | /bin 10 | /pkg 11 | *.exe 12 | *.iml 13 | sg_config.json 14 | coverage*.out 15 | coverage*.xml 16 | verbose*.out* 17 | verbose*.xml 18 | sync_gateway 19 | *.pb.gz 20 | __pycache__ 21 | tools/cache_perf_tool/cache_perf_tool 22 | cache_perf_tool 23 | tools/stats-definition-exporter/stats-definition-exporter 24 | stats-definition-exporter 25 | 26 | ### Couchbase Plugin ### 27 | .cbcache/ 28 | 29 | planPIndexes/ 30 | -------------------------------------------------------------------------------- /.yamllint.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2023-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | 9 | --- 10 | 11 | extends: default 12 | 13 | rules: 14 | document-start: disable 15 | line-length: disable 16 | comments: disable 17 | truthy: disable 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Source code in this repository is licensed under various licenses. The 2 | Business Source License 1.1 (BSL) is one such license. Each file indicates in 3 | a section at the beginning of the file the name of the license that applies to 4 | it. All licenses used in this repository can be found in the top-level 5 | licenses directory. 6 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | buildit: 2 | ./build.sh 3 | clean: 4 | rm -rf bin pkg 5 | buildclean: clean buildit 6 | cleanbuild: clean buildit 7 | test: 8 | @./test.sh -------------------------------------------------------------------------------- /auth/jwt_test_utils.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package auth 10 | 11 | import ( 12 | "testing" 13 | 14 | "github.com/go-jose/go-jose/v4" 15 | "github.com/go-jose/go-jose/v4/jwt" 16 | "github.com/stretchr/testify/require" 17 | ) 18 | 19 | // These are not in jwt_test.go to allow use in tests from other packages. 20 | 21 | type JWTHeaders map[jose.HeaderKey]interface{} 22 | 23 | // CreateTestJWT creates and signs a valid JWT with the given headers and claims. 24 | // The key must be valid for use with gopkg.in/square/go-jose.v2 (https://pkg.go.dev/gopkg.in/square/go-jose.v2#readme-supported-key-types), 25 | // and the alg must match the key. 26 | func CreateTestJWT(t *testing.T, alg jose.SignatureAlgorithm, key interface{}, headers JWTHeaders, claims map[string]interface{}) string { 27 | t.Helper() 28 | 29 | signerOpts := new(jose.SignerOptions) 30 | for key, val := range headers { 31 | signerOpts.WithHeader(key, val) 32 | } 33 | 34 | signer, err := jose.NewSigner(jose.SigningKey{ 35 | Algorithm: alg, 36 | Key: key, 37 | }, signerOpts) 38 | require.NoError(t, err, "failed to create signer") 39 | 40 | tok, err := jwt.Signed(signer).Claims(claims).Serialize() 41 | require.NoError(t, err, "failed to serialize JWT") 42 | return tok 43 | } 44 | -------------------------------------------------------------------------------- /auth/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package auth 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | ) 19 | 20 | func TestMain(m *testing.M) { 21 | ctx := context.Background() // start of test process 22 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 2048} 23 | base.TestBucketPoolNoIndexes(ctx, m, tbpOptions) 24 | } 25 | -------------------------------------------------------------------------------- /base/auditd_descriptor.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package base 10 | 11 | import ( 12 | "encoding/json" 13 | ) 14 | 15 | const ( 16 | // moduleDescriptorName is the name of the module. Must match the name used in the module descriptor file. 17 | moduleDescriptorName = "sync_gateway" 18 | // auditdFormatVersion is the version of the auditd format to be used. Only version 2 is supported. 19 | auditdFormatVersion = 2 20 | ) 21 | 22 | // generateAuditdModuleDescriptor returns an auditd-compatible module descriptor for the given events. 23 | func generateAuditdModuleDescriptor(e events) ([]byte, error) { 24 | auditEvents := make([]auditdEventDescriptor, 0, len(e)) 25 | for id, event := range e { 26 | auditEvents = append(auditEvents, toAuditdEventDescriptor(id, *event)) 27 | } 28 | m := auditdModuleDescriptor{ 29 | Version: auditdFormatVersion, 30 | Module: moduleDescriptorName, 31 | Events: auditEvents, 32 | } 33 | return json.Marshal(m) 34 | } 35 | -------------------------------------------------------------------------------- /base/auditd_descriptor_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package base 10 | 11 | import ( 12 | "testing" 13 | 14 | "github.com/stretchr/testify/require" 15 | ) 16 | 17 | // TestGenerateAuditdModuleDescriptor outputs a generated auditd module descriptor for AuditEvents. 18 | func TestGenerateAuditdModuleDescriptor(t *testing.T) { 19 | b, err := generateAuditdModuleDescriptor(AuditEvents) 20 | require.NoError(t, err) 21 | t.Log(string(b)) 22 | } 23 | -------------------------------------------------------------------------------- /base/cbgt.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package base 10 | 11 | import ( 12 | "github.com/couchbase/cbgt" 13 | ) 14 | 15 | // NewCbgtCfgMem runs cbgt.NewCfgMem and sets the matching version number we expect for Sync Gateway. 16 | func NewCbgtCfgMem() (*cbgt.CfgMem, error) { 17 | cfg := cbgt.NewCfgMem() 18 | _, err := cfg.Set(cbgt.VERSION_KEY, []byte(SGCbgtMetadataVersion), 0) 19 | if err != nil { 20 | return nil, err 21 | } 22 | return cfg, nil 23 | } 24 | -------------------------------------------------------------------------------- /base/collection_common.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package base 12 | 13 | import ( 14 | "errors" 15 | 16 | sgbucket "github.com/couchbase/sg-bucket" 17 | ) 18 | 19 | var ErrCollectionsUnsupported = errors.New("collections not supported") 20 | 21 | type ScopeAndCollectionName = sgbucket.DataStoreNameImpl 22 | 23 | func DefaultScopeAndCollectionName() ScopeAndCollectionName { 24 | return ScopeAndCollectionName{Scope: DefaultScope, Collection: DefaultCollection} 25 | } 26 | 27 | func NewScopeAndCollectionName(scope, collection string) ScopeAndCollectionName { 28 | return ScopeAndCollectionName{ 29 | Scope: scope, 30 | Collection: collection, 31 | } 32 | } 33 | 34 | type ScopeAndCollectionNames []ScopeAndCollectionName 35 | 36 | // ScopeAndCollectionNames returns a dot-separated formatted slice of scope and collection names. 37 | func (s ScopeAndCollectionNames) ScopeAndCollectionNames() []string { 38 | scopes := make([]string, 0, len(s)) 39 | for _, scopeAndCollection := range s { 40 | scopes = append(scopes, scopeAndCollection.String()) 41 | } 42 | return scopes 43 | } 44 | 45 | func FullyQualifiedCollectionName(bucketName, scopeName, collectionName string) string { 46 | return bucketName + "." + scopeName + "." + collectionName 47 | } 48 | -------------------------------------------------------------------------------- /base/constants_ce.go: -------------------------------------------------------------------------------- 1 | //go:build !cb_sg_enterprise 2 | // +build !cb_sg_enterprise 3 | 4 | /* 5 | Copyright 2019-Present Couchbase, Inc. 6 | 7 | Use of this software is governed by the Business Source License included in 8 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 9 | file, in accordance with the Business Source License, use of this software will 10 | be governed by the Apache License, Version 2.0, included in the file 11 | licenses/APL2.txt. 12 | */ 13 | 14 | package base 15 | 16 | const ( 17 | productEditionEnterprise = false 18 | productEditionShortName = "CE" 19 | 20 | DefaultAutoImport = false // Whether Sync Gateway should auto-import docs, if not specified in the config 21 | ) 22 | -------------------------------------------------------------------------------- /base/constants_ee.go: -------------------------------------------------------------------------------- 1 | //go:build cb_sg_enterprise 2 | // +build cb_sg_enterprise 3 | 4 | /* 5 | Copyright 2019-Present Couchbase, Inc. 6 | 7 | Use of this software is governed by the Business Source License included in 8 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 9 | file, in accordance with the Business Source License, use of this software will 10 | be governed by the Apache License, Version 2.0, included in the file 11 | licenses/APL2.txt. 12 | */ 13 | 14 | package base 15 | 16 | const ( 17 | productEditionEnterprise = true 18 | productEditionShortName = "EE" 19 | 20 | DefaultAutoImport = true // Whether Sync Gateway should auto-import docs, if not specified in the config 21 | ) 22 | -------------------------------------------------------------------------------- /base/devmode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package base 10 | 11 | import ( 12 | "context" 13 | ) 14 | 15 | const ( 16 | AssertionFailedPrefix = "Assertion failed: " 17 | ) 18 | 19 | // IsDevMode returns true when compiled with the `cb_sg_devmode` build tag 20 | func IsDevMode() bool { 21 | return cbSGDevModeBuildTagSet 22 | } 23 | 24 | // AssertfCtx logs an error message and continues execution, or when compiled with the `cb_sg_devmode` build tag panics for better dev-time visibility. 25 | // The SG test harness will ensure AssertionFailCount is zero at the end of tests, even without devmode enabled. 26 | // Note: Callers MUST ensure code is safe to continue executing after the Assert (e.g. by returning an error) and MUST NOT be used like a panic that will halt. 27 | func AssertfCtx(ctx context.Context, format string, args ...any) { 28 | SyncGatewayStats.GlobalStats.ResourceUtilization.AssertionFailCount.Add(1) 29 | assertLogFn(ctx, AssertionFailedPrefix+format, args...) 30 | } 31 | -------------------------------------------------------------------------------- /base/devmode_off.go: -------------------------------------------------------------------------------- 1 | //go:build !cb_sg_devmode 2 | // +build !cb_sg_devmode 3 | 4 | // Copyright 2024-Present Couchbase, Inc. 5 | // 6 | // Use of this software is governed by the Business Source License included 7 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 8 | // in that file, in accordance with the Business Source License, use of this 9 | // software will be governed by the Apache License, Version 2.0, included in 10 | // the file licenses/APL2.txt. 11 | 12 | package base 13 | 14 | const cbSGDevModeBuildTagSet = false 15 | 16 | var assertLogFn logFn = ErrorfCtx 17 | -------------------------------------------------------------------------------- /base/devmode_on.go: -------------------------------------------------------------------------------- 1 | //go:build cb_sg_devmode 2 | // +build cb_sg_devmode 3 | 4 | // Copyright 2024-Present Couchbase, Inc. 5 | // 6 | // Use of this software is governed by the Business Source License included 7 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 8 | // in that file, in accordance with the Business Source License, use of this 9 | // software will be governed by the Apache License, Version 2.0, included in 10 | // the file licenses/APL2.txt. 11 | 12 | package base 13 | 14 | const cbSGDevModeBuildTagSet = true 15 | 16 | var assertLogFn logFn = PanicfCtx 17 | -------------------------------------------------------------------------------- /base/git_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package base 12 | 13 | // The git commit that was compiled. This will be filled in by the compiler. 14 | const GitProductName = "" 15 | const GitCommit = "" 16 | const GitBranch = "" 17 | const GitDirty = "" 18 | -------------------------------------------------------------------------------- /base/logger_external_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package base 10 | 11 | import ( 12 | "testing" 13 | 14 | "github.com/couchbase/gocb/v2" 15 | "github.com/couchbase/gocbcore/v10" 16 | "github.com/stretchr/testify/assert" 17 | ) 18 | 19 | func TestGoCBLogLevelEquality(t *testing.T) { 20 | // Ensures all gocb and gocbcore log levels match between versions. 21 | // If they don't, we'll need to revisit the log wrappers to not just do direct type conversions to implement 4 loggers. 22 | assert.Equal(t, gocb.LogError, gocb.LogLevel(gocbcore.LogError)) 23 | 24 | assert.Equal(t, gocb.LogWarn, gocb.LogLevel(gocbcore.LogWarn)) 25 | 26 | assert.Equal(t, gocb.LogInfo, gocb.LogLevel(gocbcore.LogInfo)) 27 | 28 | assert.Equal(t, gocb.LogDebug, gocb.LogLevel(gocbcore.LogDebug)) 29 | 30 | assert.Equal(t, gocb.LogTrace, gocb.LogLevel(gocbcore.LogTrace)) 31 | } 32 | -------------------------------------------------------------------------------- /base/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package base 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | ) 17 | 18 | func TestMain(m *testing.M) { 19 | ctx := context.Background() // start of test process 20 | tbpOptions := TestBucketPoolOptions{MemWatermarkThresholdMB: 2048, ParallelBucketInit: true} 21 | TestBucketPoolNoIndexes(ctx, m, tbpOptions) 22 | } 23 | -------------------------------------------------------------------------------- /base/main_test_util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package base 10 | 11 | import ( 12 | "fmt" 13 | "os" 14 | "path/filepath" 15 | "runtime" 16 | "testing" 17 | ) 18 | 19 | // SkipTestMain logs in the same format as actual test output that we're skipping the current package. 20 | func SkipTestMain(m *testing.M, format string, args ...interface{}) { 21 | fmt.Println("=== RUN TestMain") 22 | printfFromLine(2, " "+format+"\n", args...) 23 | fmt.Println("--- SKIP: TestMain (0.00s)") 24 | os.Exit(0) 25 | } 26 | 27 | // printfFromLine prints the given message with the filename and line number from the caller 28 | func printfFromLine(skip int, format string, args ...interface{}) { 29 | _, filename, line, _ := runtime.Caller(skip) 30 | filename = filepath.Base(filename) // trim 31 | args = append([]interface{}{filename, line}, args...) 32 | // E.g: main_test.go:25: msg 33 | fmt.Printf("%s:%d: "+format, args...) 34 | } 35 | -------------------------------------------------------------------------------- /base/redactable_string.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package base 10 | 11 | import "fmt" 12 | 13 | // RedactSprintf is a wrapper around fmt.Sprintf that redacts any sensitive data. 14 | func RedactSprintf(format string, args ...any) string { 15 | redactedArgs := redact(args) 16 | return fmt.Sprintf(format, redactedArgs...) 17 | } 18 | -------------------------------------------------------------------------------- /base/rlimit_windows.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package base 12 | 13 | import "context" 14 | 15 | func SetMaxFileDescriptors(_ context.Context, maxFDs uint64) (uint64, error) { 16 | return 0, nil 17 | } 18 | -------------------------------------------------------------------------------- /base/user_agent.go: -------------------------------------------------------------------------------- 1 | // Copyright 2025-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package base 10 | 11 | import ( 12 | "fmt" 13 | "runtime" 14 | "strings" 15 | ) 16 | 17 | const ( 18 | HTTPHeaderUserAgent = "User-Agent" 19 | ) 20 | 21 | // NewSGProcessUserAgent returns a new user agent string for the given process name. 22 | // A process may be something like "ISGR" and is used in place of "Platform" when compared with CBL user agents. 23 | // 24 | // Additional information may be provided which will be appended to the comments section of the UA string. 25 | // Example: "CouchbaseSyncGateway/3.2.1.4@33-EE (ISGR; darwin/arm64)" 26 | func NewSGProcessUserAgent(process string, extraComments ...string) string { 27 | productName := removeAllWhitespace(ProductNameString) 28 | productVersion := removeAllWhitespace(ProductVersion.String()) 29 | 30 | comment := fmt.Sprintf("%s; %s/%s", process, runtime.GOOS, runtime.GOARCH) 31 | if len(extraComments) > 0 { 32 | comment += "; " + strings.Join(extraComments, "; ") 33 | } 34 | 35 | return fmt.Sprintf(`%s/%s (%s)`, productName, productVersion, comment) 36 | } 37 | -------------------------------------------------------------------------------- /base/util_test_norace.go: -------------------------------------------------------------------------------- 1 | // Copyright 2025-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | //go:build !race 10 | // +build !race 11 | 12 | package base 13 | 14 | import "testing" 15 | 16 | // IsRaceDetectorEnabled returns true if compiled with -race. Intended to be used for testing only. 17 | func IsRaceDetectorEnabled(t *testing.T) bool { 18 | return false 19 | } 20 | -------------------------------------------------------------------------------- /base/util_test_race.go: -------------------------------------------------------------------------------- 1 | // Copyright 2025-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | //go:build race 10 | // +build race 11 | 12 | package base 13 | 14 | import "testing" 15 | 16 | // IsRaceDetectorEnabled returns true if compiled with -race. Intended to be used for testing only 17 | func IsRaceDetectorEnabled(t *testing.T) bool { 18 | return true 19 | } 20 | -------------------------------------------------------------------------------- /base/views.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package base 12 | 13 | const ( 14 | ViewQueryParamStale = "stale" 15 | ViewQueryParamReduce = "reduce" 16 | ViewQueryParamStartKey = "startkey" 17 | ViewQueryParamEndKey = "endkey" 18 | ViewQueryParamInclusiveEnd = "inclusive_end" 19 | ViewQueryParamLimit = "limit" 20 | ViewQueryParamIncludeDocs = "include_docs" // Ignored -- see https://forums.couchbase.com/t/do-the-viewquery-options-omit-include-docs-on-purpose/12399 21 | ViewQueryParamDescending = "descending" 22 | ViewQueryParamGroup = "group" 23 | ViewQueryParamSkip = "skip" 24 | ViewQueryParamGroupLevel = "group_level" 25 | ViewQueryParamStartKeyDocId = "startkey_docid" 26 | ViewQueryParamEndKeyDocId = "endkey_docid" 27 | ViewQueryParamKey = "key" 28 | ViewQueryParamKeys = "keys" 29 | ) 30 | -------------------------------------------------------------------------------- /bench.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/bin/sh -e 3 | 4 | # Copyright 2015-Present Couchbase, Inc. 5 | # 6 | # Use of this software is governed by the Business Source License included in 7 | # the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 8 | # file, in accordance with the Business Source License, use of this software 9 | # will be governed by the Apache License, Version 2.0, included in the file 10 | # licenses/APL2.txt. 11 | 12 | # This script runs benchmark tests in all the subpackages. 13 | 14 | go test ./... -bench='LoggingPerformance' -benchtime 1m -run XXX 15 | 16 | go test ./... -bench='RestApiGetDocPerformance' -cpu 1,2,4 -benchtime 1m -run XXX 17 | 18 | go test ./... -bench='RestApiPutDocPerformanceDefaultSyncFunc' -benchtime 1m -run XXX 19 | 20 | go test ./... -bench='RestApiPutDocPerformanceExplicitSyncFunc' -benchtime 1m -run XXX 21 | -------------------------------------------------------------------------------- /build/README.Debian.tmpl: -------------------------------------------------------------------------------- 1 | @@PRODUCT@@ for Debian 2 | ---------------------------- 3 | 4 | @@PRODUCT_BASE_CAP@@ Server distribution for Debian 5 | 6 | After installing this package, please visit http://hostname:8091 7 | for the @@PRODUCT_BASE_CAP@@ Sync Gateway web console. 8 | -------------------------------------------------------------------------------- /build/README.txt: -------------------------------------------------------------------------------- 1 | Couchbase Sync Gateway 2 | 3 | This is a self-contained installation of Couchbase Sync Gateway. You can start Sync Gateway by running sync_gateway and specifying a configuration file. Sample configuration files can be found in the examples folder. Modify the example configuration files to include your Couchbase Server address and credentials. 4 | 5 | Detailed getting started information can be found at https://docs.couchbase.com/sync-gateway/current/getting-started.html 6 | 7 | $ ./sync_gateway examples/basic-couchbase-bucket.json 8 | 9 | You can stop Sync Gateway with Control-C. There is no specific shutdown procedure and it is safe to stop it at any time. 10 | 11 | This application can be run from any location on any writeable volume. You can choose to move it to your Application 12 | directory, but this is not required. However, do not move the application while it's running. -------------------------------------------------------------------------------- /build/changelog.tmpl: -------------------------------------------------------------------------------- 1 | @@PRODUCT@@ (@@VERSION@@) UNRELEASED; urgency=low 2 | 3 | * Initial debian package for @@PRODUCT_BASE_CAP@@ Sync Gateway @@VERSION@@ 4 | 5 | -- Tue, 30 Mar 2010 12:20:21 -0700 6 | -------------------------------------------------------------------------------- /build/compat.tmpl: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /build/control.tmpl: -------------------------------------------------------------------------------- 1 | Source: @@PRODUCT@@ 2 | Section: web 3 | Priority: extra 4 | Maintainer: Couchbase 5 | Build-Depends: debhelper (>= 5) 6 | Standards-Version: 3.8.1 7 | Homepage: http://couchbase.com 8 | 9 | Package: @@PRODUCT@@ 10 | Architecture: any 11 | Depends: ${shlibs:Depends}, ${misc:Depends}, lsb-base (>= 3.2), systemctl | systemd 12 | Description: Gluing Couchbase Lite to Couchbase Server 13 | Replaces: any 14 | Breaks: any 15 | -------------------------------------------------------------------------------- /build/copyright.tmpl: -------------------------------------------------------------------------------- 1 | This package was debianized by Bin Cui . 2 | 3 | Upstream Author(s): 4 | 5 | Couchbase 6 | 7 | Copyright: 8 | 9 | Copyright (C) 2013 Couchbase 10 | 11 | License: 12 | 13 | See @@PREFIX@@/LICENSE.txt 14 | 15 | -------------------------------------------------------------------------------- /build/manifest.txt.tmpl: -------------------------------------------------------------------------------- 1 | @@PRODUCT@@ @@VERSION@@ @@PLATFORM@@ 2 | -------------------------------------------------------------------------------- /build/manifest.xml.tmpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /build/postrm.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright 2014-Present Couchbase, Inc. 4 | # 5 | # Use of this software is governed by the Business Source License included in 6 | # the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 7 | # file, in accordance with the Business Source License, use of this software 8 | # will be governed by the Apache License, Version 2.0, included in the file 9 | # licenses/APL2.txt. 10 | 11 | set -e 12 | 13 | #kill any sync_gateway processes started by third party, sync_gateway has been uninstalled 14 | ps aux | grep -v grep | grep bin/@@PRODUCT_EXEC@@ | awk '{print $2}' | 15 | while read line; do 16 | # kill process 17 | kill -9 $line 18 | done 19 | -------------------------------------------------------------------------------- /build/preinst.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright 2013-Present Couchbase, Inc. 4 | # 5 | # Use of this software is governed by the Business Source License included in 6 | # the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 7 | # file, in accordance with the Business Source License, use of this software 8 | # will be governed by the Apache License, Version 2.0, included in the file 9 | # licenses/APL2.txt. 10 | 11 | # preinst script for @@PRODUCT_BASE@@ software 12 | # 13 | # see: dh_installdeb(1) 14 | 15 | set -e 16 | 17 | # summary of how this script can be called: 18 | # * `install' 19 | # * `install' 20 | # * `upgrade' 21 | # * `abort-upgrade' 22 | # for details, see http://www.debian.org/doc/debian-policy/ or 23 | # the debian-policy package 24 | 25 | case "$1" in 26 | install|upgrade) 27 | getent group @@PRODUCT_BASE@@ >/dev/null || \ 28 | groupadd -r @@PRODUCT_BASE@@ || exit 1 29 | getent passwd @@PRODUCT_BASE@@ >/dev/null || \ 30 | useradd -r -g @@PRODUCT_BASE@@ -d @@PREFIX@@ -s /bin/bash \ 31 | -c "@@PRODUCT_BASE_CAP@@ system user" @@PRODUCT_BASE@@ || exit 1 32 | exit 0 33 | ;; 34 | 35 | abort-upgrade) 36 | ;; 37 | 38 | *) 39 | echo "preinst called with unknown argument \`$1'" >&2 40 | exit 1 41 | ;; 42 | esac 43 | 44 | # dh_installdeb will replace this with shell code automatically 45 | # generated by other debhelper scripts. 46 | 47 | #DEBHELPER# 48 | 49 | exit 0 50 | -------------------------------------------------------------------------------- /build/prerm.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright 2013-Present Couchbase, Inc. 4 | # 5 | # Use of this software is governed by the Business Source License included in 6 | # the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 7 | # file, in accordance with the Business Source License, use of this software 8 | # will be governed by the Apache License, Version 2.0, included in the file 9 | # licenses/APL2.txt. 10 | 11 | set -e 12 | 13 | cd @@PREFIX@@/service 14 | ./@@PRODUCT_EXEC@@_service_uninstall.sh 15 | 16 | -------------------------------------------------------------------------------- /build/watch.tmpl: -------------------------------------------------------------------------------- 1 | # Example watch control file for uscan 2 | # Rename this file to "watch" and then you can run the "uscan" command 3 | # to check for upstream updates and more. 4 | # See uscan(1) for format 5 | 6 | # Compulsory line, this is a version 3 file 7 | version=3 8 | 9 | -------------------------------------------------------------------------------- /build/windows/couchbase.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbase/sync_gateway/cde6f6789baf97833e56961ca761fdfff6bc8457/build/windows/couchbase.ico -------------------------------------------------------------------------------- /build/windows/wix_installer/Config.wxi: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /build/windows/wix_installer/assets/cb_installer_banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbase/sync_gateway/cde6f6789baf97833e56961ca761fdfff6bc8457/build/windows/wix_installer/assets/cb_installer_banner.jpg -------------------------------------------------------------------------------- /build/windows/wix_installer/assets/cb_installer_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbase/sync_gateway/cde6f6789baf97833e56961ca761fdfff6bc8457/build/windows/wix_installer/assets/cb_installer_bg.jpg -------------------------------------------------------------------------------- /build/windows/wix_installer/assets/couchbase.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbase/sync_gateway/cde6f6789baf97833e56961ca761fdfff6bc8457/build/windows/wix_installer/assets/couchbase.ico -------------------------------------------------------------------------------- /build/windows/wix_installer/create-installer.bat: -------------------------------------------------------------------------------- 1 | setlocal 2 | set installdir=%1 3 | set version=%2 4 | set edition=%3 5 | set productname=%4 6 | set service_dir=%5 7 | 8 | if "%productname%"=="" set productname="sync-gateway" 9 | 10 | :: Use -ag to have light auto-generate GUIDs, as that way they'll be 11 | :: based on full filename and therefore consistent from build to build. 12 | :: -t wix-exclude.xlst to exclude files from msi package 13 | heat dir %installdir% -srd -suid -ag -sreg -ke -cg SyncGateway -dr INSTALLDIR -out Files.wxs -t wix-exclude.xlst || goto :error 14 | 15 | :: Unfortunately -ag and -ke don't work together - it generates an 16 | :: illegal .wxs. Post-process here to provide random GUIDs for empty 17 | :: diretories. 18 | ::python fix-empty-dir-guids.py Files.wxs || goto :error 19 | 20 | :: Compile .wxs files to intermediate objects, specifying version 21 | candle -dVersion=%version% -dProductName="%productname%" -arch x64 -ext WixUtilExtension *.wxs || goto :error 22 | 23 | :: Create RTF version of License file - our license text is close enough 24 | :: to Markdown to pass 25 | ::pandoc ..\LICENSE-%edition%.txt -f markdown -t rtf -s -o License.rtf 26 | 27 | :: Light it up! 28 | echo SERVICE_DIR: %service_dir% 29 | light -ext WixUIExtension -ext WixUtilExtension -b %installdir% -b %service_dir% -o %productname%.msi *.wixobj || goto :error 30 | 31 | :end 32 | exit /b 0 33 | 34 | :error 35 | @echo Previous command failed with error #%errorlevel%. 36 | exit /b %errorlevel% 37 | -------------------------------------------------------------------------------- /build/windows/wix_installer/wix-exclude.xlst: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | -------------------------------------------------------------------------------- /channels/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package channels 12 | 13 | import ( 14 | "context" 15 | "os" 16 | "testing" 17 | 18 | "github.com/couchbase/sync_gateway/base" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | ctx := context.Background() // start of test process 23 | // can't use defer because of os.Exit 24 | teardownFuncs := make([]func(), 0) 25 | teardownFuncs = append(teardownFuncs, base.SetUpGlobalTestLogging(ctx)) 26 | teardownFuncs = append(teardownFuncs, base.SetUpGlobalTestProfiling(m)) 27 | teardownFuncs = append(teardownFuncs, base.SetUpGlobalTestMemoryWatermark(m, 256)) 28 | 29 | base.SkipPrometheusStatsRegistration = true 30 | 31 | // must be the last teardown function added to the list to correctly detect leaked goroutines 32 | teardownFuncs = append(teardownFuncs, base.SetUpTestGoroutineDump(m)) 33 | 34 | // Run the test suite 35 | status := m.Run() 36 | 37 | for _, fn := range teardownFuncs { 38 | fn() 39 | } 40 | 41 | os.Exit(status) 42 | } 43 | -------------------------------------------------------------------------------- /channels/util_testing.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package channels 12 | 13 | import ( 14 | "testing" 15 | 16 | "github.com/couchbase/sync_gateway/base" 17 | ) 18 | 19 | // BaseSetOf a set from zero or more inline string arguments. 20 | // Channel names must be valid, else the function will panic, so this should only be called 21 | // with hardcoded known-valid strings. 22 | func BaseSetOf(tb testing.TB, names ...string) base.Set { 23 | set, err := SetFromArray(names, KeepStar) 24 | if err != nil { 25 | tb.Fatalf("channels.SetOf failed: %v", err) 26 | } 27 | return set 28 | } 29 | -------------------------------------------------------------------------------- /db/database_stats.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package db 12 | 13 | import "context" 14 | 15 | // Wrapper around *expvars.Map for database stats that provide: 16 | // 17 | // - A lazy loading mechanism 18 | // - Initialize all stats in a stat group to their zero values 19 | // 20 | // type DatabaseStats struct { 21 | // NewStats *base.DbStats 22 | // } 23 | 24 | // Update database-specific stats that are more efficiently calculated at stats collection time 25 | func (db *DatabaseContext) UpdateCalculatedStats(ctx context.Context) { 26 | 27 | if db == nil || db.DbStats == nil { 28 | return 29 | } 30 | db.changeCache.updateStats(ctx) 31 | channelCache := db.changeCache.getChannelCache() 32 | if channelCache != nil { 33 | db.DbStats.Cache().ChannelCacheMaxEntries.Set(int64(channelCache.MaxCacheSize(ctx))) 34 | db.DbStats.Cache().HighSeqCached.Set(int64(channelCache.GetHighCacheSequence())) 35 | } 36 | 37 | } 38 | 39 | // UpdateTotalSyncTimeStat updates the TotalSyncTime to the current value + NumReplicationsActive each time this is called 40 | func (db *DatabaseContext) UpdateTotalSyncTimeStat() { 41 | currentActiveReplications := db.DbStats.DatabaseStats.NumReplicationsActive.Value() 42 | db.DbStats.DatabaseStats.TotalSyncTime.Add(currentActiveReplications) 43 | } 44 | -------------------------------------------------------------------------------- /db/event_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package db 12 | 13 | import ( 14 | "math" 15 | "testing" 16 | 17 | "github.com/stretchr/testify/assert" 18 | ) 19 | 20 | func TestEventTypeNames(t *testing.T) { 21 | // Ensure number of level constants, and names match. 22 | assert.Equal(t, int(eventTypeCount), len(eventTypeNames)) 23 | 24 | assert.Equal(t, "DocumentChange", DocumentChange.String()) 25 | assert.Equal(t, "DBStateChange", DBStateChange.String()) 26 | 27 | // Test out of bounds event type 28 | assert.Equal(t, "EventType(255)", EventType(math.MaxUint8).String()) 29 | } 30 | -------------------------------------------------------------------------------- /db/functions/js_function.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package functions 12 | 13 | import ( 14 | "context" 15 | _ "embed" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | 19 | sgbucket "github.com/couchbase/sg-bucket" 20 | "github.com/couchbase/sync_gateway/db" 21 | _ "github.com/robertkrimen/otto/underscore" 22 | ) 23 | 24 | // implements UserFunctionInvocation 25 | type jsInvocation struct { 26 | *functionImpl 27 | db *db.Database 28 | ctx context.Context 29 | args map[string]any 30 | } 31 | 32 | func (fn *jsInvocation) Iterate() (sgbucket.QueryResultIterator, error) { 33 | return nil, nil 34 | } 35 | 36 | func (fn *jsInvocation) Run(ctx context.Context) (any, error) { 37 | return fn.call(ctx, db.MakeUserCtx(fn.db.User(), base.DefaultScope, base.DefaultCollection), fn.args) 38 | } 39 | 40 | func (fn *jsInvocation) call(ctx context.Context, jsArgs ...any) (any, error) { 41 | return fn.compiled.WithTask(ctx, func(task sgbucket.JSServerTask) (result any, err error) { 42 | runner := task.(*jsRunner) 43 | return runner.CallWithDB(fn.db, 44 | fn.ctx, 45 | jsArgs...) 46 | }) 47 | } 48 | -------------------------------------------------------------------------------- /db/functions/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package functions 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | "github.com/couchbase/sync_gateway/db" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | ctx := context.Background() // start of test process 23 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 2048} 24 | db.TestBucketPoolWithIndexes(ctx, m, tbpOptions) 25 | } 26 | -------------------------------------------------------------------------------- /db/indextest/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | // Package indextest runs tests which add or remove GSI tests. These exist in a separate package from db to avoid index churn, and the bucket pool function will drop all indexes in the bucket pool before running tests. 12 | package indextest 13 | 14 | import ( 15 | "context" 16 | "testing" 17 | 18 | "github.com/couchbase/sync_gateway/base" 19 | "github.com/couchbase/sync_gateway/db" 20 | ) 21 | 22 | func TestMain(m *testing.M) { 23 | // these tests are only meant to be be run against Couchbase Server with GSI 24 | if base.UnitTestUrlIsWalrus() || base.TestsDisableGSI() { 25 | base.SkipTestMain(m, "these tests are only meant to be be run against Couchbase Server with GSI") 26 | } 27 | 28 | ctx := context.Background() // start of test process 29 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 2048, NumCollectionsPerBucket: 2} 30 | db.TestBucketPoolEnsureNoIndexes(ctx, m, tbpOptions) 31 | } 32 | -------------------------------------------------------------------------------- /db/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package db 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | ) 19 | 20 | func TestMain(m *testing.M) { 21 | ctx := context.Background() // start of test process 22 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 2048, ParallelBucketInit: true} 23 | TestBucketPoolWithIndexes(ctx, m, tbpOptions) 24 | } 25 | -------------------------------------------------------------------------------- /docs/antora.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2018-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included in 4 | # the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 5 | # file, in accordance with the Business Source License, use of this software 6 | # will be governed by the Apache License, Version 2.0, included in the file 7 | # licenses/APL2.txt. 8 | 9 | name: sync_gateway 10 | title: Sync Gateway 11 | version: '2.0' 12 | start_page: ROOT:installation.adoc 13 | nav: 14 | - modules/docs/nav.adoc 15 | -------------------------------------------------------------------------------- /docs/api/README.md: -------------------------------------------------------------------------------- 1 | # Sync Gateway OpenAPI Specs 2 | 3 | This directory contains the OpenAPI specs for the Sync Gateway REST API. 4 | 5 | The recommended tool to work with these specs is [Redocly](https://redoc.ly/). 6 | 7 | ## Preview 8 | 9 | ```sh 10 | $ redocly preview-docs 11 | ``` 12 | 13 | ## Linting 14 | 15 | ```sh 16 | $ redocly lint 17 | ``` 18 | -------------------------------------------------------------------------------- /docs/api/metric-capella.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | 9 | openapi: 3.0.3 10 | info: 11 | title: App Services Metrics API 12 | description: 'App Services manages access and synchronization between Couchbase Lite and Couchbase Capella' 13 | version: '3.3' 14 | license: 15 | name: Business Source License 1.1 (BSL) 16 | url: 'https://github.com/couchbase/sync_gateway/blob/master/LICENSE' 17 | servers: 18 | - url: 'https://{hostname}:4988' 19 | description: Metrics API 20 | variables: 21 | hostname: 22 | description: The hostname to use 23 | default: localhost 24 | paths: 25 | /metrics: 26 | $ref: ./paths/metric/metrics.yaml 27 | tags: 28 | - name: Prometheus 29 | description: Endpoints for use with Prometheus 30 | externalDocs: 31 | description: Manage App Services for Mobile and Edge | Couchbase Docs 32 | url: 'https://docs.couchbase.com/cloud/app-services/index.html' 33 | -------------------------------------------------------------------------------- /docs/api/paths/admin/-.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get server information 10 | description: Returns information about the Sync Gateway node. 11 | responses: 12 | '200': 13 | description: Returned server information 14 | content: 15 | application/json: 16 | schema: 17 | $ref: ../../components/schemas.yaml#/NodeInfo 18 | tags: 19 | - Server 20 | operationId: get_- 21 | head: 22 | responses: 23 | '200': 24 | description: Server is online 25 | tags: 26 | - Server 27 | summary: Check if server online 28 | description: Check if the server is online by checking the status code of response. 29 | operationId: head_- 30 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_all_dbs.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get a list of all the databases 10 | description: |- 11 | This retrieves all the databases that are in the current Sync Gateway node. If verbose, returns bucket and state information for each database, otherwise returns names only. 12 | 13 | Required Sync Gateway RBAC roles: 14 | 15 | * Sync Gateway Dev Ops 16 | parameters: 17 | - name: verbose 18 | in: query 19 | schema: 20 | type: boolean 21 | responses: 22 | '200': 23 | description: Successfully retrieved all database names 24 | content: 25 | application/json: 26 | schema: 27 | oneOf: 28 | - $ref: "../../components/schemas.yaml#/All DBs" 29 | - $ref: "../../components/schemas.yaml#/All DBs Verbose" 30 | tags: 31 | - Database Management 32 | operationId: get__all_dbs 33 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_debug-fgprof.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get fgprof profile 10 | description: |- 11 | A sampling Go profiler that allows you to analyze On-CPU as well as [Off-CPU](https://www.brendangregg.com/offcpuanalysis.html) (e.g. I/O) time together. 12 | 13 | Required Sync Gateway RBAC roles: 14 | 15 | * Sync Gateway Dev Ops 16 | parameters: 17 | - $ref: ../../components/parameters.yaml#/debug-profile-seconds 18 | responses: 19 | '200': 20 | description: OK 21 | content: 22 | application/x-gzip: 23 | schema: 24 | type: string 25 | tags: 26 | - Profiling 27 | operationId: get__debug-fgprof 28 | post: 29 | summary: Get fgprof profile 30 | description: |- 31 | A sampling Go profiler that allows you to analyze On-CPU as well as [Off-CPU](https://www.brendangregg.com/offcpuanalysis.html) (e.g. I/O) time together. 32 | 33 | Required Sync Gateway RBAC roles: 34 | 35 | * Sync Gateway Dev Ops 36 | parameters: 37 | - $ref: ../../components/parameters.yaml#/debug-profile-seconds 38 | responses: 39 | '200': 40 | description: OK 41 | content: 42 | application/x-gzip: 43 | schema: 44 | type: string 45 | tags: 46 | - Profiling 47 | operationId: post__debug-fgprof 48 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_debug-pprof-cmdline.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get passed in command line parameters 10 | description: |- 11 | Gets the command line parameters that was passed in to Sync Gateway which will include the binary, flags (if any) and startup configuration. 12 | 13 | Required Sync Gateway RBAC roles: 14 | 15 | * Sync Gateway Dev Ops 16 | responses: 17 | '200': 18 | description: OK 19 | content: 20 | text/plain: 21 | schema: 22 | type: string 23 | tags: 24 | - Profiling 25 | operationId: get__debug-pprof-cmdline 26 | post: 27 | summary: Get passed in command line parameters 28 | description: |- 29 | Gets the command line parameters that was passed in to Sync Gateway which will include the binary, flags (if any) and startup configuration. 30 | 31 | Required Sync Gateway RBAC roles: 32 | 33 | * Sync Gateway Dev Ops 34 | responses: 35 | '200': 36 | description: OK 37 | content: 38 | text/plain: 39 | schema: 40 | type: string 41 | tags: 42 | - Profiling 43 | operationId: post__debug-pprof-cmdline 44 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_debug-pprof-goroutine.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get goroutine profile 10 | description: |- 11 | Stack traces of all current goroutines. 12 | 13 | Required Sync Gateway RBAC roles: 14 | 15 | * Sync Gateway Dev Ops 16 | parameters: 17 | - $ref: ../../components/parameters.yaml#/pprof-seconds 18 | responses: 19 | '200': 20 | $ref: ../../components/responses.yaml#/pprof-binary 21 | tags: 22 | - Profiling 23 | operationId: get__debug-pprof-goroutine 24 | post: 25 | summary: Get goroutine profile 26 | description: |- 27 | Stack traces of all current goroutines. 28 | 29 | Required Sync Gateway RBAC roles: 30 | 31 | * Sync Gateway Dev Ops 32 | parameters: 33 | - $ref: ../../components/parameters.yaml#/pprof-seconds 34 | responses: 35 | '200': 36 | $ref: ../../components/responses.yaml#/pprof-binary 37 | tags: 38 | - Profiling 39 | operationId: post__debug-pprof-goroutine 40 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_debug-pprof-heap.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get the heap pprof debug file 10 | description: |- 11 | Required Sync Gateway RBAC roles: 12 | 13 | * Sync Gateway Dev Ops 14 | parameters: 15 | - $ref: ../../components/parameters.yaml#/pprof-seconds 16 | responses: 17 | '200': 18 | $ref: ../../components/responses.yaml#/pprof-binary 19 | tags: 20 | - Profiling 21 | operationId: get__debug-pprof-heap 22 | post: 23 | summary: Get the heap pprof debug file 24 | description: |- 25 | Required Sync Gateway RBAC roles: 26 | 27 | * Sync Gateway Dev Ops 28 | parameters: 29 | - $ref: ../../components/parameters.yaml#/pprof-seconds 30 | responses: 31 | '200': 32 | $ref: ../../components/responses.yaml#/pprof-binary 33 | tags: 34 | - Profiling 35 | operationId: post__debug-pprof-heap 36 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_debug-pprof-profile.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get the profile pprof debug file 10 | description: |- 11 | Required Sync Gateway RBAC roles: 12 | 13 | * Sync Gateway Dev Ops 14 | parameters: 15 | - $ref: ../../components/parameters.yaml#/pprof-seconds 16 | responses: 17 | '200': 18 | $ref: ../../components/responses.yaml#/pprof-binary 19 | tags: 20 | - Profiling 21 | operationId: get__debug-pprof-profile 22 | post: 23 | summary: Get the profile pprof debug file 24 | description: |- 25 | Required Sync Gateway RBAC roles: 26 | 27 | * Sync Gateway Dev Ops 28 | parameters: 29 | - $ref: ../../components/parameters.yaml#/pprof-seconds 30 | responses: 31 | '200': 32 | $ref: ../../components/responses.yaml#/pprof-binary 33 | tags: 34 | - Profiling 35 | operationId: post__debug-pprof-profile 36 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_debug-pprof-symbol.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get symbol pprof debug information 10 | description: |- 11 | Required Sync Gateway RBAC roles: 12 | 13 | * Sync Gateway Dev Ops 14 | responses: 15 | '200': 16 | description: OK 17 | content: 18 | text/plain: 19 | schema: 20 | type: string 21 | tags: 22 | - Profiling 23 | operationId: get__debug-pprof-symbol 24 | post: 25 | summary: Get symbol pprof debug information 26 | description: |- 27 | Required Sync Gateway RBAC roles: 28 | 29 | * Sync Gateway Dev Ops 30 | responses: 31 | '200': 32 | description: OK 33 | content: 34 | text/plain: 35 | schema: 36 | type: string 37 | tags: 38 | - Profiling 39 | operationId: post__debug-pprof-symbol 40 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_debug-pprof-threadcreate.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get the threadcreate pprof debug file 10 | description: |- 11 | Required Sync Gateway RBAC roles: 12 | 13 | * Sync Gateway Dev Ops 14 | responses: 15 | '200': 16 | $ref: ../../components/responses.yaml#/pprof-binary 17 | tags: 18 | - Profiling 19 | operationId: get__debug-pprof-threadcreate 20 | post: 21 | summary: Get the threadcreate pprof debug file 22 | description: |- 23 | Required Sync Gateway RBAC roles: 24 | 25 | * Sync Gateway Dev Ops 26 | responses: 27 | '200': 28 | $ref: ../../components/responses.yaml#/pprof-binary 29 | tags: 30 | - Profiling 31 | operationId: post__debug-pprof-threadcreate 32 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_debug-pprof-trace.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get trace profile 10 | description: |- 11 | Responds with the execution trace in binary form. 12 | 13 | Required Sync Gateway RBAC roles: 14 | 15 | * Sync Gateway Dev Ops 16 | parameters: 17 | - name: seconds 18 | in: query 19 | schema: 20 | type: integer 21 | default: 1 22 | responses: 23 | '200': 24 | $ref: ../../components/responses.yaml#/pprof-binary 25 | tags: 26 | - Profiling 27 | operationId: get__debug-pprof-trace 28 | post: 29 | summary: Get trace profile 30 | description: |- 31 | Responds with the execution trace in binary form. 32 | 33 | Required Sync Gateway RBAC roles: 34 | 35 | * Sync Gateway Dev Ops 36 | parameters: 37 | - name: seconds 38 | in: query 39 | schema: 40 | type: integer 41 | default: 1 42 | responses: 43 | '200': 44 | $ref: ../../components/responses.yaml#/pprof-binary 45 | tags: 46 | - Profiling 47 | operationId: post__debug-pprof-trace 48 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_expvar.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2022-Present Couchbase, Inc. 3 | # 4 | # Use of this software is governed by the Business Source License included 5 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 6 | # in that file, in accordance with the Business Source License, use of this 7 | # software will be governed by the Apache License, Version 2.0, included in 8 | # the file licenses/APL2.txt. 9 | get: 10 | summary: Get all Sync Gateway statistics in JSON format 11 | description: |- 12 | This returns a snapshot of all metrics in Sync Gateway for debugging and monitoring purposes. 13 | 14 | This includes per database stats, replication stats, and server stats. 15 | 16 | Required Sync Gateway RBAC roles: 17 | 18 | * Sync Gateway Architect 19 | * Sync Gateway Dev Ops 20 | * External Stats Reader 21 | tags: 22 | - Metrics 23 | responses: 24 | $ref: ../../components/responses.yaml#/expvar_reponses 25 | operationId: get__expvar 26 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_heap.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | post: 9 | summary: Dump heap profile 10 | description: |- 11 | This endpoint will dump a pprof heap profile. 12 | 13 | Required Sync Gateway RBAC roles: 14 | 15 | * Sync Gateway Dev Ops 16 | requestBody: 17 | $ref: ../../components/requestBodies.yaml#/Profile 18 | responses: 19 | '200': 20 | description: Successfully dumped heap profile 21 | '400': 22 | $ref: ../../components/responses.yaml#/request-problem 23 | tags: 24 | - Profiling 25 | operationId: post__heap 26 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_profile-profilename.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - name: profilename 10 | in: path 11 | description: The handler to use for profiling. 12 | required: true 13 | schema: 14 | type: string 15 | enum: 16 | - heap 17 | - block 18 | - threadcreate 19 | - mutex 20 | - goroutine 21 | post: 22 | summary: Create point-in-time profile 23 | description: |- 24 | This endpoint allows you to create a pprof snapshot of the given type. 25 | 26 | Required Sync Gateway RBAC roles: 27 | 28 | * Sync Gateway Dev Ops 29 | requestBody: 30 | $ref: ../../components/requestBodies.yaml#/Profile 31 | responses: 32 | '200': 33 | description: Successfully created profile 34 | '400': 35 | $ref: ../../components/responses.yaml#/request-problem 36 | '404': 37 | $ref: ../../components/responses.yaml#/Not-found 38 | tags: 39 | - Profiling 40 | operationId: post__profile-profilename 41 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_profile.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | post: 9 | summary: Start or Stop continuous CPU profiling 10 | description: |- 11 | This endpoint allows you to start and stop continuous CPU profiling. 12 | 13 | To start profiling the CPU, call this endpoint and supply a file to output the pprof file to. 14 | 15 | To stop profiling, call this endpoint but don't supply the `file` in the body. 16 | 17 | Required Sync Gateway RBAC roles: 18 | 19 | * Sync Gateway Dev Ops 20 | requestBody: 21 | $ref: ../../components/requestBodies.yaml#/Profile 22 | responses: 23 | '200': 24 | description: Successfully started or stopped CPU profiling 25 | '400': 26 | $ref: ../../components/responses.yaml#/request-problem 27 | tags: 28 | - Profiling 29 | operationId: post__profile 30 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_stats.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get memory statistics 10 | description: |- 11 | This will return the current Sync Gateway nodes memory statistics such as current memory usage. 12 | 13 | Required Sync Gateway RBAC roles: 14 | 15 | * Sync Gateway Architect 16 | * Sync Gateway Dev Ops 17 | * External Stats Reader 18 | responses: 19 | '200': 20 | description: Returned memory usage statistics 21 | content: 22 | application/json: 23 | schema: 24 | type: object 25 | properties: 26 | memstats: 27 | description: A set of Go runtime memory statistics. 28 | additionalProperties: true 29 | tags: 30 | - Metrics 31 | operationId: get__stats 32 | -------------------------------------------------------------------------------- /docs/api/paths/admin/_status.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get the server status 10 | description: |- 11 | This will retrieve the status of each database and the overall server status. 12 | 13 | Required Sync Gateway RBAC roles: 14 | 15 | * Sync Gateway Dev Ops 16 | responses: 17 | '200': 18 | description: Returned the status successfully 19 | content: 20 | application/json: 21 | schema: 22 | $ref: ../../components/schemas.yaml#/Status 23 | '400': 24 | $ref: ../../components/responses.yaml#/request-problem 25 | tags: 26 | - Server 27 | operationId: get__status 28 | -------------------------------------------------------------------------------- /docs/api/paths/admin/db-_dump-view.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | - $ref: ../../components/parameters.yaml#/view 11 | get: 12 | summary: Dump a view | Unsupported 13 | description: |- 14 | **This is unsupported** 15 | 16 | This queries the view and outputs it as HTML. 17 | 18 | Required Sync Gateway RBAC roles: 19 | 20 | * Sync Gateway Application 21 | * Sync Gateway Application Read Only 22 | responses: 23 | '200': 24 | description: Retrieved view successfully 25 | content: 26 | text/html: 27 | schema: 28 | type: string 29 | '404': 30 | $ref: ../../components/responses.yaml#/Not-found 31 | '500': 32 | description: Internal Server Error 33 | content: 34 | application/json: 35 | schema: 36 | $ref: ../../components/schemas.yaml#/HTTP-Error 37 | tags: 38 | - Unsupported 39 | operationId: get_db-_dump-view 40 | -------------------------------------------------------------------------------- /docs/api/paths/admin/db-_flush.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | post: 11 | summary: Flush the entire database bucket | Unsupported 12 | description: |- 13 | **This is unsupported** 14 | 15 | This will purge *all* documents. 16 | 17 | The bucket will only be flushed if the unsupported database configuration option `enable_couchbase_bucket_flush` is set. 18 | 19 | Required Sync Gateway RBAC roles: 20 | 21 | * Sync Gateway Dev Ops 22 | responses: 23 | '200': 24 | description: Successfully flushed the bucket 25 | '404': 26 | $ref: ../../components/responses.yaml#/Not-found 27 | '503': 28 | description: The bucket does not support flush or delete 29 | content: 30 | application/json: 31 | schema: 32 | $ref: ../../components/schemas.yaml#/HTTP-Error 33 | tags: 34 | - Unsupported 35 | operationId: post_db-_flush 36 | -------------------------------------------------------------------------------- /docs/api/paths/admin/db-_oidc.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | get: 11 | summary: OpenID Connect authentication initiation via Location header redirect 12 | description: 'Called by clients to initiate the OpenID Connect Authorization Code Flow. Redirects to the OpenID Connect provider if successful. ' 13 | parameters: 14 | - $ref: ../../components/parameters.yaml#/provider 15 | - $ref: ../../components/parameters.yaml#/offline 16 | responses: 17 | '302': 18 | description: Successfully connected with the OpenID Connect provider so now redirecting to the requested OIDC provider for authentication. 19 | headers: 20 | Location: 21 | schema: 22 | type: string 23 | description: The link to redirect to so the client can authenticate. 24 | '400': 25 | $ref: ../../components/responses.yaml#/OIDC-invalid-provider 26 | '404': 27 | $ref: ../../components/responses.yaml#/Not-found 28 | '500': 29 | $ref: ../../components/responses.yaml#/OIDC-connection 30 | tags: 31 | - Authentication 32 | operationId: get_db-_oidc 33 | -------------------------------------------------------------------------------- /docs/api/paths/admin/db-_oidc_challenge.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | get: 11 | summary: OpenID Connect authentication initiation via WWW-Authenticate header 12 | description: 'Called by clients to initiate the OpenID Connect Authorization Code Flow. This will establish a connection with the provider, then put the redirect URL in the `WWW-Authenticate` header.' 13 | parameters: 14 | - $ref: ../../components/parameters.yaml#/provider 15 | - $ref: ../../components/parameters.yaml#/offline 16 | responses: 17 | '400': 18 | description: 'The provider provided is not defined in the Sync Gateway config. If no provided was specified then there is no default provider set. ' 19 | '401': 20 | description: Successfully connected with the OpenID Connect provider so now the client can login. 21 | headers: 22 | WWW-Authenticate: 23 | schema: 24 | type: string 25 | description: The OpenID Connect authentication URL. 26 | '404': 27 | $ref: ../../components/responses.yaml#/Not-found 28 | '500': 29 | description: Unable to connect and validate with the OpenID Connect provider requested 30 | tags: 31 | - Authentication 32 | operationId: get_db-_oidc_challenge 33 | -------------------------------------------------------------------------------- /docs/api/paths/admin/db-_oidc_refresh.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | get: 11 | summary: OpenID Connect token refresh 12 | description: Refresh the OpenID Connect token based on the provided refresh token. 13 | parameters: 14 | - name: refresh_token 15 | in: query 16 | description: The OpenID Connect refresh token. 17 | required: true 18 | schema: 19 | type: string 20 | - $ref: ../../components/parameters.yaml#/provider 21 | responses: 22 | '200': 23 | $ref: ../../components/responses.yaml#/OIDC-callback 24 | '400': 25 | $ref: ../../components/responses.yaml#/OIDC-invalid-provider 26 | '404': 27 | $ref: ../../components/responses.yaml#/Not-found 28 | '500': 29 | $ref: ../../components/responses.yaml#/OIDC-connection 30 | tags: 31 | - Authentication 32 | operationId: get_db-_oidc_refresh 33 | -------------------------------------------------------------------------------- /docs/api/paths/admin/db-_repair.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | post: 11 | summary: 'Disabled endpoint' 12 | description: |- 13 | This endpoint is disabled. 14 | 15 | Required Sync Gateway RBAC roles: 16 | 17 | * Sync Gateway Architect 18 | responses: 19 | '500': 20 | description: This endpoint is disabled 21 | tags: 22 | - Unsupported 23 | operationId: post_db-_repair 24 | -------------------------------------------------------------------------------- /docs/api/paths/admin/db-_replicationStatus-.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | get: 11 | summary: Get all replication statuses 12 | description: |- 13 | Retrieve all the replication statuses in the Sync Gateway node. 14 | 15 | Required Sync Gateway RBAC roles: 16 | 17 | * Sync Gateway Replicator 18 | parameters: 19 | - $ref: ../../components/parameters.yaml#/replication-active-only 20 | - $ref: ../../components/parameters.yaml#/replication-local-only 21 | - $ref: ../../components/parameters.yaml#/replication-include-error 22 | - $ref: ../../components/parameters.yaml#/replication-include-config 23 | responses: 24 | '200': 25 | description: Successfully retrieved all replication statuses. 26 | content: 27 | application/json: 28 | schema: 29 | type: array 30 | items: 31 | $ref: ../../components/schemas.yaml#/Replication-status 32 | '400': 33 | $ref: ../../components/responses.yaml#/request-problem 34 | tags: 35 | - Replication 36 | operationId: get_db-_replicationStatus- 37 | -------------------------------------------------------------------------------- /docs/api/paths/admin/db-_user-name-_session-sessionid.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | - $ref: ../../components/parameters.yaml#/user-name 11 | - $ref: ../../components/parameters.yaml#/sessionid 12 | delete: 13 | summary: Remove session with user validation 14 | description: |- 15 | Invalidates the session only if it belongs to the user. 16 | 17 | Required Sync Gateway RBAC roles: 18 | 19 | * Sync Gateway Architect 20 | * Sync Gateway Application 21 | responses: 22 | '200': 23 | description: Session has been successfully removed as the user was associated with the session 24 | '404': 25 | $ref: ../../components/responses.yaml#/Not-found 26 | tags: 27 | - Session 28 | operationId: delete_db-_user-name-_session-sessionid 29 | -------------------------------------------------------------------------------- /docs/api/paths/admin/db-_user-name-_session.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | - $ref: ../../components/parameters.yaml#/user-name 11 | delete: 12 | summary: Remove all of a users sessions 13 | description: |- 14 | Invalidates all the sessions that a user has. 15 | 16 | Will still return a `200` status code if the user has no sessions. 17 | 18 | Required Sync Gateway RBAC roles: 19 | 20 | * Sync Gateway Architect 21 | * Sync Gateway Application 22 | responses: 23 | '200': 24 | description: User now has no sessions 25 | '404': 26 | $ref: ../../components/responses.yaml#/Not-found 27 | tags: 28 | - Session 29 | operationId: delete_db-_user-name-_session 30 | -------------------------------------------------------------------------------- /docs/api/paths/common/_ping.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2023-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Check if API is available 10 | description: Returns OK status if API is available. 11 | responses: 12 | '200': 13 | description: Returned status 14 | content: 15 | text/plain: 16 | schema: 17 | type: string 18 | example: "OK" 19 | tags: 20 | - Server 21 | operationId: get__ping 22 | -------------------------------------------------------------------------------- /docs/api/paths/common/db-_ensure_full_commit.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | post: 11 | summary: Ensure Full Commit 12 | description: |- 13 | This endpoint is non-functional but is present for CouchDB compatibility. This was deprecated in CouchDB 3.0. 14 | 15 | Required Sync Gateway RBAC roles: 16 | 17 | * Sync Gateway Application 18 | * Sync Gateway Application Read Only 19 | deprecated: true 20 | responses: 21 | '201': 22 | description: OK 23 | content: 24 | application/json: 25 | schema: 26 | type: object 27 | properties: 28 | instance_start_time: 29 | description: 'Timestamp of when the database opened, in microseconds since the Unix epoch.' 30 | type: integer 31 | example: 1644600082279583 32 | ok: 33 | type: boolean 34 | example: true 35 | default: true 36 | tags: 37 | - Database Management 38 | operationId: post_db-_ensure_full_commit 39 | -------------------------------------------------------------------------------- /docs/api/paths/diagnostic/db-_user-name-_all_channels.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | - $ref: ../../components/parameters.yaml#/user-name 11 | get: 12 | summary: Get all channels for a user 13 | description: |- 14 | Retrieve all channels that a user has access to. 15 | 16 | Required Sync Gateway RBAC roles: 17 | 18 | * Sync Gateway Architect 19 | * Sync Gateway Application 20 | * Sync Gateway Application Read Only 21 | responses: 22 | '200': 23 | $ref: ../../components/responses.yaml#/All_user_channels_response 24 | '404': 25 | $ref: ../../components/responses.yaml#/Not-found 26 | tags: 27 | - Database Security 28 | operationId: get_db-_user-name_-all_channels 29 | -------------------------------------------------------------------------------- /docs/api/paths/diagnostic/keyspace-_user-name.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/keyspace 10 | - $ref: ../../components/parameters.yaml#/user-name 11 | get: 12 | summary: Get all document access spans. 13 | description: |- 14 | Retrieve all sequence spans where a user had access to a list of documents. 15 | The spans are in the form of start sequence - end sequence. 16 | 17 | Required Sync Gateway RBAC roles: 18 | 19 | * Sync Gateway Architect 20 | * Sync Gateway Application 21 | * Sync Gateway Application Read Only 22 | parameters: 23 | - $ref: ../../components/parameters.yaml#/doc_id 24 | responses: 25 | '200': 26 | $ref: ../../components/responses.yaml#/user_access_span_response 27 | '400': 28 | description: Bad Request 29 | '404': 30 | $ref: ../../components/responses.yaml#/Not-found 31 | tags: 32 | - Database Security 33 | operationId: get_keyspace-_user-name 34 | -------------------------------------------------------------------------------- /docs/api/paths/diagnostic/keyspace-docid-_all_channels.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/keyspace 10 | - $ref: ../../components/parameters.yaml#/docid 11 | get: 12 | summary: Get channel history for a document 13 | description: |- 14 | Retrieve all doc channels and the sequence spans showing when the doc was added to a channel and when it was removed. 15 | Required Sync Gateway RBAC roles: 16 | * Sync Gateway Application Read Only 17 | responses: 18 | '200': 19 | description: Document found successfully 20 | content: 21 | application/json: 22 | schema: 23 | additionalProperties: 24 | x-additionalPropertiesName: channel 25 | description: The channels the document has been in. 26 | type: array 27 | items: 28 | description: The sequence number that document was added to the channel. 29 | type: string 30 | example: "28-48" 31 | 32 | '404': 33 | $ref: ../../components/responses.yaml#/Not-found 34 | tags: 35 | - Document 36 | operationId: get_keyspace-docid-_all_channels 37 | -------------------------------------------------------------------------------- /docs/api/paths/metric/_expvar.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2022-Present Couchbase, Inc. 3 | # 4 | # Use of this software is governed by the Business Source License included 5 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 6 | # in that file, in accordance with the Business Source License, use of this 7 | # software will be governed by the Apache License, Version 2.0, included in 8 | # the file licenses/APL2.txt. 9 | get: 10 | summary: Get all Sync Gateway statistics in JSON format 11 | description: |- 12 | This returns a snapshot of all metrics in Sync Gateway for debugging and monitoring purposes. 13 | 14 | This includes per database stats, replication stats, and server stats. 15 | 16 | Required Sync Gateway RBAC roles: 17 | 18 | * Sync Gateway Architect 19 | * Sync Gateway Dev Ops 20 | * External Stats Reader 21 | tags: 22 | - JSON 23 | responses: 24 | $ref: ../../components/responses.yaml#/expvar_reponses 25 | operationId: get__expvar 26 | -------------------------------------------------------------------------------- /docs/api/paths/metric/metrics.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get debugging and monitoring runtime stats in Prometheus Exposition format 10 | description: |- 11 | Returns Sync Gateway statistics and other runtime variables in Prometheus Exposition format. 12 | 13 | Required Sync Gateway RBAC roles: 14 | 15 | * Sync Gateway Architect 16 | * Sync Gateway Dev Ops 17 | * External Stats Reader 18 | responses: 19 | '200': 20 | description: |- 21 | Successfully returned statistics. 22 | For details, see [Prometheus Metrics](stats-monitoring-prometheus.html). 23 | tags: 24 | - Prometheus 25 | operationId: get_metrics 26 | -------------------------------------------------------------------------------- /docs/api/paths/public/-.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | get: 9 | summary: Get server information 10 | description: Returns information about the Sync Gateway node. 11 | responses: 12 | '200': 13 | description: Returned server information 14 | content: 15 | application/json: 16 | schema: 17 | $ref: ../../components/schemas.yaml#/NodeInfo 18 | tags: 19 | - Server 20 | operationId: get_- 21 | head: 22 | responses: 23 | '200': 24 | description: Server is online 25 | tags: 26 | - Server 27 | summary: Check if server online 28 | description: Check if the server is online by checking the status code of response. 29 | operationId: head_- 30 | -------------------------------------------------------------------------------- /docs/api/paths/public/db-_oidc.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | get: 11 | summary: OpenID Connect authentication initiation via Location header redirect 12 | description: 'Called by clients to initiate the OpenID Connect Authorization Code Flow. Redirects to the OpenID Connect provider if successful. ' 13 | parameters: 14 | - $ref: ../../components/parameters.yaml#/provider 15 | - $ref: ../../components/parameters.yaml#/offline 16 | responses: 17 | '302': 18 | description: Successfully connected with the OpenID Connect provider so now redirecting to the requested OIDC provider for authentication. 19 | headers: 20 | Location: 21 | schema: 22 | type: string 23 | description: The link to redirect to so the client can authenticate. 24 | '400': 25 | $ref: ../../components/responses.yaml#/OIDC-invalid-provider 26 | '404': 27 | $ref: ../../components/responses.yaml#/Not-found 28 | '500': 29 | $ref: ../../components/responses.yaml#/OIDC-connection 30 | tags: 31 | - Authentication 32 | operationId: get_db-_oidc 33 | -------------------------------------------------------------------------------- /docs/api/paths/public/db-_oidc_challenge.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | get: 11 | summary: OpenID Connect authentication initiation via WWW-Authenticate header 12 | description: 'Called by clients to initiate the OpenID Connect Authorization Code Flow. This will establish a connection with the provider, then put the redirect URL in the `WWW-Authenticate` header.' 13 | parameters: 14 | - $ref: ../../components/parameters.yaml#/provider 15 | - $ref: ../../components/parameters.yaml#/offline 16 | responses: 17 | '400': 18 | description: 'The provider provided is not defined in the Sync Gateway config. If no provided was specified then there is no default provider set. ' 19 | '401': 20 | description: Successfully connected with the OpenID Connect provider so now the client can login. 21 | headers: 22 | WWW-Authenticate: 23 | schema: 24 | type: string 25 | description: The OpenID Connect authentication URL. 26 | '404': 27 | $ref: ../../components/responses.yaml#/Not-found 28 | '500': 29 | description: Unable to connect and validate with the OpenID Connect provider requested 30 | tags: 31 | - Authentication 32 | operationId: get_db-_oidc_challenge 33 | -------------------------------------------------------------------------------- /docs/api/paths/public/db-_oidc_refresh.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - $ref: ../../components/parameters.yaml#/db 10 | get: 11 | summary: OpenID Connect token refresh 12 | description: Refresh the OpenID Connect token based on the provided refresh token. 13 | parameters: 14 | - name: refresh_token 15 | in: query 16 | description: The OpenID Connect refresh token. 17 | required: true 18 | schema: 19 | type: string 20 | - $ref: ../../components/parameters.yaml#/provider 21 | responses: 22 | '200': 23 | $ref: ../../components/responses.yaml#/OIDC-callback 24 | '400': 25 | $ref: ../../components/responses.yaml#/OIDC-invalid-provider 26 | '404': 27 | $ref: ../../components/responses.yaml#/Not-found 28 | '500': 29 | $ref: ../../components/responses.yaml#/OIDC-connection 30 | tags: 31 | - Authentication 32 | operationId: get_db-_oidc_refresh 33 | -------------------------------------------------------------------------------- /docs/api/paths/public/targetdb-.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | parameters: 9 | - name: targetdb 10 | in: path 11 | description: The database name to target. 12 | required: true 13 | schema: 14 | type: string 15 | put: 16 | summary: Create DB public API stub 17 | description: 'A stub that always returns an error on the Public API, for createTarget/CouchDB compatibility.' 18 | responses: 19 | '403': 20 | description: Database does not exist and cannot be created over the public API 21 | '412': 22 | description: Database exists 23 | tags: 24 | - Database Management 25 | operationId: put_targetdb- 26 | -------------------------------------------------------------------------------- /docs/api/plugins/decorators/excise-rbac-capella.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024-Present Couchbase, Inc. 3 | * 4 | * Use of this software is governed by the Business Source License included 5 | * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 6 | * in that file, in accordance with the Business Source License, use of this 7 | * software will be governed by the Apache License, Version 2.0, included in 8 | * the file licenses/APL2.txt. 9 | */ 10 | 11 | /** 12 | * Removes the RBAC roles from capella API docs. This expects the RBAC information to be at the end of the documentation string. This is not a robust way of doing this. 13 | * @module ExciseRBACCapella 14 | */ 15 | 16 | module.exports = ExciseRBACCapella; 17 | 18 | const re = new RegExp("Required Sync Gateway RBAC roles"); 19 | 20 | /** @type {import('@redocly/cli').OasDecorator} */ 21 | function ExciseRBACCapella() { 22 | return { 23 | Operation: { 24 | leave(Operation) { 25 | // remove all text after first regex match 26 | idx = (Operation.description || '').search(re); 27 | if (idx > 0) { 28 | Operation.description = Operation.description.substr(0, idx); 29 | } 30 | }, 31 | }, 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /docs/api/plugins/decorators/replace-description-capella.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024-Present Couchbase, Inc. 3 | * 4 | * Use of this software is governed by the Business Source License included 5 | * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 6 | * in that file, in accordance with the Business Source License, use of this 7 | * software will be governed by the Apache License, Version 2.0, included in 8 | * the file licenses/APL2.txt. 9 | */ 10 | 11 | /** 12 | * Does a string replacement on all operations (GET,PUT,POST,etc) to replace Sync Gateway with App Services. 13 | * @module ReplaceDescriptionCapella 14 | */ 15 | 16 | module.exports = ReplaceDescriptionCapella; 17 | 18 | /** @type {import('@redocly/cli').OasDecorator} */ 19 | function ReplaceDescriptionCapella() { 20 | return { 21 | Operation: { 22 | leave(Operation) { 23 | if (Operation.description) { 24 | Operation.description = Operation.description.replace( 25 | "Sync Gateway", 26 | "App Services", 27 | ); 28 | } 29 | }, 30 | }, 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /docs/api/plugins/decorators/replace-server-capella.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024-Present Couchbase, Inc. 3 | * 4 | * Use of this software is governed by the Business Source License included 5 | * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 6 | * in that file, in accordance with the Business Source License, use of this 7 | * software will be governed by the Apache License, Version 2.0, included in 8 | * the file licenses/APL2.txt. 9 | */ 10 | 11 | module.exports = ReplaceServersCapella; 12 | 13 | /** @type {import('@redocly/cli').OasDecorator} */ 14 | function ReplaceServersCapella({ serverUrl }) { 15 | return { 16 | Server: { 17 | leave(Server) { 18 | if (serverUrl) { 19 | Server.url = serverUrl; 20 | } 21 | }, 22 | }, 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /docs/api/plugins/plugin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024-Present Couchbase, Inc. 3 | * 4 | * Use of this software is governed by the Business Source License included 5 | * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 6 | * in that file, in accordance with the Business Source License, use of this 7 | * software will be governed by the Apache License, Version 2.0, included in 8 | * the file licenses/APL2.txt. 9 | */ 10 | 11 | const ExciseRBACCapella = require("./decorators/excise-rbac-capella.js"); 12 | const ReplaceDescriptionCapella = require("./decorators/replace-description-capella.js"); 13 | const ReplaceServerCapella = require("./decorators/replace-server-capella.js"); 14 | 15 | module.exports = { 16 | decorators: { 17 | oas3: { 18 | "excise-rbac-capella": ExciseRBACCapella, 19 | "replace-description-capella": ReplaceDescriptionCapella, 20 | "replace-server-capella": ReplaceServerCapella, 21 | }, 22 | }, 23 | id: "plugin", 24 | }; 25 | -------------------------------------------------------------------------------- /docs/api/plugins/rules.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2025-Present Couchbase, Inc. 3 | * 4 | * Use of this software is governed by the Business Source License included 5 | * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 6 | * in that file, in accordance with the Business Source License, use of this 7 | * software will be governed by the Apache License, Version 2.0, included in 8 | * the file licenses/APL2.txt. 9 | */ 10 | 11 | const TypeCheckDefaults = require("./rules/typecheck-defaults.js"); 12 | const CheckAdditionalPropertiesNames = require("./rules/check-additional-properties-names.js"); 13 | 14 | module.exports = { 15 | rules: { 16 | oas3: { 17 | "typecheck-defaults": TypeCheckDefaults, 18 | "check-additional-properties-names": CheckAdditionalPropertiesNames, 19 | }, 20 | }, 21 | id: "custom-rules", 22 | }; 23 | -------------------------------------------------------------------------------- /docs/api/plugins/rules/check-additional-properties-names.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2025-Present Couchbase, Inc. 3 | * 4 | * Use of this software is governed by the Business Source License included 5 | * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 6 | * in that file, in accordance with the Business Source License, use of this 7 | * software will be governed by the Apache License, Version 2.0, included in 8 | * the file licenses/APL2.txt. 9 | */ 10 | 11 | module.exports = CheckAdditionalPropertiesNames; 12 | 13 | function CheckAdditionalPropertiesNames() { 14 | return { 15 | Schema: { 16 | enter(schema, ctx) { 17 | props = schema.additionalProperties; 18 | if (props === undefined) { 19 | return; 20 | } 21 | // additionalProperties: true or additionalProperties: {} is valid openapi 22 | if (Object.keys(props).length === 0) { 23 | return; 24 | } 25 | // x-additionalPropertiesName is a redocly extension used to provide example map values 26 | if ( 27 | props["x-additionalPropertiesName"] === undefined && 28 | schema.example === undefined 29 | ) { 30 | ctx.report({ 31 | message: `additionalProperties should also include x-additionalPropertiesName or an example to show a meaningful name for generating examples.`, 32 | }); 33 | } 34 | }, 35 | }, 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /docs/api/replace-servers-capella.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024-Present Couchbase, Inc. 3 | * 4 | * Use of this software is governed by the Business Source License included 5 | * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 6 | * in that file, in accordance with the Business Source License, use of this 7 | * software will be governed by the Apache License, Version 2.0, included in 8 | * the file licenses/APL2.txt. 9 | */ 10 | 11 | module.exports = ReplaceServersCapella; 12 | 13 | /** @type {import('@redocly/cli').OasDecorator} */ 14 | 15 | function ReplaceServersCapella({ serverUrl }) { 16 | return { 17 | Server: { 18 | leave(Server) { 19 | Server.url = serverUrl; 20 | delete Server.protocol; 21 | }, 22 | }, 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /docs/design/cache/README.md: -------------------------------------------------------------------------------- 1 | ##Remote Change Cache 2 | 3 | The primary goal of the distributed cache implementation for Sync Gateway is to provide an 4 | alternative to the existing in-memory change cache. The existing cache requires each Sync Gateway 5 | node to process every mutation occuring on the Couchbase Server bucket. The intention of the distributed 6 | cache is to increase the scaling capacity of a Sync Gateway cluster. 7 | 8 | ###Limitations of Current Approach 9 | - [multiple feeds cause server perf problems] 10 | - [each node must process full feed - "DDOS" - results in a cap on throughput] 11 | 12 | ###Goals 13 | 14 | - **Scale Out Sync Gateway** – Ability to scale out Sync Gateway capacity by adding additional nodes to the cluster. 15 | - **Reduce Couchbase Server Overhead** – Add additional Sync Gateway nodes to the cluster without requiring the Couchbase Server to provide additional TAP/DCP feeds 16 | - **Replication Consistency** – Consistent sequence handling to ensure replication stability and consistency 17 | 18 | ###Components 19 | - **[Cache Overview](cache_overview.md)** 20 | 21 | ###Implementations 22 | - **[Single Writer Cache](single_writer.md)** - A remote cache with a single cache writer, multiple cache readers 23 | - **[Multi-writer Cache](multi_writer.md)** - Multi-writer cache 24 | 25 | -------------------------------------------------------------------------------- /docs/design/cache/multi_writer_dcp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbase/sync_gateway/cde6f6789baf97833e56961ca761fdfff6bc8457/docs/design/cache/multi_writer_dcp.png -------------------------------------------------------------------------------- /docs/design/cache/multi_writer_projector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbase/sync_gateway/cde6f6789baf97833e56961ca761fdfff6bc8457/docs/design/cache/multi_writer_projector.png -------------------------------------------------------------------------------- /docs/design/cache/single_writer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbase/sync_gateway/cde6f6789baf97833e56961ca761fdfff6bc8457/docs/design/cache/single_writer.png -------------------------------------------------------------------------------- /docs/design/channel_index/feed_management.md: -------------------------------------------------------------------------------- 1 | ##Feed Partition/Management 2 | 3 | Each Sync Gateway node will be assigned a subset of vbuckets - call this set of vbuckets a **partition**. 4 | 5 | The number of partitions defined will be a configurable setting, defined for the cluster. The number of partitions should be greater than the number of Sync Gateway nodes initially in the cluster, to support future scale out. More detailed performance testing is required to identify the recommended partition values. 6 | 7 | Each Sync Gateway node is given responsibility for one or more partitions. When establishing it's DCP feed, a Sync Gateway node will start streams for each vbucket it is responsible for. 8 | 9 | ###Milestone 1 10 | 11 | The number of partitions for the cluster will be fixed at 64. Each of the Sync Gateway nodes will be assigned partitions in its config file. For this milestone, partitions will simply be made up of a continuous sequence of vbuckets - e.g. partition 0 represent vbuckets 0 through 15. When the partition assignment is moved out of the Sync Gateway config in future revisions, it will also be possible to define something other than a sequential range of vbuckets as a partition. 12 | 13 | ``` 14 | {"partitions": [0,1,2,3,4,5,6,7,8,9]} 15 | ``` 16 | 17 | Each Sync Gateway will start a DCP feed, and start streams for each vbucket in each of their partitions. 18 | 19 | This milestone should also include support for handling a the case where a vbucket stream is closed by the CBS cluster. Sync Gateway will attempt to reopen the stream at the last stable sequence for that vbucket and continue processing. 20 | 21 | -------------------------------------------------------------------------------- /docs/design/channel_index/index_reads.md: -------------------------------------------------------------------------------- 1 | ##Reading the Index -------------------------------------------------------------------------------- /docs/modules/ROOT/_attributes.adoc: -------------------------------------------------------------------------------- 1 | :imagesdir: {moduledir}/assets/images -------------------------------------------------------------------------------- /docs/modules/ROOT/assets/images/admin-ui-getting-started.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbase/sync_gateway/cde6f6789baf97833e56961ca761fdfff6bc8457/docs/modules/ROOT/assets/images/admin-ui-getting-started.png -------------------------------------------------------------------------------- /docs/modules/ROOT/assets/images/windows-installation-complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbase/sync_gateway/cde6f6789baf97833e56961ca761fdfff6bc8457/docs/modules/ROOT/assets/images/windows-installation-complete.png -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/_attributes.adoc: -------------------------------------------------------------------------------- 1 | :moduledir: .. 2 | include::{moduledir}/_attributes.adoc[] -------------------------------------------------------------------------------- /examples/database_config/collections-with-custom-scope.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db", 3 | "bucket": "bucket", 4 | "scopes" : { 5 | "scope1": { 6 | "collections": { 7 | "collection1" : { 8 | "sync": ` 9 | function(doc, oldDoc, meta) { 10 | if (doc.type != "default") { 11 | throw({forbidden : "Rejected document"}) 12 | } 13 | channel("legacy") 14 | } 15 | `, 16 | "import_filter": ` 17 | function(doc) { 18 | return doc.type == "mobile" 19 | } 20 | ` 21 | }, 22 | "collection2" : { 23 | "sync": ` 24 | function(doc, oldDoc, meta) { 25 | channel("collection1") 26 | } 27 | `, 28 | "import_filter": ` 29 | function(doc) { 30 | return doc.type == "mobile" 31 | } 32 | ` 33 | } 34 | } 35 | } 36 | }, 37 | "num_index_replicas": 0 38 | } 39 | -------------------------------------------------------------------------------- /examples/database_config/collections-with-default-collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db", 3 | "bucket": "bucket", 4 | "scopes" : { 5 | "_default": { 6 | "collections": { 7 | "_default" : { 8 | "sync": ` 9 | function(doc, oldDoc, meta) { 10 | if (doc.collection != "default") { 11 | throw({forbidden : "Rejected document"}) 12 | } 13 | channel("legacy") 14 | } 15 | `, 16 | "import_filter": ` 17 | function(doc) { 18 | return doc.type == "mobile" 19 | } 20 | ` 21 | }, 22 | "collection1" : { 23 | "sync": ` 24 | function(doc, oldDoc, meta) { 25 | channel("collection1") 26 | } 27 | `, 28 | "import_filter": ` 29 | function(doc) { 30 | return doc.type == "mobile" 31 | } 32 | ` 33 | } 34 | } 35 | } 36 | }, 37 | "num_index_replicas": 0 38 | } 39 | -------------------------------------------------------------------------------- /examples/database_config/ee-basic-delta-sync.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db", 3 | "bucket": "default", 4 | "delta_sync": { 5 | "enabled": true, 6 | "rev_max_age_seconds": 86400 7 | }, 8 | "revs_limit": 20, 9 | "allow_conflicts": false, 10 | "num_index_replicas": 0 11 | } -------------------------------------------------------------------------------- /examples/database_config/ee-cache-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db", 3 | "bucket": "default", 4 | "cache": { 5 | "rev_cache": { 6 | "size": 5000, 7 | "shard_count": 8 8 | }, 9 | "channel_cache": { 10 | "max_number": 50000, 11 | "compact_high_watermark_pct": 80, 12 | "compact_low_watermark_pct": 60, 13 | "max_wait_pending": 5, 14 | "max_num_pending": 10000, 15 | "max_wait_skipped": 60, 16 | "enable_star_channel": true, 17 | "max_length": 500, 18 | "min_length": 50, 19 | "expiry_seconds": 60 20 | } 21 | }, 22 | "revs_limit": 20, 23 | "allow_conflicts": false, 24 | "num_index_replicas": 0 25 | } -------------------------------------------------------------------------------- /examples/database_config/events-webhook.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db", 3 | "bucket": "default", 4 | "event_handlers": { 5 | "max_processes": 500, 6 | "wait_for_process": "100", 7 | "document_changed": [ 8 | { 9 | "handler": "webhook", 10 | "url": "http://localhost:8081/my_webhook_target", 11 | "filter": 12 | ` 13 | function(doc) { 14 | if (doc._id.indexOf('webhooktest') >= 0) { 15 | return true; 16 | } 17 | return false; 18 | } 19 | ` 20 | } 21 | ] 22 | }, 23 | "revs_limit": 20, 24 | "allow_conflicts": false, 25 | "num_index_replicas": 0 26 | } -------------------------------------------------------------------------------- /examples/database_config/import-filter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db", 3 | "bucket": "default", 4 | "import_docs": true, 5 | "import_filter": 6 | ` 7 | function(doc) { 8 | if (doc.type != "mobile") { 9 | return false 10 | } 11 | return true 12 | } 13 | `, 14 | "revs_limit": 20, 15 | "allow_conflicts": false, 16 | "num_index_replicas": 0 17 | } -------------------------------------------------------------------------------- /examples/database_config/openid-connect.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db", 3 | "bucket": "default", 4 | "oidc": { 5 | "default_provider": "google", 6 | "providers": { 7 | "google": { 8 | "issuer": "https://accounts.google.com", 9 | "register": true, 10 | "client_id": "YOUR_CLIENT_ID", 11 | "validation_key": "YOUR_CLIENT_SECRET", 12 | "callback_url": "http://localhost:4984/default/_oidc_callback" 13 | } 14 | } 15 | }, 16 | "revs_limit": 20, 17 | "allow_conflicts": false, 18 | "num_index_replicas": 0 19 | } -------------------------------------------------------------------------------- /examples/database_config/sync-function.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "db", 3 | "bucket": "default", 4 | "sync": 5 | ` 6 | function(doc, oldDoc) { 7 | if (doc.type == "reject_me") { 8 | throw({forbidden : "Rejected document"}) 9 | } else if (doc.type == "bar") { 10 | // add "bar" docs to the "important" channel 11 | channel("important") 12 | } else if (doc.type == "secret") { 13 | if (!doc.owner) { 14 | throw({forbidden : "Secret documents must have an owner field"}) 15 | } 16 | } else { 17 | // all other documents just go into all channels listed in the doc["channels"] field 18 | channel(doc.channels) 19 | 20 | // Expire documents based on document "expiry" property 21 | expiry(doc.expiry) 22 | } 23 | } 24 | `, 25 | "revs_limit": 20, 26 | "allow_conflicts": false, 27 | "num_index_replicas": 0 28 | } -------------------------------------------------------------------------------- /examples/grafana/README.md: -------------------------------------------------------------------------------- 1 | # Sync Gateway Grafana Dashboard # 2 | 3 | The provided dashboard.json is Grafana compatible out-of-the-box and can be imported into a Grafana environment directly. 4 | 5 | In order to aid in the process of setting this up a makefile was made which should make the process easier. 6 | 7 | --- 8 | Dev setup: 9 | ``` 10 | make grafana-dev 11 | ``` 12 | The above command will attempt to upload the dashboard.json file to a Grafana instance which is expected to be running on localhost:3000 13 | 14 | --- 15 | 16 | If one is unable to run the makefile, the steps can be performed manually. `make grafana-dev` simply uploads the dashboard.json file to localhost:3000 (requires Grafana instance to be active over that address) - This requires a couple of operations to be performed which can be found in `install_grafana.sh` 17 | -------------------------------------------------------------------------------- /examples/grafana/install_grafana.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2020-Present Couchbase, Inc. 4 | # 5 | # Use of this software is governed by the Business Source License included in 6 | # the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 7 | # file, in accordance with the Business Source License, use of this software 8 | # will be governed by the Apache License, Version 2.0, included in the file 9 | # licenses/APL2.txt. 10 | 11 | set -eo pipefail 12 | echo 13 | echo "grafana: making sure Prometheus is a data source" 14 | curl -fu admin:admin 'http://localhost:3000/api/datasources/id/Prometheus' || 15 | curl -fu admin:admin -XPOST 'http://localhost:3000/api/datasources' \ 16 | -H 'Content-Type: application/json;charset=UTF-8' \ 17 | --data-binary '{ 18 | "name": "Prometheus", 19 | "isDefault": true, 20 | "type": "prometheus", 21 | "url": "http://prometheus:9090", 22 | "access": "proxy", 23 | "basicAuth": false 24 | }' 25 | 26 | echo 27 | echo 28 | echo "grafana: install/overwrite dashboard" 29 | curl -fu admin:admin 'http://localhost:3000/api/dashboards/db' \ 30 | -H 'Accept: application/json' \ 31 | -H 'Content-Type: application/json' \ 32 | --data-binary @<( echo "{\"overwrite\": true, \"dashboard\": $(cat ./dashboard.json)}" | jq . ) 33 | -------------------------------------------------------------------------------- /examples/grafana/makefile: -------------------------------------------------------------------------------- 1 | grafana-dev: 2 | @./install_grafana.sh 3 | .PHONY: grafana-dev 4 | -------------------------------------------------------------------------------- /examples/legacy_config/basic-couchbase-bucket.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "logging": { 4 | "console": { 5 | "log_keys": ["*"] 6 | } 7 | }, 8 | "databases": { 9 | "db": { 10 | "server": "couchbase://localhost", 11 | "username": "username", 12 | "password": "password", 13 | "bucket": "default", 14 | "users": { "GUEST": { "disabled": false, "admin_channels": ["*"] } }, 15 | "allow_conflicts": false, 16 | "revs_limit": 20, 17 | "num_index_replicas": 0 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/legacy_config/basic-sync-function.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "logging": { 4 | "console": { 5 | "log_keys": ["*"] 6 | } 7 | }, 8 | "databases": { 9 | "db": { 10 | "server": "couchbase://localhost", 11 | "username": "username", 12 | "password": "password", 13 | "bucket": "default", 14 | "users": { "GUEST": { "disabled": false, "admin_channels": ["*"] } }, 15 | "sync": 16 | ` 17 | function(doc, oldDoc) { 18 | if (doc.type == "reject_me") { 19 | throw({forbidden : "Rejected document"}) 20 | } else if (doc.type == "bar") { 21 | // add "bar" docs to the "important" channel 22 | channel("important"); 23 | } else if (doc.type == "secret") { 24 | if (!doc.owner) { 25 | throw({forbidden : "Secret documents must have an owner field"}) 26 | } 27 | } else { 28 | // all other documents just go into all channels listed in the doc["channels"] field 29 | channel(doc.channels) 30 | 31 | // Expire documents based on document "expiry" property 32 | expiry(doc.expiry) 33 | } 34 | } 35 | `, 36 | "allow_conflicts": false, 37 | "revs_limit": 20 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/legacy_config/config-server.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "logging": { 4 | "console": { 5 | "log_keys": ["*"] 6 | } 7 | }, 8 | "configServer": "http://localhost:8001/", 9 | "databases": { 10 | "db": { 11 | "server": "couchbase://localhost", 12 | "username": "username", 13 | "password": "password", 14 | "bucket": "default", 15 | "users": { "GUEST": { "disabled": false, "admin_channels": ["*"] } }, 16 | "allow_conflicts": false, 17 | "revs_limit": 20 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/legacy_config/config-shared-bucket-filter.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "databases": { 4 | "db": { 5 | "server": "couchbase://localhost", 6 | "username": "username", 7 | "password": "password", 8 | "bucket": "default", 9 | "import_docs": true, 10 | "enable_shared_bucket_access":true, 11 | "import_filter": ` 12 | function(doc) { 13 | if (doc.type != "mobile") { 14 | return false 15 | } 16 | return true 17 | } 18 | `, 19 | "allow_conflicts": false, 20 | "revs_limit": 20 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/legacy_config/config-shared-bucket.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "databases": { 4 | "db": { 5 | "server": "couchbase://localhost", 6 | "username": "username", 7 | "password": "password", 8 | "bucket": "default", 9 | "import_docs": true, 10 | "enable_shared_bucket_access":true, 11 | "allow_conflicts": false, 12 | "revs_limit": 20 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/legacy_config/cors.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "logging": { 4 | "console": { 5 | "log_keys": ["*"] 6 | } 7 | }, 8 | "CORS": { 9 | "Origin":["http://localhost:8000"], 10 | "LoginOrigin":["http://localhost:8000"], 11 | "Headers":["Content-Type"], 12 | "MaxAge": 1728000 13 | }, 14 | "databases": { 15 | "db": { 16 | "server": "couchbase://localhost", 17 | "username": "username", 18 | "password": "password", 19 | "bucket": "default", 20 | "users": { "GUEST": { "disabled": false, "admin_channels": ["*"] } }, 21 | "allow_conflicts": false, 22 | "revs_limit": 20 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/legacy_config/ee-cache-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "logging": { 4 | "console": { 5 | "log_keys": [ 6 | "*" 7 | ] 8 | } 9 | }, 10 | "databases": { 11 | "db": { 12 | "server": "couchbase://localhost", 13 | "username": "username", 14 | "password": "password", 15 | "bucket": "default", 16 | "users": { 17 | "GUEST": { 18 | "disabled": false, 19 | "admin_channels": [ 20 | "*" 21 | ] 22 | } 23 | }, 24 | "allow_conflicts": false, 25 | "revs_limit": 20, 26 | "cache":{ 27 | "channel_cache":{ 28 | "max_number": 50000, 29 | "compact_high_watermark_pct":80, 30 | "compact_low_watermark_pct":60, 31 | "max_length":500, 32 | "min_length":50, 33 | "expiry_seconds":60, 34 | "max_wait_pending":5, 35 | "max_num_pending":10000, 36 | "max_wait_skipped":60, 37 | "enable_star_channel":true 38 | }, 39 | "rev_cache":{ 40 | "size":5000, 41 | "shard_count":8 42 | } 43 | } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /examples/legacy_config/ee_basic-delta-sync.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "logging": { 4 | "console": { 5 | "log_keys": ["*"] 6 | } 7 | }, 8 | "databases": { 9 | "db": { 10 | "server": "couchbase://localhost", 11 | "username": "username", 12 | "password": "password", 13 | "bucket": "default", 14 | "users": { "GUEST": { "disabled": false, "admin_channels": ["*"] } }, 15 | "allow_conflicts": false, 16 | "revs_limit": 20, 17 | "delta_sync": { 18 | "enabled": true, 19 | "rev_max_age_seconds": 86400 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/legacy_config/events_webhook.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "logging": { 4 | "console": { 5 | "log_level": "debug", 6 | "log_keys": ["CRUD", "Events"] 7 | } 8 | }, 9 | "databases": { 10 | "db": { 11 | "server": "couchbase://localhost", 12 | "username": "username", 13 | "password": "password", 14 | "bucket": "default", 15 | "event_handlers": { 16 | "max_processes": 500, 17 | "wait_for_process": "100", 18 | "document_changed": [ 19 | { 20 | "handler": "webhook", 21 | "url": "http://localhost:8081/my_webhook_target", 22 | "timeout": 0, 23 | "filter": ` 24 | function(doc) { 25 | if (doc._id.indexOf('webhooktest') >= 0) { 26 | return true; 27 | } 28 | return false; 29 | }` 30 | } 31 | ] 32 | }, 33 | "allow_conflicts": false, 34 | "revs_limit": 20 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/legacy_config/logging-with-redaction.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "logging": { 4 | "redaction_level": "partial" 5 | }, 6 | "databases": { 7 | "db": { 8 | "server": "couchbase://localhost", 9 | "username": "username", 10 | "password": "password", 11 | "bucket": "default", 12 | "users": {"GUEST": {"disabled": false,"admin_channels": ["*"]}}, 13 | "allow_conflicts": false, 14 | "revs_limit": 20 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/legacy_config/logging-with-rotation.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "logging": { 4 | "log_file_path": "/var/tmp/sglogs", 5 | "console": { 6 | "log_level": "debug", 7 | "log_keys": ["*"] 8 | }, 9 | "error": { 10 | "enabled": true, 11 | "rotation": { 12 | "max_size": 20, 13 | "max_age": 180 14 | } 15 | }, 16 | "warn": { 17 | "enabled": true, 18 | "rotation": { 19 | "max_size": 20, 20 | "max_age": 90 21 | } 22 | }, 23 | "info": { 24 | "enabled": false 25 | }, 26 | "debug": { 27 | "enabled": false 28 | } 29 | }, 30 | "databases": { 31 | "db": { 32 | "server": "couchbase://localhost", 33 | "username": "username", 34 | "password": "password", 35 | "bucket": "default", 36 | "users": {"GUEST": {"disabled": false,"admin_channels": ["*"]}}, 37 | "allow_conflicts": false, 38 | "revs_limit": 20 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /examples/legacy_config/openid-connect.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "interface":":4984", 4 | "logging": { 5 | "console": { 6 | "log_keys": ["*"] 7 | } 8 | }, 9 | "databases": { 10 | "default": { 11 | "server": "couchbase://localhost", 12 | "username": "username", 13 | "password": "password", 14 | "bucket": "default", 15 | "oidc": { 16 | "default_provider":"google", 17 | "providers": { 18 | "google": { 19 | "issuer":"https://accounts.google.com", 20 | "client_id":"YOUR_CLIENT_ID", 21 | "validation_key":"YOUR_CLIENT_SECRET", 22 | "callback_url":"http://localhost:4984/default/_oidc_callback", 23 | "register":true 24 | } 25 | } 26 | }, 27 | "allow_conflicts": false, 28 | "revs_limit": 20 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/legacy_config/read-write-timeouts.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "ServerReadTimeout": 200, 4 | "ServerWriteTimeout": 200, 5 | "ReadHeaderTimeout": 120, 6 | "IdleTimeout": 180, 7 | "logging": { 8 | "console": { 9 | "log_keys": ["*"] 10 | } 11 | }, 12 | "databases": { 13 | "db": { 14 | "server": "couchbase://localhost", 15 | "username": "username", 16 | "password": "password", 17 | "bucket": "default", 18 | "users": { "GUEST": { "disabled": false, "admin_channels": ["*"] } }, 19 | "allow_conflicts": false, 20 | "revs_limit": 20 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/legacy_config/ssl.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "logging": { 4 | "console": { 5 | "log_keys": ["*"] 6 | } 7 | }, 8 | "SSLCert": "examples/ssl/cert.pem", 9 | "SSLKey": "examples/ssl/privkey.pem", 10 | "databases": { 11 | "db": { 12 | "server": "walrus:", 13 | "users": { 14 | "GUEST": { 15 | "disabled": false, 16 | "admin_channels": ["*"] 17 | } 18 | }, 19 | "allow_conflicts": false, 20 | "revs_limit": 20 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/legacy_config/users-roles.json: -------------------------------------------------------------------------------- 1 | { 2 | "disable_persistent_config": true, 3 | "logging": { 4 | "console": { 5 | "log_keys": ["*"] 6 | } 7 | }, 8 | "databases": { 9 | "db": { 10 | "server": "couchbase://localhost", 11 | "username": "username", 12 | "password": "password", 13 | "bucket": "default", 14 | "users": { 15 | "pupshaw": { 16 | "admin_channels": ["*"], 17 | "admin_roles": ["froods"], 18 | "password": "foo" 19 | } 20 | }, 21 | "roles": { "froods": { "admin_channels": ["hoopy"] } }, 22 | "allow_conflicts": false, 23 | "revs_limit": 20 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/prometheus/README.md: -------------------------------------------------------------------------------- 1 | # Sync Gateway Prometheus Setup # 2 | 3 | With Sync Gateway version 2.8, a new endpoint is provided that exposes stats in a Prometheus compatible format. This feature is available as a "Developer Preview" feature. In order to enable this, one must simply provide the `metricsInterface` config option within the Sync Gateway config. For example setting this to ":4986" will mean the metrics endpoint is exposed on port 4986. 4 | 5 | In order to make the installation and setup process easier we have provided both a `prometheus.yml` file and a set of rules under `rules/sync-gateway.rules.yml`. 6 | 7 | The `prometheus.yml` file specifies the configuration required to scrape the Sync Gateway metrics target. The provided `prometheus.yml` file points to the `metricsInterface` being accessible on `sync_gateway:4986/_metrics`. This can be changed to a different host or multiple targets can be added if required. 8 | 9 | Within this file a rules directory is provided which contains some pre-configured rules: 10 | - A total queries record that adds up all query counts and saves it as `sgw::gsi::total_queries` 11 | - A few example alerts 12 | 13 | Prometheus should be setup to use the `prometheus.yml` file and the `rules` directory should be put into `/etc/prometheus`. If the directory can't be put in that location then the `rule_files` configuration option within `prometheus.yml` can be modified to point to a different location. -------------------------------------------------------------------------------- /examples/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2020-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included in 4 | # the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 5 | # file, in accordance with the Business Source License, use of this software 6 | # will be governed by the Apache License, Version 2.0, included in the file 7 | # licenses/APL2.txt. 8 | 9 | global: 10 | scrape_interval: 5s 11 | evaluation_interval: 5s 12 | 13 | rule_files: 14 | - '/etc/prometheus/rules/*' 15 | 16 | scrape_configs: 17 | - job_name: swg 18 | metrics_path: /_metrics 19 | static_configs: 20 | - targets: 21 | - sync_gateway:4986 22 | -------------------------------------------------------------------------------- /examples/serviceconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap": { 3 | "server": "rosmar:/?mode=memory" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /examples/ssl/cert.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbase/sync_gateway/cde6f6789baf97833e56961ca761fdfff6bc8457/examples/ssl/cert.cer -------------------------------------------------------------------------------- /examples/ssl/cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDIDCCAgigAwIBAgIJAKqpH5Nh+KeAMA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV 3 | BAMTCWxvY2FsaG9zdDAeFw0xNDA1MDIxNjA4MzhaFw0xNzA1MDExNjA4MzhaMBQx 4 | EjAQBgNVBAMTCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC 5 | ggEBANLyAWIad5cwy3x34GZV5cy72oQdbM5f+oYw5bkeZNsDs65r3PWiM4kgTgjO 6 | C4plx9D7SNsiNlc/mbv5gL+peMmrRpFpyZvpWIptNpdYprTBba+xMPsUguhgbgv4 7 | /Rqh2C97Bqq/1qsxByGte3PRfRXThhR92N5J6LRNGb7G8ASlq2AQ48CFlZIQX8kC 8 | qN3o4rUngUYD3rTeiQcy9qYciUMRYQLIljai8NKwtO8QJbhg6WfV35OfwerSAmtV 9 | KxQ8RqMUP8txI8bGtfGT5bwBVQB8EVvEM21sTghjBRt8MImZgwHkmkh0UPbuesBp 10 | xnAbEC8Z9hHf49yA09oJEMFXEWcCAwEAAaN1MHMwHQYDVR0OBBYEFN/4E3dUJLTd 11 | jhAy3ale7LU+PHcmMEQGA1UdIwQ9MDuAFN/4E3dUJLTdjhAy3ale7LU+PHcmoRik 12 | FjAUMRIwEAYDVQQDEwlsb2NhbGhvc3SCCQCqqR+TYfingDAMBgNVHRMEBTADAQH/ 13 | MA0GCSqGSIb3DQEBBQUAA4IBAQB2i41uNeSdLYkp8zOF3NiwGLqW3+2sUkOjFGDf 14 | rh2O0u9BV1baDIJmembS8YwCcm9edZ7zXXqNJidzTIipZ8VCWjUPlEVTqEDSUC8R 15 | m6e22FQlSr6ZHpby7ONBrx4MA1kWzqSps/5eSyCPx8MS1oOwXg9Uroawdhrrfjan 16 | HEpvyUuYrAANG9YUMd70dXaOn0e1KJ21TTwvvw8IjtRM0+QBN8I8tOkDTij+SuMd 17 | QQE6hXrH3MJRWmp+K5UaAv0wuyyP6H5JpGs9Gq0a5tbG/Xj2RlWe87/5cpBarWsO 18 | VEWhjkgbdXpT7DEYLkKKjosT3L1G2UEKUxobERMHFVi1Ng9k 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /examples/ssl/ssl.json: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap": { 3 | "server": "couchbases://localhost", 4 | "server_tls_skip_verify": true, 5 | "username": "username", 6 | "password": "password" 7 | }, 8 | "logging": { 9 | "console": { 10 | "enabled": true, 11 | "log_level": "info", 12 | "log_keys": ["*"] 13 | } 14 | }, 15 | "api": { 16 | "https": { 17 | "tls_cert_path": "examples/ssl/cert.pem", 18 | "tls_key_path": "examples/ssl/privkey.pem" 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /examples/startup_config/basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap": { 3 | "server": "couchbases://localhost", 4 | "server_tls_skip_verify": true, 5 | "username": "username", 6 | "password": "password" 7 | }, 8 | "logging": { 9 | "console": { 10 | "enabled": true, 11 | "log_level": "info", 12 | "log_keys": ["*"] 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /examples/startup_config/cors.json: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap": { 3 | "server": "couchbases://localhost", 4 | "server_tls_skip_verify": true, 5 | "username": "username", 6 | "password": "password" 7 | }, 8 | "logging": { 9 | "console": { 10 | "enabled": true, 11 | "log_level": "info", 12 | "log_keys": ["*"] 13 | } 14 | }, 15 | "api": { 16 | "cors": { 17 | "origin": ["http://localhost:8000"], 18 | "login_origin": ["http://localhost:8000"], 19 | "headers": ["Content-Type"], 20 | "max_age": 1728000 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /examples/startup_config/logging-with-rotation.json: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap": { 3 | "server": "couchbases://localhost", 4 | "server_tls_skip_verify": true, 5 | "username": "username", 6 | "password": "password" 7 | }, 8 | "logging": { 9 | "log_file_path": "/var/tmp/sglogs", 10 | "console": { 11 | "enabled": true, 12 | "log_level": "debug", 13 | "log_keys": ["*"] 14 | }, 15 | "error": { 16 | "enabled": true, 17 | "rotation": { 18 | "max_size": 20, 19 | "max_age": 180 20 | } 21 | }, 22 | "warn": { 23 | "enabled": true, 24 | "rotation": { 25 | "max_size": 20, 26 | "max_age": 90 27 | } 28 | }, 29 | "info": { 30 | "enabled": false 31 | }, 32 | "debug": { 33 | "enabled": false 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /examples/startup_config/logging-without-redaction.json: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap": { 3 | "server": "couchbases://localhost", 4 | "server_tls_skip_verify": true, 5 | "username": "username", 6 | "password": "password" 7 | }, 8 | "logging": { 9 | "redaction_level": "none", 10 | "console": { 11 | "enabled": true, 12 | "log_level": "info", 13 | "log_keys": ["*"] 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /examples/startup_config/x509.json: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap": { 3 | "server": "couchbases://localhost", 4 | "ca_cert_path": "path/to/ca-cert", 5 | "x509_cert_path": "path/to/cert", 6 | "x509_key_path": "path/to/key" 7 | }, 8 | "logging": { 9 | "console": { 10 | "enabled": true, 11 | "log_level": "info", 12 | "log_keys": ["*"] 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /integration-test/docker-compose.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2023-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | 9 | services: 10 | couchbase: 11 | container_name: couchbase 12 | image: "couchbase/server:${COUCHBASE_DOCKER_IMAGE_NAME:-enterprise-7.6.5}" 13 | ports: 14 | - 8091:8091 15 | - 8092:8092 16 | - 8093:8093 17 | - 8094:8094 18 | - 8095:8095 19 | - 8096:8096 20 | - 8097:8097 21 | - 9102:9102 22 | - 9123:9123 23 | - 11207:11207 24 | - 11210:11210 25 | - 11211:11211 26 | - 18091:18091 27 | - 18092:18092 28 | - 18093:18093 29 | - 18094:18094 30 | - 18095:18095 31 | - 18096:18096 32 | - 18097:18097 33 | - 19102:19102 34 | volumes: 35 | - "${DOCKER_CBS_ROOT_DIR:-.}/cbs:/root" 36 | - "${WORKSPACE_ROOT:-.}:/workspace" 37 | couchbase-replica1: 38 | container_name: couchbase-replica1 39 | image: "couchbase/${COUCHBASE_DOCKER_IMAGE_NAME:-server:enterprise-7.6.5}" 40 | couchbase-replica2: 41 | container_name: couchbase-replica2 42 | image: "couchbase/server:${COUCHBASE_DOCKER_IMAGE_NAME:-enterprise-7.6.5}" 43 | -------------------------------------------------------------------------------- /integration-test/service-install-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2024-Present Couchbase, Inc. 3 | # 4 | # Use of this software is governed by the Business Source License included 5 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 6 | # in that file, in accordance with the Business Source License, use of this 7 | # software will be governed by the Apache License, Version 2.0, included in 8 | # the file licenses/APL2.txt. 9 | 10 | # This file is used by github CI or locally and runs a subset of test scripts to validate the service installation done by the package managers. This is intended to be run from Linux or Mac. 11 | 12 | set -eux -o pipefail 13 | 14 | IMAGES=( 15 | "almalinux:9" 16 | "amazonlinux:2" 17 | "amazonlinux:2023" 18 | "debian:10" 19 | "debian:11" 20 | "debian:12" 21 | "redhat/ubi8" 22 | "redhat/ubi9" 23 | "rockylinux:9" 24 | "ubuntu:20.04" 25 | "ubuntu:22.04" 26 | "ubuntu:24.04" 27 | 28 | # not technically supported 29 | "oraclelinux:9" 30 | ) 31 | 32 | SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") 33 | SYNC_GATEWAY_DIR=$(realpath ${SCRIPT_DIR}/..) 34 | 35 | if [ "$(uname)" == "Darwin" ]; then 36 | sudo ${SYNC_GATEWAY_DIR}/integration-test/service-test.sh 37 | fi 38 | 39 | for IMAGE in "${IMAGES[@]}"; do 40 | echo "Running tests for ${IMAGE}" 41 | docker run --mount src=${SYNC_GATEWAY_DIR},target=/sync_gateway,type=bind ${IMAGE} /bin/bash -c "/sync_gateway/integration-test/service-test.sh" 42 | done 43 | -------------------------------------------------------------------------------- /licenses/addlicense.tmpl: -------------------------------------------------------------------------------- 1 | Copyright {{.Year}}-Present Couchbase, Inc. 2 | 3 | Use of this software is governed by the Business Source License included 4 | in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | in that file, in accordance with the Business Source License, use of this 6 | software will be governed by the Apache License, Version 2.0, included in 7 | the file licenses/APL2.txt. 8 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package main 10 | 11 | import ( 12 | "github.com/couchbase/sync_gateway/rest" 13 | ) 14 | 15 | // Simple Sync Gateway launcher tool. 16 | func main() { 17 | rest.ServerMain() 18 | } 19 | -------------------------------------------------------------------------------- /manifest/3.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.1.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.10.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.11.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.3.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.1/3.1.9.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.2/3.2.0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.2/3.2.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.2/3.2.2.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.2/3.2.2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.2/3.2.3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.2/3.2.4.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /manifest/3.2/3.2.4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/3.2/3.2.5.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /manifest/3.2/3.2.5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /manifest/3.3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/4.0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /manifest/default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] # this isn't a real project, but we need this to make the tools work 2 | name = "sgcollect_info" 3 | version = "0.0.1" 4 | requires-python = ">=3.9,<3.10" # miniconda pyinstaller is pinned to python 3.9 5 | 6 | [tool.mypy] 7 | files = ["tools/sgcollect_info", "tools-tests/*.py", "tools/*.py"] 8 | check_untyped_defs = false # candidate for removal in the future 9 | disable_error_code = [ 10 | "type-arg", # candidate for removal in the future 11 | ] 12 | disallow_incomplete_defs = false # candidate for removal in the future 13 | disallow_untyped_calls = false # candidate for removal in the future 14 | disallow_untyped_defs = false # candidate for removal in the future 15 | strict = true # mypy has stricter warnings 16 | warn_return_any = false # candidate for removal in the future 17 | warn_unused_configs = true # validates this file 18 | warn_unreachable = true # candidate for removal in the future 19 | 20 | [tool.pyright] 21 | extraPaths = ["tools"] 22 | 23 | [tool.ruff] 24 | extend-include = ["tools/sgcollect_info"] 25 | 26 | [tool.ruff.lint] 27 | extend-select = ["I","B006"] # isort, mutable default argument 28 | 29 | # test only dependencies 30 | [dependency-groups] 31 | dev = [ 32 | "mypy>=1.16.1", 33 | "pytest>=8.4.0", 34 | "pytest-httpserver>=1.1.3", 35 | "trustme>=1.2.1", 36 | ] 37 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | testpaths = tools-tests 3 | pythonpath = tools 4 | -------------------------------------------------------------------------------- /rest/adminapitest/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package adminapitest 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | "github.com/couchbase/sync_gateway/rest" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | ctx := context.Background() // start of test process 23 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 8192, NumCollectionsPerBucket: 3} 24 | rest.TestBucketPoolRestWithIndexes(ctx, m, tbpOptions) 25 | } 26 | -------------------------------------------------------------------------------- /rest/attachmentcompactiontest/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package attachmentcompactiontest 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | "github.com/couchbase/sync_gateway/rest" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | ctx := context.Background() // start of test process 23 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 2048} 24 | rest.TestBucketPoolRestWithIndexes(ctx, m, tbpOptions) 25 | } 26 | -------------------------------------------------------------------------------- /rest/changestest/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package changestest 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | "github.com/couchbase/sync_gateway/rest" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | ctx := context.Background() // start of test process 23 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 2048} 24 | rest.TestBucketPoolRestWithIndexes(ctx, m, tbpOptions) 25 | } 26 | -------------------------------------------------------------------------------- /rest/functionsapitest/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package functionsapitest 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | "github.com/couchbase/sync_gateway/rest" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | ctx := context.Background() // start of test process 23 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 18192} 24 | rest.TestBucketPoolRestWithIndexes(ctx, m, tbpOptions) 25 | } 26 | -------------------------------------------------------------------------------- /rest/importtest/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package importtest 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | "github.com/couchbase/sync_gateway/rest" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | if !base.TestUseXattrs() { // import tests only run if xattrs are enabled 23 | base.SkipTestMain(m, "import tests only run if xattrs are enabled") 24 | } 25 | 26 | ctx := context.Background() // start of test process 27 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 2048, NumCollectionsPerBucket: 3} 28 | rest.TestBucketPoolRestWithIndexes(ctx, m, tbpOptions) 29 | } 30 | -------------------------------------------------------------------------------- /rest/importuserxattrtest/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package importuserxattrtest 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | "github.com/couchbase/sync_gateway/rest" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | // user xattr tests require xattrs and EE 23 | if !base.TestUseXattrs() || !base.IsEnterpriseEdition() { 24 | base.SkipTestMain(m, "user xattr tests require xattrs and EE") 25 | } 26 | 27 | ctx := context.Background() // start of test process 28 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 2048} 29 | rest.TestBucketPoolRestWithIndexes(ctx, m, tbpOptions) 30 | } 31 | -------------------------------------------------------------------------------- /rest/indextest/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package indextest 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | "github.com/couchbase/sync_gateway/db" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | ctx := context.Background() // start of test process 23 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 2048} 24 | // Do not create indexes for this test, so they are built by server_context.go 25 | db.TestBucketPoolEnsureNoIndexes(ctx, m, tbpOptions) 26 | } 27 | -------------------------------------------------------------------------------- /rest/replicatortest/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package replicatortest 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | "github.com/couchbase/sync_gateway/rest" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | ctx := context.Background() // start of test process 23 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 8192, NumCollectionsPerBucket: 3} 24 | rest.TestBucketPoolRestWithIndexes(ctx, m, tbpOptions) 25 | } 26 | -------------------------------------------------------------------------------- /rest/sgcollecttest/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package sgcollecttest 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | "github.com/couchbase/sync_gateway/rest" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | ctx := context.Background() // start of test process 23 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 8192, NumCollectionsPerBucket: 3} 24 | rest.TestBucketPoolRestWithIndexes(ctx, m, tbpOptions) 25 | } 26 | -------------------------------------------------------------------------------- /rest/upgradetest/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package upgradetest 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | "github.com/couchbase/sync_gateway/rest" 19 | ) 20 | 21 | func TestMain(m *testing.M) { 22 | ctx := context.Background() // start of test process 23 | tbpOptions := base.TestBucketPoolOptions{ 24 | MemWatermarkThresholdMB: 8192, 25 | UseDefaultScope: true, 26 | } 27 | rest.TestBucketPoolRestWithIndexes(ctx, m, tbpOptions) 28 | } 29 | -------------------------------------------------------------------------------- /rest/utilities_testing_functions_api.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package rest 10 | 11 | import ( 12 | "testing" 13 | 14 | "github.com/couchbase/sync_gateway/base" 15 | ) 16 | 17 | // NewRestTesterForUserQueries creates a new RestTester using persistent config, and a database "db". 18 | // Only the user-query-related fields are copied from `queryConfig`; the rest are ignored. 19 | func NewRestTesterForUserQueries(t *testing.T, queryConfig DbConfig) *RestTester { 20 | if base.TestsDisableGSI() { 21 | t.Skip("These tests use N1QL functions which requires GSI") 22 | } 23 | rt := NewRestTesterDefaultCollection(t, &RestTesterConfig{ 24 | EnableUserQueries: true, 25 | PersistentConfig: true, 26 | }) 27 | 28 | dbConfig := rt.NewDbConfig() 29 | 30 | dbConfig.UserFunctions = queryConfig.UserFunctions 31 | 32 | resp := rt.CreateDatabase("db", dbConfig) 33 | if !AssertStatus(t, resp, 201) { 34 | rt.Close() 35 | t.FailNow() 36 | return nil // (never reached) 37 | } 38 | return rt 39 | } 40 | -------------------------------------------------------------------------------- /ruleguard/README.md: -------------------------------------------------------------------------------- 1 | # ruleguard rules 2 | 3 | A directory containing [ruleguard](https://github.com/quasilyte/go-ruleguard) rules run by [go-critic](https://github.com/go-critic/go-critic) via [golangci-lint](https://golangci-lint.run/). 4 | 5 | ## Manual usage: 6 | 7 | ```sh 8 | $ ruleguard -rules ruleguard/*.go ./... 9 | db/crud.go:2577:4: logwrappederr: cannot use error wrapping verb %w outside of fmt.Errorf() - use %s or %v instead? (rules-logwrappederr.go:64) 10 | 11 | $ golangci-lint --config .golangci.yml run' 12 | db/crud.go:2577:4: ruleguard: cannot use error wrapping verb %w outside of fmt.Errorf() - use %s or %v instead? (gocritic) 13 | base.WarnfCtx(ctx, "CheckProposedRev(%q) --> %T %w", base.UD(docid), err, err) 14 | ^ 15 | ``` -------------------------------------------------------------------------------- /ruleguard/go.mod: -------------------------------------------------------------------------------- 1 | module ruleguard 2 | 3 | go 1.21 4 | 5 | require github.com/quasilyte/go-ruleguard/dsl v0.3.22 6 | -------------------------------------------------------------------------------- /ruleguard/go.sum: -------------------------------------------------------------------------------- 1 | github.com/quasilyte/go-ruleguard/dsl v0.3.22 h1:wd8zkOhSNr+I+8Qeciml08ivDt1pSXe60+5DqOpCjPE= 2 | github.com/quasilyte/go-ruleguard/dsl v0.3.22/go.mod h1:KeCP03KrjuSO0H1kTuZQCWlQPulDV6YMIXmpQss17rU= 3 | -------------------------------------------------------------------------------- /ruleguard/internal/test_pkg/base/log.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package base 10 | 11 | import ( 12 | "context" 13 | "fmt" 14 | "log" 15 | ) 16 | 17 | //nolint:goprintffuncname 18 | func PanicfCtx(_ context.Context, format string, args ...interface{}) { 19 | log.Printf("[ERR] "+format, args...) 20 | } 21 | 22 | //nolint:goprintffuncname 23 | func InfofCtx(_ context.Context, logkey, format string, args ...interface{}) { 24 | format = fmt.Sprintf("[INF] %s: %s", logkey, format) 25 | log.Printf(format, args...) 26 | } 27 | -------------------------------------------------------------------------------- /ruleguard/rules-requirefailnow.go: -------------------------------------------------------------------------------- 1 | // Copyright 2025-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | //go:build ruleguard 10 | // +build ruleguard 11 | 12 | //nolint:unused // functions in here are invoked by ruleguard, but aren't imported/used by anything Go can detect. 13 | package ruleguard 14 | 15 | import ( 16 | "github.com/quasilyte/go-ruleguard/dsl" 17 | ) 18 | 19 | func failnow(m dsl.Matcher) { 20 | m.Match( 21 | `require.FailNow($t, $msg, $*_)`, 22 | `require.FailNow($t, $msg)`, 23 | `require.FailNowf($t, $msg)`, 24 | `require.FailNowf($t, $msg, $*_)`, 25 | `require.Fail($t, $msg)`, 26 | `require.Fail($t, $msg, $*_)`, 27 | `require.Failf($t, $msg)`, 28 | `require.Failf($t, $msg, $*_)`, 29 | `assert.FailNow($t, $msg, $*_)`, 30 | `assert.FailNow($t, $msg)`, 31 | `assert.FailNowf($t, $msg)`, 32 | `assert.FailNowf($t, $msg, $*_)`, 33 | `assert.Fail($t, $msg)`, 34 | `assert.Fail($t, $msg, $*_)`, 35 | `assert.Failf($t, $msg)`, 36 | `assert.Failf($t, $msg, $*_)`, 37 | ).Where(m["msg"].Pure && m["msg"].Type.Is("string") && m["msg"].Text.Matches(".*%[A-Za-z]")).Report("second argument can not contain format verbs starting with %, wrap this argument in fmt.Sprintf() if you want to use format verbs") 38 | } 39 | -------------------------------------------------------------------------------- /service/script_templates/com.couchbase.mobile.sync_gateway.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Label 6 | com.couchbase.mobile.sync_gateway 7 | UserName 8 | ${RUNAS_TEMPLATE_VAR} 9 | WorkingDirectory 10 | ${RUNBASE_TEMPLATE_VAR} 11 | ProgramArguments 12 | 13 | ${GATEWAY_TEMPLATE_VAR} 14 | --defaultLogFilePath 15 | ${LOGS_TEMPLATE_VAR} 16 | ${CONFIG_TEMPLATE_VAR} 17 | 18 | KeepAlive 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /service/script_templates/systemd_debian_sync_gateway.tpl: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Couchbase Sync Gateway server 3 | After=syslog.target 4 | After=network.target 5 | 6 | [Service] 7 | LimitNOFILE=65535 8 | Environment=\"RUNBASE=${RUNBASE_TEMPLATE_VAR}\" 9 | Environment=\"GATEWAY=${GATEWAY_TEMPLATE_VAR}\" 10 | Environment=\"CONFIG=${CONFIG_TEMPLATE_VAR}\" 11 | Environment=\"LOGS=${LOGS_TEMPLATE_VAR}\" 12 | Environment=\"NAME=${SERVICE_NAME}\" 13 | Type=simple 14 | User=${RUNAS_TEMPLATE_VAR} 15 | WorkingDirectory=${RUNBASE_TEMPLATE_VAR} 16 | ExecStartPre=/bin/mkdir -p ${LOGS_TEMPLATE_VAR} 17 | ExecStartPre=/bin/chown -R ${RUNAS_TEMPLATE_VAR}:${RUNAS_TEMPLATE_VAR} ${LOGS_TEMPLATE_VAR} 18 | ExecStartPre=/bin/mkdir -p ${RUNBASE_TEMPLATE_VAR}/data 19 | ExecStartPre=/bin/chown -R ${RUNAS_TEMPLATE_VAR}:${RUNAS_TEMPLATE_VAR} ${RUNBASE_TEMPLATE_VAR}/data 20 | ExecStart=/bin/bash -c '\${GATEWAY} --defaultLogFilePath \"\${LOGS}\" \${CONFIG}' 21 | Restart=on-failure 22 | 23 | # Give a reasonable amount of time for the server to start up/shut down 24 | TimeoutSec=60 25 | 26 | [Install] 27 | WantedBy=multi-user.target 28 | -------------------------------------------------------------------------------- /service/script_templates/systemd_sync_gateway.tpl: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Couchbase Sync Gateway server 3 | After=syslog.target 4 | After=network.target 5 | 6 | [Service] 7 | LimitNOFILE=65535 8 | Environment=\"RUNBASE=${RUNBASE_TEMPLATE_VAR}\" 9 | Environment=\"GATEWAY=${GATEWAY_TEMPLATE_VAR}\" 10 | Environment=\"CONFIG=${CONFIG_TEMPLATE_VAR}\" 11 | Environment=\"LOGS=${LOGS_TEMPLATE_VAR}\" 12 | Environment=\"NAME=${SERVICE_NAME}\" 13 | Type=simple 14 | User=${RUNAS_TEMPLATE_VAR} 15 | WorkingDirectory=${RUNBASE_TEMPLATE_VAR} 16 | ExecStartPre=/bin/mkdir -p ${LOGS_TEMPLATE_VAR} 17 | ExecStartPre=/bin/chown -R ${RUNAS_TEMPLATE_VAR}:${RUNAS_TEMPLATE_VAR} ${LOGS_TEMPLATE_VAR} 18 | ExecStartPre=/bin/mkdir -p ${RUNBASE_TEMPLATE_VAR}/data 19 | ExecStartPre=/bin/chown -R ${RUNAS_TEMPLATE_VAR}:${RUNAS_TEMPLATE_VAR} ${RUNBASE_TEMPLATE_VAR}/data 20 | ExecStart=/usr/bin/bash -c '\${GATEWAY} --defaultLogFilePath \"\${LOGS}\" \${CONFIG}' 21 | Restart=on-failure 22 | 23 | # Give a reasonable amount of time for the server to start up/shut down 24 | TimeoutSec=60 25 | 26 | [Install] 27 | WantedBy=multi-user.target 28 | -------------------------------------------------------------------------------- /service/script_templates/upstart_redhat_sync_gateway.tpl: -------------------------------------------------------------------------------- 1 | description \"Sync Gateway Upstart Script\" 2 | version \"0.1.0\" 3 | author \"Andrew Reslan\" 4 | 5 | # Upstart env vars 6 | env RUNAS=${RUNAS_TEMPLATE_VAR} 7 | env RUNBASE=${RUNBASE_TEMPLATE_VAR} 8 | env PIDFILE=${PIDFILE_TEMPLATE_VAR} 9 | env GATEWAY=${GATEWAY_TEMPLATE_VAR} 10 | env CONFIG=${CONFIG_TEMPLATE_VAR} 11 | env LOGS=${LOGS_TEMPLATE_VAR} 12 | env NAME=${SERVICE_NAME} 13 | 14 | # Keep the server running on crash or machine reboot 15 | start on started 16 | stop on shutdown 17 | respawn 18 | 19 | pre-start script 20 | mkdir -p \$LOGS 21 | chown -R \${RUNAS}:\${RUNAS} \$LOGS 22 | 23 | mkdir -p \${RUNBASE}/data 24 | chown -R \${RUNAS}:\${RUNAS} \${RUNBASE}/data 25 | end script 26 | 27 | # Start the Sync Gateway and redirect output streams to log files 28 | script 29 | # Keep a pid around 30 | echo \$\$ > \$PIDFILE 31 | cd \$RUNBASE 32 | su --session-command \"\$GATEWAY --defaultLogFilePath \"\$LOGS\" \$CONFIG\" \$RUNAS 33 | end script 34 | 35 | # Remove pid file when we stop the server 36 | pre-stop script 37 | rm $PIDFILE 38 | end script 39 | -------------------------------------------------------------------------------- /service/script_templates/upstart_ubuntu_sync_gateway.tpl: -------------------------------------------------------------------------------- 1 | description \"Sync Gateway Upstart Script\" 2 | version \"0.1.0\" 3 | author \"Andrew Reslan\" 4 | 5 | # Upstart env vars 6 | env RUNAS=${RUNAS_TEMPLATE_VAR} 7 | env RUNBASE=${RUNBASE_TEMPLATE_VAR} 8 | env PIDFILE=${PIDFILE_TEMPLATE_VAR} 9 | env GATEWAY=${GATEWAY_TEMPLATE_VAR} 10 | env CONFIG=${CONFIG_TEMPLATE_VAR} 11 | env LOGS=${LOGS_TEMPLATE_VAR} 12 | env NAME=${SERVICE_NAME} 13 | 14 | # Keep the server running on crash or machine reboot 15 | start on runlevel [2345] 16 | stop on shutdown 17 | respawn 18 | 19 | pre-start script 20 | mkdir -p \$LOGS 21 | chown -R \${RUNAS}:\${RUNAS} \$LOGS 22 | 23 | mkdir -p \${RUNBASE}/data 24 | chown -R \${RUNAS}:\${RUNAS} \${RUNBASE}/data 25 | end script 26 | 27 | exec start-stop-daemon --start --chuid \$RUNAS --chdir \$RUNBASE --make-pidfile --pidfile \$PIDFILE --startas \$GATEWAY -- --defaultLogFilePath \"\$LOGS\" \$CONFIG 28 | -------------------------------------------------------------------------------- /service/sg-windows/build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | SETLOCAL 4 | 5 | set CWD=%cd% 6 | cd ..\..\..\..\..\.. 7 | set GO_PATH=%cd% 8 | cd %CWD% 9 | SET GOPATH=%cd%;%GO_PATH% 10 | 11 | REM Build the Sync Gateway service wrapper 12 | go build -o sg-windows.exe sg-service\sg-service.go 13 | 14 | ENDLOCAL 15 | -------------------------------------------------------------------------------- /set-version-stamp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | # Copyright 2016-Present Couchbase, Inc. 4 | # 5 | # Use of this software is governed by the Business Source License included in 6 | # the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 7 | # file, in accordance with the Business Source License, use of this software 8 | # will be governed by the Apache License, Version 2.0, included in the file 9 | # licenses/APL2.txt. 10 | 11 | # This script updates the rest/git_info.go file which bakes in the 12 | # git version to the Sync Gateway binary 13 | 14 | ## Update the version 15 | BUILD_INFO="./base/git_info.go" 16 | 17 | #tell git to ignore any local changes to git_info.go, we don't want to commit them to the repo 18 | git update-index --assume-unchanged ${BUILD_INFO} 19 | 20 | # Escape forward slash's so sed command does not get confused 21 | # We use thses in feature branches e.g. feature/issue_nnn 22 | PRODUCT_NAME="Couchbase Sync Gateway" 23 | GIT_BRANCH=`git status -b -s | sed q | sed 's/## //' | sed 's/\.\.\..*$//' | sed 's/\\//\\\\\//g' | sed 's/[[:space:]]//g'` 24 | GIT_COMMIT=`git rev-parse HEAD` 25 | GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true) 26 | 27 | sed -i.bak -e 's/GitProductName.*=.*/GitProductName = "'"$PRODUCT_NAME"'"/' $BUILD_INFO 28 | sed -i.bak -e 's/GitCommit.*=.*/GitCommit = "'$GIT_COMMIT'"/' $BUILD_INFO 29 | sed -i.bak -e 's/GitBranch.*=.*/GitBranch = "'$GIT_BRANCH'"/' $BUILD_INFO 30 | sed -i.bak -e 's/GitDirty.*=.*/GitDirty = "'$GIT_DIRTY'"/' $BUILD_INFO 31 | 32 | 33 | -------------------------------------------------------------------------------- /tools-tests/parser_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-Present Couchbase, Inc. 2 | # 3 | # Use of this software is governed by the Business Source License included 4 | # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | # in that file, in accordance with the Business Source License, use of this 6 | # software will be governed by the Apache License, Version 2.0, included in 7 | # the file licenses/APL2.txt. 8 | import sgcollect 9 | 10 | 11 | def test_parser(): 12 | sgcollect.create_option_parser() 13 | 14 | 15 | def test_parser_log_redaction_salt(): 16 | parser = sgcollect.create_option_parser() 17 | options, _ = parser.parse_args(["--log-redaction-salt=a", "foo.zip"]) 18 | assert options.salt_value == "a" 19 | 20 | options, _ = parser.parse_args(["foo.zip"]) 21 | # assert this is a str repr of uuid4 22 | assert isinstance(options.salt_value, str) 23 | assert len(options.salt_value) == 36 24 | -------------------------------------------------------------------------------- /tools.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | //go:build tools 10 | 11 | package tools 12 | 13 | import ( 14 | _ "github.com/quasilyte/go-ruleguard/dsl" 15 | ) 16 | -------------------------------------------------------------------------------- /tools/sgcollect_info: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | Copyright 2016-Present Couchbase, Inc. 4 | 5 | Use of this software is governed by the Business Source License included in 6 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 7 | file, in accordance with the Business Source License, use of this software will 8 | be governed by the Apache License, Version 2.0, included in the file 9 | licenses/APL2.txt. 10 | """ 11 | 12 | import sgcollect 13 | 14 | if __name__ == "__main__": 15 | sgcollect.main() 16 | -------------------------------------------------------------------------------- /tools/stats-definition-exporter/main_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package main 10 | 11 | import ( 12 | "bytes" 13 | "log" 14 | "testing" 15 | 16 | "github.com/stretchr/testify/assert" 17 | ) 18 | 19 | func TestRegisterStats(t *testing.T) { 20 | globalStats, dbStats, err := registerStats() 21 | 22 | assert.NotNil(t, globalStats) 23 | assert.NotNil(t, dbStats) 24 | assert.NoError(t, err) 25 | } 26 | 27 | func TestFileOutput(t *testing.T) { 28 | outputFile := t.TempDir() + "/" + t.Name() + ".json" 29 | 30 | // Set all logging to buffer 31 | var buf bytes.Buffer 32 | logger := log.New(&buf, "", 0) 33 | 34 | err := statsToFile(logger, &outputFile) 35 | assert.NoError(t, err) 36 | 37 | // Make sure no errors where logged 38 | assert.Empty(t, buf) 39 | 40 | // Test file outputted 41 | assert.FileExists(t, outputFile) 42 | } 43 | 44 | func TestStdOutput(t *testing.T) { 45 | // Set all logging to buffer 46 | var buf bytes.Buffer 47 | logger := log.New(&buf, "", 0) 48 | 49 | err := statsToFile(logger, nil) 50 | assert.NoError(t, err) 51 | 52 | // Make sure no errors where logged 53 | assert.Empty(t, buf) 54 | } 55 | -------------------------------------------------------------------------------- /xdcr/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020-Present Couchbase, Inc. 3 | 4 | Use of this software is governed by the Business Source License included in 5 | the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that 6 | file, in accordance with the Business Source License, use of this software will 7 | be governed by the Apache License, Version 2.0, included in the file 8 | licenses/APL2.txt. 9 | */ 10 | 11 | package xdcr 12 | 13 | import ( 14 | "context" 15 | "testing" 16 | 17 | "github.com/couchbase/sync_gateway/base" 18 | ) 19 | 20 | func TestMain(m *testing.M) { 21 | ctx := context.Background() // start of test process 22 | tbpOptions := base.TestBucketPoolOptions{MemWatermarkThresholdMB: 2048, RequireXDCR: true} 23 | base.TestBucketPoolNoIndexes(ctx, m, tbpOptions) 24 | } 25 | -------------------------------------------------------------------------------- /xdcr/stats.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024-Present Couchbase, Inc. 2 | // 3 | // Use of this software is governed by the Business Source License included 4 | // in the file licenses/BSL-Couchbase.txt. As of the Change Date specified 5 | // in that file, in accordance with the Business Source License, use of this 6 | // software will be governed by the Apache License, Version 2.0, included in 7 | // the file licenses/APL2.txt. 8 | 9 | package xdcr 10 | 11 | // Stats represents the stats of a replication. 12 | type Stats struct { 13 | // DocsFiltered is the number of documents that have been filtered out and have not been replicated to the target cluster. 14 | DocsFiltered uint64 15 | // DocsWritten is the number of documents written to the destination cluster, since the start or resumption of the current replication. 16 | DocsWritten uint64 17 | // ErrorCount is the number of errors that have occurred during the replication. 18 | ErrorCount uint64 19 | 20 | // TargetNewerDocs is the number of documents that were newer on the target cluster than the source cluster. 21 | TargetNewerDocs uint64 22 | } 23 | --------------------------------------------------------------------------------